Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / cc / trees / layer_tree_host_common_unittest.cc
blob99dc89cffd6956f5b8b0fedc12cc34feb7dedaf7
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"
7 #include <algorithm>
8 #include <set>
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"
43 namespace cc {
44 namespace {
46 class LayerWithForcedDrawsContent : public Layer {
47 public:
48 explicit LayerWithForcedDrawsContent(const LayerSettings& settings)
49 : Layer(settings) {}
51 bool DrawsContent() const override;
53 private:
54 ~LayerWithForcedDrawsContent() override {}
57 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
59 class MockContentLayerClient : public ContentLayerClient {
60 public:
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 {
69 NOTIMPLEMENTED();
70 return nullptr;
72 bool FillsBoundsCompletely() const override { return false; }
73 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; }
76 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
77 do { \
78 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
79 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
80 } while (false)
82 #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
83 do { \
84 EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \
85 } while (false)
87 class LayerTreeSettingsScaleContent : public LayerTreeSettings {
88 public:
89 LayerTreeSettingsScaleContent() {
90 layer_transforms_should_scale_layer_contents = true;
94 class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTest {
95 public:
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(),
116 identity_matrix,
117 gfx::Point3F(),
118 gfx::PointF(),
119 gfx::Size(100, 100),
120 true,
121 false);
122 SetLayerPropertiesForTesting(child.get(),
123 identity_matrix,
124 gfx::Point3F(),
125 gfx::PointF(),
126 gfx::Size(),
127 true,
128 false);
129 SetLayerPropertiesForTesting(grand_child.get(),
130 identity_matrix,
131 gfx::Point3F(),
132 gfx::PointF(),
133 gfx::Size(),
134 true,
135 false);
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,
156 true);
157 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
158 gfx::PointF(10, 10), gfx::Size(100, 100), true,
159 false, false);
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
162 // with handlers.
163 child->SetOpacity(0.f);
164 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
165 gfx::PointF(10, 10), gfx::Size(100, 100), true,
166 false, false);
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
172 // |child|.
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(
200 identity_matrix,
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(
212 identity_matrix,
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(
226 position_transform,
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(
240 layer_transform,
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(
255 expected_result,
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(
270 expected_result,
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(),
279 -kScrollOffset.y());
280 const float kPageScale = 0.888f;
281 const float kDeviceScale = 1.666f;
283 FakeImplProxy proxy;
284 TestSharedBitmapManager shared_bitmap_manager;
285 TestTaskGraphRunner task_graph_runner;
286 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
287 &task_graph_runner);
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,
295 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,
302 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,
322 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),
347 true, false, false);
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 *
354 kDeviceScale),
355 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
356 sub_layer_screen_position.y() * kPageScale *
357 kDeviceScale));
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),
390 true, false);
391 ExecuteCalculateDrawProperties(root.get());
393 EXPECT_TRANSFORMATION_MATRIX_EQ(
394 identity_matrix, DrawTransformFromPropertyTrees(child.get(), tree));
395 EXPECT_TRANSFORMATION_MATRIX_EQ(
396 identity_matrix,
397 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
398 EXPECT_TRANSFORMATION_MATRIX_EQ(
399 identity_matrix, DrawTransformFromPropertyTrees(grand_child.get(), tree));
400 EXPECT_TRANSFORMATION_MATRIX_EQ(
401 identity_matrix,
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),
414 true, false);
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),
444 true, false);
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,
470 true);
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,
485 1.f);
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,
497 true);
498 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
499 gfx::PointF(), gfx::Size(8, 10), true, false,
500 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
522 // into the root.
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,
541 true);
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,
557 1.f);
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,
573 true);
574 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
575 gfx::PointF(-0.5f, -0.5f), gfx::Size(1, 1), true,
576 false, false);
577 SetLayerPropertiesForTesting(child_replica.get(), replica_layer_transform,
578 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
579 false, false);
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()
593 ->render_surface()
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,
638 true);
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);
650 gfx::Transform A =
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
664 // the owning layer
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
676 // the owning layer
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(
794 A * R * S1,
795 render_surface1->render_surface()->replica_screen_space_transform());
796 // Draw transform of render surface 2 is described with respect to render
797 // surface 1.
798 EXPECT_TRANSFORMATION_MATRIX_EQ(
799 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
800 EXPECT_TRANSFORMATION_MATRIX_EQ(
801 SS1 * R * S2,
802 render_surface2->render_surface()->replica_draw_transform());
803 EXPECT_TRANSFORMATION_MATRIX_EQ(
804 A * A * A * S2,
805 render_surface2->render_surface()->screen_space_transform());
806 EXPECT_TRANSFORMATION_MATRIX_EQ(
807 A * A * R * S2,
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));
814 EXPECT_FLOAT_EQ(2.0,
815 child_of_root->screen_space_transform().matrix().get(1, 3));
816 EXPECT_FLOAT_EQ(
817 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
819 EXPECT_FLOAT_EQ(2.0,
820 render_surface1->screen_space_transform().matrix().get(1, 3));
821 EXPECT_FLOAT_EQ(3.0,
822 child_of_rs1->screen_space_transform().matrix().get(1, 3));
823 EXPECT_FLOAT_EQ(
824 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
826 EXPECT_FLOAT_EQ(3.0,
827 render_surface2->screen_space_transform().matrix().get(1, 3));
828 EXPECT_FLOAT_EQ(4.0,
829 child_of_rs2->screen_space_transform().matrix().get(1, 3));
830 EXPECT_FLOAT_EQ(
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,
853 true);
854 SetLayerPropertiesForTesting(child, rotation_about_y_axis, gfx::Point3F(),
855 gfx::PointF(), gfx::Size(10, 10), true, false,
856 true);
857 SetLayerPropertiesForTesting(grand_child, rotation_about_y_axis,
858 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
859 true, false, false);
860 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
861 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
862 true, false, false);
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,
963 true);
964 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
965 gfx::PointF(), gfx::Size(10, 0), true, false,
966 true);
967 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
968 gfx::PointF(), gfx::Size(10, 10), true, false,
969 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,
995 true);
996 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
997 gfx::PointF(), gfx::Size(20, 20), true, false,
998 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;
1014 scale.Scale(2, 2);
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;
1027 rotate.Rotate(2);
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,
1123 true);
1124 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1125 gfx::PointF(), gfx::Size(10, 10), true, false,
1126 true);
1127 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1128 gfx::PointF(30.f, 30.f), gfx::Size(10, 10), true,
1129 false, false);
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
1137 // of size 0).
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,
1151 true);
1152 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1153 gfx::PointF(), gfx::Size(10, 10), true, false,
1154 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,
1183 true);
1184 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1185 gfx::PointF(), gfx::Size(10, 10), true, false,
1186 true);
1187 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1188 gfx::PointF(), gfx::Size(10, 10), true, false,
1189 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,
1218 true);
1219 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1220 gfx::PointF(), gfx::Size(10, 10), true, false,
1221 true);
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(),
1249 identity_matrix,
1250 gfx::Point3F(),
1251 gfx::PointF(),
1252 gfx::Size(10, 10),
1253 true,
1254 false);
1255 SetLayerPropertiesForTesting(render_surface1.get(),
1256 identity_matrix,
1257 gfx::Point3F(),
1258 gfx::PointF(),
1259 gfx::Size(10, 10),
1260 true,
1261 false);
1262 SetLayerPropertiesForTesting(child.get(),
1263 identity_matrix,
1264 gfx::Point3F(),
1265 gfx::PointF(),
1266 gfx::Size(10, 10),
1267 true,
1268 false);
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(),
1279 parent->bounds());
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(),
1290 parent->bounds());
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,
1317 true);
1318 SetLayerPropertiesForTesting(parent, rotation_about_y_axis, gfx::Point3F(),
1319 gfx::PointF(), gfx::Size(10, 10), true, false,
1320 true);
1321 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1322 gfx::PointF(), gfx::Size(10, 10), true, false,
1323 false);
1324 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1325 gfx::PointF(), gfx::Size(10, 10), true, false,
1326 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
1375 // render surfaces.
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,
1394 true);
1395 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1396 gfx::PointF(), gfx::Size(20, 20), true, false,
1397 true);
1398 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1399 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
1400 false, false);
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,
1406 false);
1407 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1408 gfx::PointF(), gfx::Size(20, 20), true, false,
1409 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
1425 // of the surface.
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
1430 // the parent.
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,
1448 true);
1449 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1450 gfx::PointF(), gfx::Size(20, 20), true, false,
1451 true);
1452 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1453 gfx::PointF(200.f, 200.f), gfx::Size(10, 10),
1454 true, false, true);
1455 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
1456 gfx::PointF(), gfx::Size(10, 10), true, false,
1457 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
1475 // render target,
1476 // - a surface is clipped by an ancestor that contributes to the same
1477 // render target.
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(),
1507 identity_matrix,
1508 gfx::Point3F(),
1509 gfx::PointF(),
1510 gfx::Size(100, 100),
1511 true,
1512 false);
1513 SetLayerPropertiesForTesting(parent.get(),
1514 identity_matrix,
1515 gfx::Point3F(),
1516 gfx::PointF(),
1517 gfx::Size(100, 100),
1518 true,
1519 false);
1520 SetLayerPropertiesForTesting(child1.get(),
1521 identity_matrix,
1522 gfx::Point3F(),
1523 gfx::PointF(),
1524 gfx::Size(100, 100),
1525 true,
1526 false);
1527 SetLayerPropertiesForTesting(child2.get(),
1528 identity_matrix,
1529 gfx::Point3F(),
1530 gfx::PointF(),
1531 gfx::Size(100, 100),
1532 true,
1533 false);
1534 SetLayerPropertiesForTesting(grand_child.get(),
1535 identity_matrix,
1536 gfx::Point3F(),
1537 gfx::PointF(),
1538 gfx::Size(100, 100),
1539 true,
1540 false);
1541 SetLayerPropertiesForTesting(leaf_node1.get(),
1542 identity_matrix,
1543 gfx::Point3F(),
1544 gfx::PointF(),
1545 gfx::Size(100, 100),
1546 true,
1547 false);
1548 SetLayerPropertiesForTesting(leaf_node2.get(),
1549 identity_matrix,
1550 gfx::Point3F(),
1551 gfx::PointF(),
1552 gfx::Size(100, 100),
1553 true,
1554 false);
1556 // Case 1: nothing is clipped except the root render surface.
1558 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(root.get(),
1559 parent->bounds());
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
1577 // that clip.
1579 parent->SetMasksToBounds(true);
1580 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(root.get(),
1581 parent->bounds());
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(),
1602 parent->bounds());
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,
1635 true);
1636 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1637 gfx::PointF(), gfx::Size(100, 100), true, false,
1638 false);
1639 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1640 gfx::PointF(), gfx::Size(100, 100), true, false,
1641 false);
1642 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1643 gfx::PointF(), gfx::Size(100, 100), true, false,
1644 true);
1645 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1646 gfx::PointF(), gfx::Size(100, 100), true, false,
1647 false);
1648 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1649 gfx::PointF(), gfx::Size(100, 100), true, false,
1650 false);
1651 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1652 gfx::PointF(), gfx::Size(100, 100), true, false,
1653 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
1676 // that clip.
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
1736 // the mask region.
1737 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1738 // be empty.
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,
1750 true);
1751 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1752 gfx::PointF(), gfx::Size(20, 20), true, false,
1753 true);
1754 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
1755 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
1756 false, false);
1757 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
1758 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
1759 false, false);
1760 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
1761 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
1762 false, false);
1763 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
1764 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
1765 false, false);
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
1796 // this test.
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,
1810 true);
1811 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1812 gfx::PointF(), gfx::Size(20, 20), true, false,
1813 true);
1814 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
1815 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
1816 false, true);
1817 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
1818 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
1819 false, true);
1820 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
1821 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
1822 false, true);
1823 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
1824 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
1825 false, true);
1826 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1827 gfx::PointF(), gfx::Size(10, 10), true, false,
1828 false);
1829 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1830 gfx::PointF(), gfx::Size(10, 10), true, false,
1831 false);
1832 SetLayerPropertiesForTesting(leaf_node3, identity_matrix, gfx::Point3F(),
1833 gfx::PointF(), gfx::Size(10, 10), true, false,
1834 false);
1835 SetLayerPropertiesForTesting(leaf_node4, identity_matrix, gfx::Point3F(),
1836 gfx::PointF(), gfx::Size(10, 10), true, false,
1837 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
1857 // masksToBounds.
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));
1976 EXPECT_FLOAT_EQ(
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));
1983 EXPECT_FLOAT_EQ(
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));
1990 EXPECT_FLOAT_EQ(
1991 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
1994 TEST_F(LayerTreeHostCommonTest,
1995 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) {
1996 LayerImpl* parent = root_layer();
1997 LayerImpl* child = AddChild<LayerImpl>(parent);
1998 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1999 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
2001 parent->SetDrawsContent(true);
2002 child->SetDrawsContent(true);
2003 grand_child->SetDrawsContent(true);
2004 great_grand_child->SetDrawsContent(true);
2006 gfx::Transform identity;
2008 SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(),
2009 gfx::Size(10, 10), true, false, true);
2010 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
2011 gfx::Size(10, 10), true, false, false);
2012 SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(),
2013 gfx::PointF(), gfx::Size(10, 10), true, false,
2014 false);
2015 SetLayerPropertiesForTesting(great_grand_child, identity, gfx::Point3F(),
2016 gfx::PointF(), gfx::Size(10, 10), true, false,
2017 false);
2019 // Add a transform animation with a start delay to |grand_child|.
2020 scoped_ptr<Animation> animation = Animation::Create(
2021 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), 0, 1,
2022 Animation::TRANSFORM);
2023 animation->set_fill_mode(Animation::FILL_MODE_NONE);
2024 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
2025 grand_child->layer_animation_controller()->AddAnimation(animation.Pass());
2027 ExecuteCalculateDrawProperties(parent);
2029 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2030 EXPECT_FALSE(child->screen_space_transform_is_animating());
2032 EXPECT_FALSE(grand_child->TransformIsAnimating());
2033 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation());
2034 EXPECT_TRUE(grand_child->screen_space_transform_is_animating());
2035 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating());
2038 TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
2039 // Test the calculateVisibleRect() function works correctly for identity
2040 // transforms.
2042 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2043 gfx::Transform layer_to_surface_transform;
2045 // Case 1: Layer is contained within the surface.
2046 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
2047 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
2048 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2049 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2050 EXPECT_EQ(expected, actual);
2052 // Case 2: Layer is outside the surface rect.
2053 layer_content_rect = gfx::Rect(120, 120, 30, 30);
2054 actual = LayerTreeHostCommon::CalculateVisibleRect(
2055 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2056 EXPECT_TRUE(actual.IsEmpty());
2058 // Case 3: Layer is partially overlapping the surface rect.
2059 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2060 expected = gfx::Rect(80, 80, 20, 20);
2061 actual = LayerTreeHostCommon::CalculateVisibleRect(
2062 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2063 EXPECT_EQ(expected, actual);
2066 TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
2067 // Test the calculateVisibleRect() function works correctly for scaling
2068 // transforms.
2070 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2071 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
2072 gfx::Transform layer_to_surface_transform;
2074 // Case 1: Layer is contained within the surface.
2075 layer_to_surface_transform.MakeIdentity();
2076 layer_to_surface_transform.Translate(10.0, 10.0);
2077 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
2078 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2079 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2080 EXPECT_EQ(expected, actual);
2082 // Case 2: Layer is outside the surface rect.
2083 layer_to_surface_transform.MakeIdentity();
2084 layer_to_surface_transform.Translate(120.0, 120.0);
2085 actual = LayerTreeHostCommon::CalculateVisibleRect(
2086 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2087 EXPECT_TRUE(actual.IsEmpty());
2089 // Case 3: Layer is partially overlapping the surface rect.
2090 layer_to_surface_transform.MakeIdentity();
2091 layer_to_surface_transform.Translate(80.0, 80.0);
2092 expected = gfx::Rect(0, 0, 20, 20);
2093 actual = LayerTreeHostCommon::CalculateVisibleRect(
2094 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2095 EXPECT_EQ(expected, actual);
2098 TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
2099 // Test the calculateVisibleRect() function works correctly for rotations
2100 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2101 // should return the g in the layer's space.
2103 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2104 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
2105 gfx::Transform layer_to_surface_transform;
2107 // Case 1: Layer is contained within the surface.
2108 layer_to_surface_transform.MakeIdentity();
2109 layer_to_surface_transform.Translate(50.0, 50.0);
2110 layer_to_surface_transform.Rotate(45.0);
2111 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
2112 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2113 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2114 EXPECT_EQ(expected, actual);
2116 // Case 2: Layer is outside the surface rect.
2117 layer_to_surface_transform.MakeIdentity();
2118 layer_to_surface_transform.Translate(-50.0, 0.0);
2119 layer_to_surface_transform.Rotate(45.0);
2120 actual = LayerTreeHostCommon::CalculateVisibleRect(
2121 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2122 EXPECT_TRUE(actual.IsEmpty());
2124 // Case 3: The layer is rotated about its top-left corner. In surface space,
2125 // the layer is oriented diagonally, with the left half outside of the render
2126 // surface. In this case, the g should still be the entire layer
2127 // (remember the g is computed in layer space); both the top-left
2128 // and bottom-right corners of the layer are still visible.
2129 layer_to_surface_transform.MakeIdentity();
2130 layer_to_surface_transform.Rotate(45.0);
2131 expected = gfx::Rect(0, 0, 30, 30);
2132 actual = LayerTreeHostCommon::CalculateVisibleRect(
2133 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2134 EXPECT_EQ(expected, actual);
2136 // Case 4: The layer is rotated about its top-left corner, and translated
2137 // upwards. In surface space, the layer is oriented diagonally, with only the
2138 // top corner of the surface overlapping the layer. In layer space, the render
2139 // surface overlaps the right side of the layer. The g should be
2140 // the layer's right half.
2141 layer_to_surface_transform.MakeIdentity();
2142 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2143 layer_to_surface_transform.Rotate(45.0);
2144 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
2145 actual = LayerTreeHostCommon::CalculateVisibleRect(
2146 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2147 EXPECT_EQ(expected, actual);
2150 TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
2151 // Test that the calculateVisibleRect() function works correctly for 3d
2152 // transforms.
2154 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2155 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
2156 gfx::Transform layer_to_surface_transform;
2158 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2159 // degrees, should be fully contained in the render surface.
2160 layer_to_surface_transform.MakeIdentity();
2161 layer_to_surface_transform.RotateAboutYAxis(45.0);
2162 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
2163 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2164 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2165 EXPECT_EQ(expected, actual);
2167 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2168 // degrees, but shifted to the side so only the right-half the layer would be
2169 // visible on the surface.
2170 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2171 SkMScalar half_width_of_rotated_layer =
2172 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2173 layer_to_surface_transform.MakeIdentity();
2174 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
2175 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2176 // edge of the layer.
2177 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2178 actual = LayerTreeHostCommon::CalculateVisibleRect(
2179 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2180 EXPECT_EQ(expected, actual);
2183 TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
2184 // Test the calculateVisibleRect() function works correctly when the layer has
2185 // a perspective projection onto the target surface.
2187 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2188 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
2189 gfx::Transform layer_to_surface_transform;
2191 // Case 1: Even though the layer is twice as large as the surface, due to
2192 // perspective foreshortening, the layer will fit fully in the surface when
2193 // its translated more than the perspective amount.
2194 layer_to_surface_transform.MakeIdentity();
2196 // The following sequence of transforms applies the perspective about the
2197 // center of the surface.
2198 layer_to_surface_transform.Translate(50.0, 50.0);
2199 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2200 layer_to_surface_transform.Translate(-50.0, -50.0);
2202 // This translate places the layer in front of the surface's projection plane.
2203 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2205 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
2206 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2207 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2208 EXPECT_EQ(expected, actual);
2210 // Case 2: same projection as before, except that the layer is also translated
2211 // to the side, so that only the right half of the layer should be visible.
2213 // Explanation of expected result: The perspective ratio is (z distance
2214 // between layer and camera origin) / (z distance between projection plane and
2215 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2216 // move a layer by translating -50 units in projected surface units (so that
2217 // only half of it is visible), then we would need to translate by (-36 / 9) *
2218 // -50 == -200 in the layer's units.
2219 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
2220 expected = gfx::Rect(gfx::Point(50, -50),
2221 gfx::Size(100, 200)); // The right half of the layer's
2222 // bounding rect.
2223 actual = LayerTreeHostCommon::CalculateVisibleRect(
2224 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2225 EXPECT_EQ(expected, actual);
2228 TEST_F(LayerTreeHostCommonTest,
2229 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
2230 // There is currently no explicit concept of an orthographic projection plane
2231 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2232 // are technically behind the surface in an orthographic world should not be
2233 // clipped when they are flattened to the surface.
2235 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2236 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
2237 gfx::Transform layer_to_surface_transform;
2239 // This sequence of transforms effectively rotates the layer about the y-axis
2240 // at the center of the layer.
2241 layer_to_surface_transform.MakeIdentity();
2242 layer_to_surface_transform.Translate(50.0, 0.0);
2243 layer_to_surface_transform.RotateAboutYAxis(45.0);
2244 layer_to_surface_transform.Translate(-50.0, 0.0);
2246 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
2247 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2248 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2249 EXPECT_EQ(expected, actual);
2252 TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
2253 // Test the calculateVisibleRect() function works correctly when projecting a
2254 // surface onto a layer, but the layer is partially behind the camera (not
2255 // just behind the projection plane). In this case, the cartesian coordinates
2256 // may seem to be valid, but actually they are not. The visible rect needs to
2257 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2258 // converting to cartesian coordinates.
2260 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2261 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
2262 gfx::Transform layer_to_surface_transform;
2264 // The layer is positioned so that the right half of the layer should be in
2265 // front of the camera, while the other half is behind the surface's
2266 // projection plane. The following sequence of transforms applies the
2267 // perspective and rotation about the center of the layer.
2268 layer_to_surface_transform.MakeIdentity();
2269 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2270 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2271 layer_to_surface_transform.RotateAboutYAxis(45.0);
2273 // Sanity check that this transform does indeed cause w < 0 when applying the
2274 // transform, otherwise this code is not testing the intended scenario.
2275 bool clipped;
2276 MathUtil::MapQuad(layer_to_surface_transform,
2277 gfx::QuadF(gfx::RectF(layer_content_rect)),
2278 &clipped);
2279 ASSERT_TRUE(clipped);
2281 int expected_x_position = 0;
2282 int expected_width = 10;
2283 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2284 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2285 EXPECT_EQ(expected_x_position, actual.x());
2286 EXPECT_EQ(expected_width, actual.width());
2289 TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
2290 // To determine visible rect in layer space, there needs to be an
2291 // un-projection from surface space to layer space. When the original
2292 // transform was a perspective projection that was clipped, it returns a rect
2293 // that encloses the clipped bounds. Un-projecting this new rect may require
2294 // clipping again.
2296 // This sequence of transforms causes one corner of the layer to protrude
2297 // across the w = 0 plane, and should be clipped.
2298 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2299 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
2300 gfx::Transform layer_to_surface_transform;
2301 layer_to_surface_transform.MakeIdentity();
2302 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2303 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2304 layer_to_surface_transform.RotateAboutYAxis(45.0);
2305 layer_to_surface_transform.RotateAboutXAxis(80.0);
2307 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2308 // code is not testing the intended scenario.
2309 bool clipped;
2310 gfx::RectF clipped_rect = MathUtil::MapClippedRect(
2311 layer_to_surface_transform, gfx::RectF(layer_content_rect));
2312 MathUtil::ProjectQuad(
2313 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2314 ASSERT_TRUE(clipped);
2316 // Only the corner of the layer is not visible on the surface because of being
2317 // clipped. But, the net result of rounding visible region to an axis-aligned
2318 // rect is that the entire layer should still be considered visible.
2319 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
2320 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2321 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2322 EXPECT_EQ(expected, actual);
2325 TEST_F(LayerTreeHostCommonTest,
2326 VisibleRectsForPositionedRootLayerClippedByViewport) {
2327 LayerImpl* root = root_layer();
2328 root->SetDrawsContent(true);
2330 gfx::Transform identity_matrix;
2331 // Root layer is positioned at (60, 70). The default device viewport size
2332 // is (0, 0, 100x100) in target space. So the root layer's visible rect
2333 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
2334 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2335 gfx::PointF(60, 70), gfx::Size(100, 100), true,
2336 false, true);
2337 ExecuteCalculateDrawProperties(root);
2339 EXPECT_EQ(gfx::RectF(100.f, 100.f),
2340 root->render_surface()->DrawableContentRect());
2341 // In target space, not clipped.
2342 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
2343 // In layer space, clipped.
2344 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect());
2347 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
2348 LayerImpl* root = root_layer();
2349 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>();
2350 child1_layer->SetDrawsContent(true);
2351 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>();
2352 child2_layer->SetDrawsContent(true);
2353 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>();
2354 child3_layer->SetDrawsContent(true);
2356 gfx::Transform identity_matrix;
2357 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2358 gfx::PointF(), gfx::Size(100, 100), true, false,
2359 true);
2360 SetLayerPropertiesForTesting(child1_layer, identity_matrix, gfx::Point3F(),
2361 gfx::PointF(), gfx::Size(50, 50), true, false,
2362 false);
2363 SetLayerPropertiesForTesting(child2_layer, identity_matrix, gfx::Point3F(),
2364 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2365 false, false);
2366 SetLayerPropertiesForTesting(child3_layer, identity_matrix, gfx::Point3F(),
2367 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2368 true, false, false);
2370 ExecuteCalculateDrawProperties(root);
2372 EXPECT_EQ(gfx::RectF(100.f, 100.f),
2373 root->render_surface()->DrawableContentRect());
2374 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
2376 // Layers that do not draw content should have empty visible_layer_rects.
2377 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2379 // layer visible_layer_rects are clipped by their target surface.
2380 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect());
2381 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect());
2382 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty());
2384 // layer drawable_content_rects are not clipped.
2385 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect());
2386 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect());
2387 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect());
2390 TEST_F(LayerTreeHostCommonTest,
2391 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
2392 LayerImpl* root = root_layer();
2393 LayerImpl* child = AddChildToRoot<LayerImpl>();
2394 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2395 grand_child1->SetDrawsContent(true);
2396 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2397 grand_child2->SetDrawsContent(true);
2398 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2399 grand_child3->SetDrawsContent(true);
2401 gfx::Transform identity_matrix;
2402 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2403 gfx::PointF(), gfx::Size(100, 100), true, false,
2404 true);
2405 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2406 gfx::PointF(), gfx::Size(100, 100), true, false,
2407 false);
2408 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2409 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2410 false, false);
2411 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2412 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2413 false, false);
2414 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
2415 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2416 true, false, false);
2418 child->SetMasksToBounds(true);
2419 ExecuteCalculateDrawProperties(root);
2421 EXPECT_EQ(gfx::RectF(100.f, 100.f),
2422 root->render_surface()->DrawableContentRect());
2423 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
2425 // Layers that do not draw content should have empty visible content rects.
2426 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2427 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
2429 // All grandchild visible content rects should be clipped by child.
2430 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect());
2431 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect());
2432 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty());
2434 // All grandchild DrawableContentRects should also be clipped by child.
2435 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
2436 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
2437 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2440 TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
2441 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2442 scoped_refptr<Layer> child = Layer::Create(layer_settings());
2443 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
2444 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2445 root->AddChild(child);
2446 child->AddChild(grand_child);
2448 host()->SetRootLayer(root);
2450 gfx::Transform identity_matrix;
2451 gfx::Transform child_scale_matrix;
2452 child_scale_matrix.Scale(0.25f, 0.25f);
2453 gfx::Transform grand_child_scale_matrix;
2454 grand_child_scale_matrix.Scale(0.246f, 0.246f);
2455 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2456 gfx::PointF(), gfx::Size(100, 100), true, false);
2457 SetLayerPropertiesForTesting(child.get(), child_scale_matrix, gfx::Point3F(),
2458 gfx::PointF(), gfx::Size(10, 10), true, false);
2459 SetLayerPropertiesForTesting(grand_child.get(), grand_child_scale_matrix,
2460 gfx::Point3F(), gfx::PointF(),
2461 gfx::Size(100, 100), true, false);
2463 child->SetMasksToBounds(true);
2464 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
2466 // The visible rect is expanded to integer coordinates in target space before
2467 // being projected back to layer space, where it is once again expanded to
2468 // integer coordinates.
2469 EXPECT_EQ(gfx::Rect(49, 49), grand_child->visible_rect_from_property_trees());
2472 TEST_F(LayerTreeHostCommonTest,
2473 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
2474 LayerImpl* root = root_layer();
2475 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
2476 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
2477 child1->SetDrawsContent(true);
2478 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
2479 child2->SetDrawsContent(true);
2480 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
2481 child3->SetDrawsContent(true);
2483 gfx::Transform identity_matrix;
2484 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2485 gfx::PointF(), gfx::Size(100, 100), true, false,
2486 true);
2487 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
2488 gfx::PointF(), gfx::Size(3, 4), true, false,
2489 true);
2490 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2491 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2492 false, false);
2493 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2494 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2495 false, false);
2496 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
2497 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2498 true, false, false);
2500 ExecuteCalculateDrawProperties(root);
2502 ASSERT_TRUE(render_surface->render_surface());
2504 EXPECT_EQ(gfx::RectF(100.f, 100.f),
2505 root->render_surface()->DrawableContentRect());
2506 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
2508 // Layers that do not draw content should have empty visible content rects.
2509 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2510 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
2512 // An unclipped surface grows its DrawableContentRect to include all drawable
2513 // regions of the subtree.
2514 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
2515 render_surface->render_surface()->DrawableContentRect());
2517 // All layers that draw content into the unclipped surface are also unclipped.
2518 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
2519 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
2520 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
2522 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2523 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2524 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2527 TEST_F(LayerTreeHostCommonTest,
2528 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
2529 LayerImpl* root = root_layer();
2530 LayerImpl* child1 = AddChild<LayerImpl>(root);
2531 LayerImpl* child2 = AddChild<LayerImpl>(root);
2532 LayerImpl* child3 = AddChild<LayerImpl>(root);
2533 child1->SetDrawsContent(true);
2534 child2->SetDrawsContent(true);
2535 child3->SetDrawsContent(true);
2537 gfx::Transform identity_matrix;
2538 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2539 gfx::PointF(), gfx::Size(100, 100), true, false,
2540 true);
2541 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2542 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2543 false, false);
2544 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2545 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2546 false, false);
2547 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
2548 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2549 true, false, false);
2551 LayerImplList render_surface_layer_list_impl;
2552 // Now set the root render surface an empty clip.
2553 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
2554 root, gfx::Size(), &render_surface_layer_list_impl);
2556 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
2557 ASSERT_TRUE(root->render_surface());
2558 EXPECT_FALSE(root->is_clipped());
2560 gfx::Rect empty;
2561 EXPECT_EQ(empty, root->render_surface()->clip_rect());
2562 EXPECT_TRUE(root->render_surface()->is_clipped());
2564 // Visible content rect calculation will check if the target surface is
2565 // clipped or not. An empty clip rect does not indicate the render surface
2566 // is unclipped.
2567 EXPECT_EQ(empty, child1->visible_layer_rect());
2568 EXPECT_EQ(empty, child2->visible_layer_rect());
2569 EXPECT_EQ(empty, child3->visible_layer_rect());
2572 TEST_F(LayerTreeHostCommonTest,
2573 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
2574 LayerImpl* root = root_layer();
2575 LayerImpl* child = AddChildToRoot<LayerImpl>();
2576 child->SetDrawsContent(true);
2578 // Case 1: a truly degenerate matrix
2579 gfx::Transform identity_matrix;
2580 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2581 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2583 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2584 gfx::PointF(), gfx::Size(100, 100), true, false,
2585 true);
2586 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
2587 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2588 false, false);
2590 ExecuteCalculateDrawProperties(root);
2592 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
2593 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
2595 // Case 2: a matrix with flattened z, uninvertible and not visible according
2596 // to the CSS spec.
2597 uninvertible_matrix.MakeIdentity();
2598 uninvertible_matrix.matrix().set(2, 2, 0.0);
2599 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2601 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
2602 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2603 false, false);
2605 ExecuteCalculateDrawProperties(root);
2607 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
2608 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
2610 // Case 3: a matrix with flattened z, also uninvertible and not visible.
2611 uninvertible_matrix.MakeIdentity();
2612 uninvertible_matrix.Translate(500.0, 0.0);
2613 uninvertible_matrix.matrix().set(2, 2, 0.0);
2614 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2616 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
2617 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2618 false, false);
2620 ExecuteCalculateDrawProperties(root);
2622 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
2623 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
2626 TEST_F(LayerTreeHostCommonTest,
2627 VisibleContentRectForLayerWithUninvertibleDrawTransform) {
2628 LayerImpl* root = root_layer();
2629 LayerImpl* child = AddChildToRoot<LayerImpl>();
2630 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2631 child->SetDrawsContent(true);
2632 grand_child->SetDrawsContent(true);
2634 gfx::Transform identity_matrix;
2636 gfx::Transform perspective;
2637 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
2639 gfx::Transform rotation;
2640 rotation.RotateAboutYAxis(45.0);
2642 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2643 gfx::PointF(), gfx::Size(100, 100), true, false,
2644 true);
2645 SetLayerPropertiesForTesting(child, perspective, gfx::Point3F(),
2646 gfx::PointF(10.f, 10.f), gfx::Size(100, 100),
2647 false, true, false);
2648 SetLayerPropertiesForTesting(grand_child, rotation, gfx::Point3F(),
2649 gfx::PointF(), gfx::Size(100, 100), false, true,
2650 false);
2652 ExecuteCalculateDrawProperties(root);
2654 // Though all layers have invertible transforms, matrix multiplication using
2655 // floating-point math makes the draw transform uninvertible.
2656 EXPECT_FALSE(grand_child->draw_transform().IsInvertible());
2658 // CalcDrawProps only skips a subtree when a layer's own transform is
2659 // uninvertible, not when its draw transform is invertible, since CDP makes
2660 // skipping decisions before computing a layer's draw transform. Property
2661 // trees make skipping decisions after computing draw transforms, so could be
2662 // made to skip layers with an uninvertible draw transform (once CDP is
2663 // deleted).
2664 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
2665 grand_child->visible_layer_rect());
2668 TEST_F(LayerTreeHostCommonTest,
2669 OcclusionForLayerWithUninvertibleDrawTransform) {
2670 FakeImplProxy proxy;
2671 TestSharedBitmapManager shared_bitmap_manager;
2672 TestTaskGraphRunner task_graph_runner;
2673 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
2674 &task_graph_runner);
2675 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
2676 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2);
2677 scoped_ptr<LayerImpl> grand_child =
2678 LayerImpl::Create(host_impl.active_tree(), 3);
2679 scoped_ptr<LayerImpl> occluding_child =
2680 LayerImpl::Create(host_impl.active_tree(), 4);
2681 child->SetDrawsContent(true);
2682 grand_child->SetDrawsContent(true);
2683 occluding_child->SetDrawsContent(true);
2684 occluding_child->SetContentsOpaque(true);
2686 gfx::Transform identity_matrix;
2687 gfx::Transform perspective;
2688 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
2690 gfx::Transform rotation;
2691 rotation.RotateAboutYAxis(45.0);
2693 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2694 gfx::PointF(), gfx::Size(1000, 1000), true,
2695 false, true);
2696 SetLayerPropertiesForTesting(child.get(), perspective, gfx::Point3F(),
2697 gfx::PointF(10.f, 10.f), gfx::Size(300, 300),
2698 false, true, false);
2699 SetLayerPropertiesForTesting(grand_child.get(), rotation, gfx::Point3F(),
2700 gfx::PointF(), gfx::Size(200, 200), false, true,
2701 false);
2702 SetLayerPropertiesForTesting(occluding_child.get(), identity_matrix,
2703 gfx::Point3F(), gfx::PointF(),
2704 gfx::Size(200, 200), false, false, false);
2706 host_impl.SetViewportSize(root->bounds());
2708 child->AddChild(grand_child.Pass());
2709 root->AddChild(child.Pass());
2710 root->AddChild(occluding_child.Pass());
2711 host_impl.active_tree()->SetRootLayer(root.Pass());
2712 host_impl.InitializeRenderer(FakeOutputSurface::Create3d());
2713 bool update_lcd_text = false;
2714 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
2716 LayerImpl* grand_child_ptr =
2717 host_impl.active_tree()->root_layer()->children()[0]->children()[0];
2719 // Though all layers have invertible transforms, matrix multiplication using
2720 // floating-point math makes the draw transform uninvertible.
2721 EXPECT_FALSE(grand_child_ptr->draw_transform().IsInvertible());
2723 // Since |grand_child| has an uninvertible draw transform, it is treated as
2724 // unoccluded (even though |occluding_child| comes later in draw order, and
2725 // hence potentially occludes it).
2726 gfx::Rect layer_bounds = gfx::Rect(grand_child_ptr->bounds());
2727 EXPECT_EQ(
2728 layer_bounds,
2729 grand_child_ptr->draw_properties()
2730 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds));
2733 TEST_F(LayerTreeHostCommonTest,
2734 SingularTransformDoesNotPreventClearingDrawProperties) {
2735 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2736 scoped_refptr<LayerWithForcedDrawsContent> child =
2737 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2738 root->AddChild(child);
2740 host()->SetRootLayer(root);
2742 gfx::Transform identity_matrix;
2743 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2744 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2746 SetLayerPropertiesForTesting(root.get(),
2747 uninvertible_matrix,
2748 gfx::Point3F(),
2749 gfx::PointF(),
2750 gfx::Size(100, 100),
2751 true,
2752 false);
2753 SetLayerPropertiesForTesting(child.get(),
2754 identity_matrix,
2755 gfx::Point3F(),
2756 gfx::PointF(5.f, 5.f),
2757 gfx::Size(50, 50),
2758 true,
2759 false);
2761 child->set_sorted_for_recursion(true);
2763 TransformOperations start_transform_operations;
2764 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
2766 TransformOperations end_transform_operations;
2767 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
2769 AddAnimatedTransformToLayer(
2770 root.get(), 10.0, start_transform_operations, end_transform_operations);
2772 EXPECT_TRUE(root->TransformIsAnimating());
2774 ExecuteCalculateDrawProperties(root.get());
2776 EXPECT_FALSE(child->sorted_for_recursion());
2779 TEST_F(LayerTreeHostCommonTest,
2780 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) {
2781 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2783 host()->SetRootLayer(root);
2785 gfx::Transform identity_matrix;
2786 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2787 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2789 SetLayerPropertiesForTesting(root.get(),
2790 uninvertible_matrix,
2791 gfx::Point3F(),
2792 gfx::PointF(),
2793 gfx::Size(100, 100),
2794 true,
2795 false);
2797 root->set_sorted_for_recursion(true);
2799 EXPECT_FALSE(root->TransformIsAnimating());
2801 ExecuteCalculateDrawProperties(root.get());
2803 EXPECT_FALSE(root->sorted_for_recursion());
2806 TEST_F(LayerTreeHostCommonTest,
2807 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
2808 LayerImpl* root = root_layer();
2809 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
2810 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
2811 child1->SetDrawsContent(true);
2812 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
2813 child2->SetDrawsContent(true);
2814 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
2815 child3->SetDrawsContent(true);
2817 gfx::Transform identity_matrix;
2818 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2819 gfx::PointF(), gfx::Size(100, 100), true, false,
2820 true);
2821 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
2822 gfx::PointF(), gfx::Size(3, 4), true, false,
2823 true);
2824 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2825 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2826 false, false);
2827 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2828 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2829 false, false);
2830 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
2831 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2832 true, false, false);
2834 root->SetMasksToBounds(true);
2836 ExecuteCalculateDrawProperties(root);
2838 ASSERT_TRUE(render_surface->render_surface());
2840 EXPECT_EQ(gfx::RectF(100.f, 100.f),
2841 root->render_surface()->DrawableContentRect());
2842 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
2844 // Layers that do not draw content should have empty visible content rects.
2845 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2846 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
2848 // A clipped surface grows its DrawableContentRect to include all drawable
2849 // regions of the subtree, but also gets clamped by the ancestor's clip.
2850 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
2851 render_surface->render_surface()->DrawableContentRect());
2853 // All layers that draw content into the surface have their visible content
2854 // rect clipped by the surface clip rect.
2855 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
2856 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
2857 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
2859 // But the DrawableContentRects are unclipped.
2860 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2861 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2862 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2865 TEST_F(LayerTreeHostCommonTest,
2866 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
2867 // Check that clipping does not propagate down surfaces.
2868 LayerImpl* root = root_layer();
2869 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
2870 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
2871 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2);
2872 child1->SetDrawsContent(true);
2873 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
2874 child2->SetDrawsContent(true);
2875 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2);
2876 child3->SetDrawsContent(true);
2878 gfx::Transform identity_matrix;
2879 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2880 gfx::PointF(), gfx::Size(100, 100), true, false,
2881 true);
2882 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
2883 gfx::PointF(), gfx::Size(3, 4), true, false,
2884 true);
2885 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
2886 gfx::PointF(), gfx::Size(7, 13), true, false,
2887 true);
2888 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2889 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2890 false, false);
2891 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2892 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2893 false, false);
2894 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
2895 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2896 true, false, false);
2898 root->SetMasksToBounds(true);
2900 ExecuteCalculateDrawProperties(root);
2902 ASSERT_TRUE(render_surface1->render_surface());
2903 ASSERT_TRUE(render_surface2->render_surface());
2905 EXPECT_EQ(gfx::RectF(100.f, 100.f),
2906 root->render_surface()->DrawableContentRect());
2907 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
2909 // Layers that do not draw content should have empty visible content rects.
2910 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2911 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
2912 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect());
2914 // A clipped surface grows its DrawableContentRect to include all drawable
2915 // regions of the subtree, but also gets clamped by the ancestor's clip.
2916 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
2917 render_surface1->render_surface()->DrawableContentRect());
2919 // render_surface1 lives in the "unclipped universe" of render_surface1, and
2920 // is only implicitly clipped by render_surface1's content rect. So,
2921 // render_surface2 grows to enclose all drawable content of its subtree.
2922 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
2923 render_surface2->render_surface()->DrawableContentRect());
2925 // All layers that draw content into render_surface2 think they are unclipped.
2926 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
2927 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
2928 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
2930 // DrawableContentRects are also unclipped.
2931 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2932 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2933 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2936 TEST_F(LayerTreeHostCommonTest,
2937 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
2938 // Layers that have non-axis aligned bounds (due to transforms) have an
2939 // expanded, axis-aligned DrawableContentRect and visible content rect.
2940 LayerImpl* root = root_layer();
2941 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
2942 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
2943 child1->SetDrawsContent(true);
2945 gfx::Transform identity_matrix;
2946 gfx::Transform child_rotation;
2947 child_rotation.Rotate(45.0);
2948 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2949 gfx::PointF(), gfx::Size(100, 100), true, false,
2950 true);
2951 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
2952 gfx::PointF(), gfx::Size(3, 4), true, false,
2953 true);
2954 SetLayerPropertiesForTesting(
2955 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
2956 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
2958 ExecuteCalculateDrawProperties(root);
2960 ASSERT_TRUE(render_surface->render_surface());
2962 EXPECT_EQ(gfx::RectF(100.f, 100.f),
2963 root->render_surface()->DrawableContentRect());
2964 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2966 // Layers that do not draw content should have empty visible content rects.
2967 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2968 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
2970 // The unclipped surface grows its DrawableContentRect to include all drawable
2971 // regions of the subtree.
2972 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
2973 gfx::Rect expected_surface_drawable_content =
2974 gfx::Rect(50 - diagonal_radius,
2975 50 - diagonal_radius,
2976 diagonal_radius * 2,
2977 diagonal_radius * 2);
2978 EXPECT_EQ(gfx::RectF(expected_surface_drawable_content),
2979 render_surface->render_surface()->DrawableContentRect());
2981 // All layers that draw content into the unclipped surface are also unclipped.
2982 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
2983 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
2986 TEST_F(LayerTreeHostCommonTest,
2987 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
2988 // Layers that have non-axis aligned bounds (due to transforms) have an
2989 // expanded, axis-aligned DrawableContentRect and visible content rect.
2990 LayerImpl* root = root_layer();
2991 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
2992 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
2993 child1->SetDrawsContent(true);
2995 gfx::Transform identity_matrix;
2996 gfx::Transform child_rotation;
2997 child_rotation.Rotate(45.0);
2998 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2999 gfx::PointF(), gfx::Size(50, 50), true, false,
3000 true);
3001 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
3002 gfx::PointF(), gfx::Size(3, 4), true, false,
3003 true);
3005 SetLayerPropertiesForTesting(
3006 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
3007 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
3009 root->SetMasksToBounds(true);
3011 ExecuteCalculateDrawProperties(root);
3013 ASSERT_TRUE(render_surface->render_surface());
3015 // The clipped surface clamps the DrawableContentRect that encloses the
3016 // rotated layer.
3017 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3018 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3019 50 - diagonal_radius,
3020 diagonal_radius * 2,
3021 diagonal_radius * 2);
3022 gfx::RectF expected_surface_drawable_content(
3023 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50)));
3024 EXPECT_EQ(expected_surface_drawable_content,
3025 render_surface->render_surface()->DrawableContentRect());
3027 // On the clipped surface, only a quarter of the child1 is visible, but when
3028 // rotating it back to child1's content space, the actual enclosing rect ends
3029 // up covering the full left half of child1.
3031 // Given the floating point math, this number is a little bit fuzzy.
3032 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_layer_rect());
3034 // The child's DrawableContentRect is unclipped.
3035 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
3038 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
3039 LayerImpl* root = root_layer();
3040 FakePictureLayerImpl* render_surface1 =
3041 AddChildToRoot<FakePictureLayerImpl>();
3042 render_surface1->SetDrawsContent(true);
3043 FakePictureLayerImpl* render_surface2 =
3044 AddChild<FakePictureLayerImpl>(render_surface1);
3045 render_surface2->SetDrawsContent(true);
3046 FakePictureLayerImpl* child1 =
3047 AddChild<FakePictureLayerImpl>(render_surface2);
3048 child1->SetDrawsContent(true);
3049 FakePictureLayerImpl* child2 =
3050 AddChild<FakePictureLayerImpl>(render_surface2);
3051 child2->SetDrawsContent(true);
3052 FakePictureLayerImpl* child3 =
3053 AddChild<FakePictureLayerImpl>(render_surface2);
3054 child3->SetDrawsContent(true);
3056 gfx::Transform identity_matrix;
3057 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3058 gfx::PointF(), gfx::Size(100, 100), true, false,
3059 true);
3060 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3061 gfx::PointF(5.f, 5.f), gfx::Size(3, 4), true,
3062 false, true);
3063 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3064 gfx::PointF(5.f, 5.f), gfx::Size(7, 13), true,
3065 false, true);
3066 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3067 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3068 false, false);
3069 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3070 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3071 false, false);
3072 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3073 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3074 true, false, false);
3076 float device_scale_factor = 2.f;
3078 root->SetMasksToBounds(true);
3080 ExecuteCalculateDrawProperties(root, device_scale_factor);
3082 ASSERT_TRUE(render_surface1->render_surface());
3083 ASSERT_TRUE(render_surface2->render_surface());
3085 // drawable_content_rects for all layers and surfaces are scaled by
3086 // device_scale_factor.
3087 EXPECT_EQ(gfx::RectF(200.f, 200.f),
3088 root->render_surface()->DrawableContentRect());
3089 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3090 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f),
3091 render_surface1->render_surface()->DrawableContentRect());
3093 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3094 // is only implicitly clipped by render_surface1.
3095 EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f),
3096 render_surface2->render_surface()->DrawableContentRect());
3098 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3099 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
3100 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
3102 // The root layer does not actually draw content of its own.
3103 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3105 // All layer visible content rects are not expressed in content space of each
3106 // layer, so they are not scaled by the device_scale_factor.
3107 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect());
3108 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect());
3109 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3110 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3111 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
3114 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
3115 // Verify the behavior of back-face culling when there are no preserve-3d
3116 // layers. Note that 3d transforms still apply in this case, but they are
3117 // "flattened" to each parent layer according to current W3C spec.
3119 const gfx::Transform identity_matrix;
3120 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
3121 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3122 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3123 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3124 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3125 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3126 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3127 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3128 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3129 scoped_refptr<LayerWithForcedDrawsContent>
3130 front_facing_child_of_front_facing_surface =
3131 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3132 scoped_refptr<LayerWithForcedDrawsContent>
3133 back_facing_child_of_front_facing_surface =
3134 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3135 scoped_refptr<LayerWithForcedDrawsContent>
3136 front_facing_child_of_back_facing_surface =
3137 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3138 scoped_refptr<LayerWithForcedDrawsContent>
3139 back_facing_child_of_back_facing_surface =
3140 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3142 parent->AddChild(front_facing_child);
3143 parent->AddChild(back_facing_child);
3144 parent->AddChild(front_facing_surface);
3145 parent->AddChild(back_facing_surface);
3146 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3147 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3148 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3149 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3151 host()->SetRootLayer(parent);
3153 // Nothing is double-sided
3154 front_facing_child->SetDoubleSided(false);
3155 back_facing_child->SetDoubleSided(false);
3156 front_facing_surface->SetDoubleSided(false);
3157 back_facing_surface->SetDoubleSided(false);
3158 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3159 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3160 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3161 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3163 gfx::Transform backface_matrix;
3164 backface_matrix.Translate(50.0, 50.0);
3165 backface_matrix.RotateAboutYAxis(180.0);
3166 backface_matrix.Translate(-50.0, -50.0);
3168 // Having a descendant and opacity will force these to have render surfaces.
3169 front_facing_surface->SetOpacity(0.5f);
3170 back_facing_surface->SetOpacity(0.5f);
3172 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3173 // these layers should blindly use their own local transforms to determine
3174 // back-face culling.
3175 SetLayerPropertiesForTesting(parent.get(),
3176 identity_matrix,
3177 gfx::Point3F(),
3178 gfx::PointF(),
3179 gfx::Size(100, 100),
3180 true,
3181 false);
3182 SetLayerPropertiesForTesting(front_facing_child.get(),
3183 identity_matrix,
3184 gfx::Point3F(),
3185 gfx::PointF(),
3186 gfx::Size(100, 100),
3187 true,
3188 false);
3189 SetLayerPropertiesForTesting(back_facing_child.get(),
3190 backface_matrix,
3191 gfx::Point3F(),
3192 gfx::PointF(),
3193 gfx::Size(100, 100),
3194 true,
3195 false);
3196 SetLayerPropertiesForTesting(front_facing_surface.get(),
3197 identity_matrix,
3198 gfx::Point3F(),
3199 gfx::PointF(),
3200 gfx::Size(100, 100),
3201 true,
3202 false);
3203 SetLayerPropertiesForTesting(back_facing_surface.get(),
3204 backface_matrix,
3205 gfx::Point3F(),
3206 gfx::PointF(),
3207 gfx::Size(100, 100),
3208 true,
3209 false);
3210 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3211 identity_matrix,
3212 gfx::Point3F(),
3213 gfx::PointF(),
3214 gfx::Size(100, 100),
3215 true,
3216 false);
3217 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3218 backface_matrix,
3219 gfx::Point3F(),
3220 gfx::PointF(),
3221 gfx::Size(100, 100),
3222 true,
3223 false);
3224 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3225 identity_matrix,
3226 gfx::Point3F(),
3227 gfx::PointF(),
3228 gfx::Size(100, 100),
3229 true,
3230 false);
3231 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3232 backface_matrix,
3233 gfx::Point3F(),
3234 gfx::PointF(),
3235 gfx::Size(100, 100),
3236 true,
3237 false);
3239 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
3241 // Verify which render surfaces were created.
3242 EXPECT_FALSE(front_facing_child->has_render_surface());
3243 EXPECT_FALSE(back_facing_child->has_render_surface());
3244 EXPECT_TRUE(front_facing_surface->has_render_surface());
3245 EXPECT_TRUE(back_facing_surface->has_render_surface());
3246 EXPECT_FALSE(
3247 front_facing_child_of_front_facing_surface->has_render_surface());
3248 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
3249 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
3250 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
3252 EXPECT_EQ(4u, update_layer_list().size());
3253 EXPECT_TRUE(UpdateLayerListContains(front_facing_child->id()));
3254 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
3255 EXPECT_TRUE(UpdateLayerListContains(
3256 front_facing_child_of_front_facing_surface->id()));
3257 EXPECT_TRUE(
3258 UpdateLayerListContains(front_facing_child_of_back_facing_surface->id()));
3261 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
3262 // Verify the behavior of back-face culling when preserves-3d transform style
3263 // is used.
3265 const gfx::Transform identity_matrix;
3266 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
3267 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3268 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3269 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3270 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3271 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3272 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3273 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3274 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3275 scoped_refptr<LayerWithForcedDrawsContent>
3276 front_facing_child_of_front_facing_surface =
3277 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3278 scoped_refptr<LayerWithForcedDrawsContent>
3279 back_facing_child_of_front_facing_surface =
3280 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3281 scoped_refptr<LayerWithForcedDrawsContent>
3282 front_facing_child_of_back_facing_surface =
3283 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3284 scoped_refptr<LayerWithForcedDrawsContent>
3285 back_facing_child_of_back_facing_surface =
3286 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3287 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3288 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3289 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3290 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3292 parent->AddChild(front_facing_child);
3293 parent->AddChild(back_facing_child);
3294 parent->AddChild(front_facing_surface);
3295 parent->AddChild(back_facing_surface);
3296 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3297 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3298 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3299 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3301 host()->SetRootLayer(parent);
3303 // Nothing is double-sided
3304 front_facing_child->SetDoubleSided(false);
3305 back_facing_child->SetDoubleSided(false);
3306 front_facing_surface->SetDoubleSided(false);
3307 back_facing_surface->SetDoubleSided(false);
3308 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3309 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3310 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3311 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3313 gfx::Transform backface_matrix;
3314 backface_matrix.Translate(50.0, 50.0);
3315 backface_matrix.RotateAboutYAxis(180.0);
3316 backface_matrix.Translate(-50.0, -50.0);
3318 // Opacity will not force creation of render surfaces in this case because of
3319 // the preserve-3d transform style. Instead, an example of when a surface
3320 // would be created with preserve-3d is when there is a replica layer.
3321 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3322 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3324 // Each surface creates its own new 3d rendering context (as defined by W3C
3325 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3326 // rendering context should use the transform with respect to that context.
3327 // This 3d rendering context occurs when (a) parent's transform style is flat
3328 // and (b) the layer's transform style is preserve-3d.
3329 SetLayerPropertiesForTesting(parent.get(),
3330 identity_matrix,
3331 gfx::Point3F(),
3332 gfx::PointF(),
3333 gfx::Size(100, 100),
3334 true,
3335 false); // parent transform style is flat.
3336 SetLayerPropertiesForTesting(front_facing_child.get(),
3337 identity_matrix,
3338 gfx::Point3F(),
3339 gfx::PointF(),
3340 gfx::Size(100, 100),
3341 true,
3342 false);
3343 SetLayerPropertiesForTesting(back_facing_child.get(),
3344 backface_matrix,
3345 gfx::Point3F(),
3346 gfx::PointF(),
3347 gfx::Size(100, 100),
3348 true,
3349 false);
3350 // surface transform style is preserve-3d.
3351 SetLayerPropertiesForTesting(front_facing_surface.get(),
3352 identity_matrix,
3353 gfx::Point3F(),
3354 gfx::PointF(),
3355 gfx::Size(100, 100),
3356 false,
3357 true);
3358 // surface transform style is preserve-3d.
3359 SetLayerPropertiesForTesting(back_facing_surface.get(),
3360 backface_matrix,
3361 gfx::Point3F(),
3362 gfx::PointF(),
3363 gfx::Size(100, 100),
3364 false,
3365 true);
3366 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3367 identity_matrix,
3368 gfx::Point3F(),
3369 gfx::PointF(),
3370 gfx::Size(100, 100),
3371 true,
3372 true);
3373 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3374 backface_matrix,
3375 gfx::Point3F(),
3376 gfx::PointF(),
3377 gfx::Size(100, 100),
3378 true,
3379 true);
3380 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3381 identity_matrix,
3382 gfx::Point3F(),
3383 gfx::PointF(),
3384 gfx::Size(100, 100),
3385 true,
3386 true);
3387 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3388 backface_matrix,
3389 gfx::Point3F(),
3390 gfx::PointF(),
3391 gfx::Size(100, 100),
3392 true,
3393 true);
3395 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
3397 // Verify which render surfaces were created and used.
3398 EXPECT_FALSE(front_facing_child->has_render_surface());
3399 EXPECT_FALSE(back_facing_child->has_render_surface());
3400 EXPECT_TRUE(front_facing_surface->has_render_surface());
3401 // We expect that a has_render_surface was created but not used.
3402 EXPECT_TRUE(back_facing_surface->has_render_surface());
3403 EXPECT_FALSE(
3404 front_facing_child_of_front_facing_surface->has_render_surface());
3405 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
3406 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
3407 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
3409 EXPECT_EQ(3u, update_layer_list().size());
3411 EXPECT_TRUE(UpdateLayerListContains(front_facing_child->id()));
3412 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
3413 EXPECT_TRUE(UpdateLayerListContains(
3414 front_facing_child_of_front_facing_surface->id()));
3417 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
3418 // Verify that layers are appropriately culled when their back face is showing
3419 // and they are not double sided, while animations are going on.
3421 // Layers that are animating do not get culled on the main thread, as their
3422 // transforms should be treated as "unknown" so we can not be sure that their
3423 // back face is really showing.
3424 const gfx::Transform identity_matrix;
3425 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
3426 scoped_refptr<LayerWithForcedDrawsContent> child =
3427 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3428 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
3429 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3430 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
3431 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3432 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
3433 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3434 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3435 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3437 parent->AddChild(child);
3438 parent->AddChild(animating_surface);
3439 animating_surface->AddChild(child_of_animating_surface);
3440 parent->AddChild(animating_child);
3441 parent->AddChild(child2);
3443 host()->SetRootLayer(parent);
3445 // Nothing is double-sided
3446 child->SetDoubleSided(false);
3447 child2->SetDoubleSided(false);
3448 animating_surface->SetDoubleSided(false);
3449 child_of_animating_surface->SetDoubleSided(false);
3450 animating_child->SetDoubleSided(false);
3452 gfx::Transform backface_matrix;
3453 backface_matrix.Translate(50.0, 50.0);
3454 backface_matrix.RotateAboutYAxis(180.0);
3455 backface_matrix.Translate(-50.0, -50.0);
3457 // Make our render surface.
3458 animating_surface->SetForceRenderSurface(true);
3460 // Animate the transform on the render surface.
3461 AddAnimatedTransformToController(
3462 animating_surface->layer_animation_controller(), 10.0, 30, 0);
3463 // This is just an animating layer, not a surface.
3464 AddAnimatedTransformToController(
3465 animating_child->layer_animation_controller(), 10.0, 30, 0);
3467 SetLayerPropertiesForTesting(parent.get(),
3468 identity_matrix,
3469 gfx::Point3F(),
3470 gfx::PointF(),
3471 gfx::Size(100, 100),
3472 true,
3473 false);
3474 SetLayerPropertiesForTesting(child.get(),
3475 backface_matrix,
3476 gfx::Point3F(),
3477 gfx::PointF(),
3478 gfx::Size(100, 100),
3479 true,
3480 false);
3481 SetLayerPropertiesForTesting(animating_surface.get(),
3482 backface_matrix,
3483 gfx::Point3F(),
3484 gfx::PointF(),
3485 gfx::Size(100, 100),
3486 true,
3487 false);
3488 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
3489 backface_matrix,
3490 gfx::Point3F(),
3491 gfx::PointF(),
3492 gfx::Size(100, 100),
3493 true,
3494 false);
3495 SetLayerPropertiesForTesting(animating_child.get(),
3496 backface_matrix,
3497 gfx::Point3F(),
3498 gfx::PointF(),
3499 gfx::Size(100, 100),
3500 true,
3501 false);
3502 SetLayerPropertiesForTesting(child2.get(),
3503 identity_matrix,
3504 gfx::Point3F(),
3505 gfx::PointF(),
3506 gfx::Size(100, 100),
3507 true,
3508 false);
3510 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(parent.get(),
3511 parent->bounds());
3512 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
3514 EXPECT_FALSE(child->has_render_surface());
3515 EXPECT_TRUE(animating_surface->has_render_surface());
3516 EXPECT_FALSE(child_of_animating_surface->has_render_surface());
3517 EXPECT_FALSE(animating_child->has_render_surface());
3518 EXPECT_FALSE(child2->has_render_surface());
3520 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
3522 EXPECT_EQ(4u, update_layer_list().size());
3524 // The non-animating child be culled from the layer list for the parent render
3525 // surface.
3526 EXPECT_TRUE(UpdateLayerListContains(animating_surface->id()));
3527 EXPECT_TRUE(UpdateLayerListContains(animating_child->id()));
3528 EXPECT_TRUE(UpdateLayerListContains(child2->id()));
3529 EXPECT_TRUE(UpdateLayerListContains(child_of_animating_surface->id()));
3531 EXPECT_FALSE(child2->visible_rect_from_property_trees().IsEmpty());
3533 // The animating layers should have a visible content rect that represents the
3534 // area of the front face that is within the viewport.
3535 EXPECT_EQ(animating_child->visible_rect_from_property_trees(),
3536 gfx::Rect(animating_child->bounds()));
3537 EXPECT_EQ(animating_surface->visible_rect_from_property_trees(),
3538 gfx::Rect(animating_surface->bounds()));
3539 // And layers in the subtree of the animating layer should have valid visible
3540 // content rects also.
3541 EXPECT_EQ(child_of_animating_surface->visible_rect_from_property_trees(),
3542 gfx::Rect(child_of_animating_surface->bounds()));
3545 TEST_F(LayerTreeHostCommonTest,
3546 BackFaceCullingWithPreserves3dForFlatteningSurface) {
3547 // Verify the behavior of back-face culling for a render surface that is
3548 // created when it flattens its subtree, and its parent has preserves-3d.
3550 const gfx::Transform identity_matrix;
3551 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
3552 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3553 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3554 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3555 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3556 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3557 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3558 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3559 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3561 parent->AddChild(front_facing_surface);
3562 parent->AddChild(back_facing_surface);
3563 front_facing_surface->AddChild(child1);
3564 back_facing_surface->AddChild(child2);
3566 host()->SetRootLayer(parent);
3568 // RenderSurfaces are not double-sided
3569 front_facing_surface->SetDoubleSided(false);
3570 back_facing_surface->SetDoubleSided(false);
3572 gfx::Transform backface_matrix;
3573 backface_matrix.Translate(50.0, 50.0);
3574 backface_matrix.RotateAboutYAxis(180.0);
3575 backface_matrix.Translate(-50.0, -50.0);
3577 SetLayerPropertiesForTesting(parent.get(),
3578 identity_matrix,
3579 gfx::Point3F(),
3580 gfx::PointF(),
3581 gfx::Size(100, 100),
3582 false,
3583 true); // parent transform style is preserve3d.
3584 SetLayerPropertiesForTesting(front_facing_surface.get(),
3585 identity_matrix,
3586 gfx::Point3F(),
3587 gfx::PointF(),
3588 gfx::Size(100, 100),
3589 true,
3590 true); // surface transform style is flat.
3591 SetLayerPropertiesForTesting(back_facing_surface.get(),
3592 backface_matrix,
3593 gfx::Point3F(),
3594 gfx::PointF(),
3595 gfx::Size(100, 100),
3596 true,
3597 true); // surface transform style is flat.
3598 SetLayerPropertiesForTesting(child1.get(),
3599 identity_matrix,
3600 gfx::Point3F(),
3601 gfx::PointF(),
3602 gfx::Size(100, 100),
3603 true,
3604 false);
3605 SetLayerPropertiesForTesting(child2.get(),
3606 identity_matrix,
3607 gfx::Point3F(),
3608 gfx::PointF(),
3609 gfx::Size(100, 100),
3610 true,
3611 false);
3613 front_facing_surface->Set3dSortingContextId(1);
3614 back_facing_surface->Set3dSortingContextId(1);
3616 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
3618 // Verify which render surfaces were created and used.
3619 EXPECT_TRUE(front_facing_surface->has_render_surface());
3621 // We expect the render surface to have been created, but remain unused.
3622 EXPECT_TRUE(back_facing_surface->has_render_surface());
3623 EXPECT_FALSE(child1->has_render_surface());
3624 EXPECT_FALSE(child2->has_render_surface());
3626 EXPECT_EQ(2u, update_layer_list().size());
3627 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
3628 EXPECT_TRUE(UpdateLayerListContains(child1->id()));
3631 TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
3632 // Verify draw and screen space transforms of layers not in a surface.
3633 gfx::Transform identity_matrix;
3635 LayerImpl* parent = root_layer();
3636 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
3637 gfx::PointF(), gfx::Size(100, 100), false, true,
3638 true);
3640 LayerImpl* child = AddChildToRoot<LayerImpl>();
3641 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
3642 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
3643 true, false);
3645 LayerImpl* child_empty = AddChildToRoot<LayerImpl>();
3646 SetLayerPropertiesForTesting(child_empty, identity_matrix, gfx::Point3F(),
3647 gfx::PointF(2.f, 2.f), gfx::Size(), false, true,
3648 false);
3650 float device_scale_factor = 2.5f;
3651 gfx::Size viewport_size(100, 100);
3652 ExecuteCalculateDrawProperties(parent, device_scale_factor);
3654 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, parent);
3655 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child);
3656 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child_empty);
3658 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
3660 // Verify parent transforms
3661 gfx::Transform expected_parent_transform;
3662 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
3663 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
3664 parent->screen_space_transform());
3665 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
3666 parent->draw_transform());
3668 // Verify results of transformed parent rects
3669 gfx::RectF parent_bounds(parent->bounds());
3671 gfx::RectF parent_draw_rect =
3672 MathUtil::MapClippedRect(parent->draw_transform(), parent_bounds);
3673 gfx::RectF parent_screen_space_rect =
3674 MathUtil::MapClippedRect(parent->screen_space_transform(), parent_bounds);
3676 gfx::RectF expected_parent_draw_rect(parent->bounds());
3677 expected_parent_draw_rect.Scale(device_scale_factor);
3678 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
3679 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
3681 // Verify child and child_empty transforms. They should match.
3682 gfx::Transform expected_child_transform;
3683 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
3684 expected_child_transform.Translate(child->position().x(),
3685 child->position().y());
3686 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
3687 child->draw_transform());
3688 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
3689 child->screen_space_transform());
3690 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
3691 child_empty->draw_transform());
3692 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
3693 child_empty->screen_space_transform());
3695 // Verify results of transformed child and child_empty rects. They should
3696 // match.
3697 gfx::RectF child_bounds(child->bounds());
3699 gfx::RectF child_draw_rect =
3700 MathUtil::MapClippedRect(child->draw_transform(), child_bounds);
3701 gfx::RectF child_screen_space_rect =
3702 MathUtil::MapClippedRect(child->screen_space_transform(), child_bounds);
3704 gfx::RectF child_empty_draw_rect =
3705 MathUtil::MapClippedRect(child_empty->draw_transform(), child_bounds);
3706 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
3707 child_empty->screen_space_transform(), child_bounds);
3709 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
3710 expected_child_draw_rect.Scale(device_scale_factor);
3711 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
3712 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
3713 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
3714 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
3717 TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
3718 // Verify draw and screen space transforms of layers in a surface.
3719 gfx::Transform identity_matrix;
3720 gfx::Transform perspective_matrix;
3721 perspective_matrix.ApplyPerspectiveDepth(2.0);
3723 gfx::Transform scale_small_matrix;
3724 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
3726 LayerImpl* root = root_layer();
3727 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3728 gfx::PointF(), gfx::Size(100, 100), false, true,
3729 false);
3730 LayerImpl* parent = AddChildToRoot<LayerImpl>();
3731 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
3732 gfx::PointF(), gfx::Size(100, 100), false, true,
3733 false);
3735 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
3736 SetLayerPropertiesForTesting(perspective_surface,
3737 perspective_matrix * scale_small_matrix,
3738 gfx::Point3F(), gfx::PointF(2.f, 2.f),
3739 gfx::Size(10, 10), false, true, true);
3740 perspective_surface->SetDrawsContent(true);
3742 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
3743 SetLayerPropertiesForTesting(scale_surface, scale_small_matrix,
3744 gfx::Point3F(), gfx::PointF(2.f, 2.f),
3745 gfx::Size(10, 10), false, true, true);
3746 scale_surface->SetDrawsContent(true);
3748 float device_scale_factor = 2.5f;
3749 float page_scale_factor = 3.f;
3750 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
3751 root);
3753 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
3754 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor,
3755 perspective_surface);
3756 // Ideal scale is the max 2d scale component of the combined transform up to
3757 // the nearest render target. Here this includes the layer transform as well
3758 // as the device and page scale factors.
3759 gfx::Transform transform = scale_small_matrix;
3760 transform.Scale(device_scale_factor * page_scale_factor,
3761 device_scale_factor * page_scale_factor);
3762 gfx::Vector2dF scales =
3763 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
3764 float max_2d_scale = std::max(scales.x(), scales.y());
3765 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface);
3767 // The ideal scale will draw 1:1 with its render target space along
3768 // the larger-scale axis.
3769 gfx::Vector2dF target_space_transform_scales =
3770 MathUtil::ComputeTransform2dScaleComponents(
3771 scale_surface->draw_properties().target_space_transform, 0.f);
3772 EXPECT_FLOAT_EQ(max_2d_scale,
3773 std::max(target_space_transform_scales.x(),
3774 target_space_transform_scales.y()));
3776 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
3778 gfx::Transform expected_parent_draw_transform;
3779 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
3780 device_scale_factor * page_scale_factor);
3781 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
3782 parent->draw_transform());
3784 // The scale for the perspective surface is not known, so it is rendered 1:1
3785 // with the screen, and then scaled during drawing.
3786 gfx::Transform expected_perspective_surface_draw_transform;
3787 expected_perspective_surface_draw_transform.Translate(
3788 device_scale_factor * page_scale_factor *
3789 perspective_surface->position().x(),
3790 device_scale_factor * page_scale_factor *
3791 perspective_surface->position().y());
3792 expected_perspective_surface_draw_transform.PreconcatTransform(
3793 perspective_matrix);
3794 expected_perspective_surface_draw_transform.PreconcatTransform(
3795 scale_small_matrix);
3796 gfx::Transform expected_perspective_surface_layer_draw_transform;
3797 expected_perspective_surface_layer_draw_transform.Scale(
3798 device_scale_factor * page_scale_factor,
3799 device_scale_factor * page_scale_factor);
3800 EXPECT_TRANSFORMATION_MATRIX_EQ(
3801 expected_perspective_surface_draw_transform,
3802 perspective_surface->render_surface()->draw_transform());
3803 EXPECT_TRANSFORMATION_MATRIX_EQ(
3804 expected_perspective_surface_layer_draw_transform,
3805 perspective_surface->draw_transform());
3808 TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) {
3809 gfx::Transform parent_scale_matrix;
3810 SkMScalar initial_parent_scale = 1.75;
3811 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
3813 gfx::Transform child_scale_matrix;
3814 SkMScalar initial_child_scale = 0.25;
3815 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
3817 LayerImpl* root = root_layer();
3818 root->SetBounds(gfx::Size(100, 100));
3820 LayerImpl* parent = AddChildToRoot<LayerImpl>();
3821 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
3822 gfx::PointF(), gfx::Size(100, 100), false, true,
3823 false);
3825 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
3826 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
3827 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
3828 true, false);
3830 float device_scale_factor = 2.5f;
3831 float page_scale_factor = 0.01f;
3834 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
3835 root);
3837 // The ideal scale is able to go below 1.
3838 float expected_ideal_scale =
3839 device_scale_factor * page_scale_factor * initial_parent_scale;
3840 EXPECT_LT(expected_ideal_scale, 1.f);
3841 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent);
3843 expected_ideal_scale = device_scale_factor * page_scale_factor *
3844 initial_parent_scale * initial_child_scale;
3845 EXPECT_LT(expected_ideal_scale, 1.f);
3846 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale);
3850 TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) {
3851 gfx::Transform parent_scale_matrix;
3852 SkMScalar initial_parent_scale = 1.75;
3853 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
3855 gfx::Transform child_scale_matrix;
3856 SkMScalar initial_child_scale = 1.25;
3857 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
3859 LayerImpl* root = root_layer();
3860 root->SetBounds(gfx::Size(100, 100));
3862 LayerImpl* parent = AddChildToRoot<LayerImpl>();
3863 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
3864 gfx::PointF(), gfx::Size(100, 100), false, true,
3865 false);
3867 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
3868 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
3869 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
3870 true, false);
3873 ExecuteCalculateDrawProperties(root);
3875 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent);
3876 // Animating layers compute ideal scale in the same way as when
3877 // they are static.
3878 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale,
3879 child_scale);
3883 TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
3884 gfx::Transform identity_matrix;
3886 LayerImpl* parent = root_layer();
3887 parent->SetDrawsContent(true);
3888 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
3889 gfx::PointF(), gfx::Size(30, 30), false, true,
3890 true);
3892 LayerImpl* child = AddChildToRoot<LayerImpl>();
3893 child->SetDrawsContent(true);
3894 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
3895 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
3896 true, true);
3898 gfx::Transform replica_transform;
3899 replica_transform.Scale(1.0, -1.0);
3901 scoped_ptr<LayerImpl> replica =
3902 LayerImpl::Create(host_impl()->active_tree(), 7);
3903 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(),
3904 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
3905 true, false);
3906 child->SetReplicaLayer(replica.Pass());
3908 // This layer should end up in the same surface as child, with the same draw
3909 // and screen space transforms.
3910 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child);
3911 duplicate_child_non_owner->SetDrawsContent(true);
3912 SetLayerPropertiesForTesting(duplicate_child_non_owner, identity_matrix,
3913 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
3914 false, true, false);
3916 float device_scale_factor = 1.5f;
3917 ExecuteCalculateDrawProperties(parent, device_scale_factor);
3919 // We should have two render surfaces. The root's render surface and child's
3920 // render surface (it needs one because it has a replica layer).
3921 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
3923 gfx::Transform expected_parent_transform;
3924 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
3925 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
3926 parent->screen_space_transform());
3927 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
3928 parent->draw_transform());
3930 gfx::Transform expected_draw_transform;
3931 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
3932 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
3933 child->draw_transform());
3935 gfx::Transform expected_screen_space_transform;
3936 expected_screen_space_transform.Scale(device_scale_factor,
3937 device_scale_factor);
3938 expected_screen_space_transform.Translate(child->position().x(),
3939 child->position().y());
3940 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
3941 child->screen_space_transform());
3943 gfx::Transform expected_duplicate_child_draw_transform =
3944 child->draw_transform();
3945 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
3946 duplicate_child_non_owner->draw_transform());
3947 EXPECT_TRANSFORMATION_MATRIX_EQ(
3948 child->screen_space_transform(),
3949 duplicate_child_non_owner->screen_space_transform());
3950 EXPECT_EQ(child->drawable_content_rect(),
3951 duplicate_child_non_owner->drawable_content_rect());
3952 EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds());
3954 gfx::Transform expected_render_surface_draw_transform;
3955 expected_render_surface_draw_transform.Translate(
3956 device_scale_factor * child->position().x(),
3957 device_scale_factor * child->position().y());
3958 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
3959 child->render_surface()->draw_transform());
3961 gfx::Transform expected_surface_draw_transform;
3962 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
3963 device_scale_factor * 2.f);
3964 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
3965 child->render_surface()->draw_transform());
3967 gfx::Transform expected_surface_screen_space_transform;
3968 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
3969 device_scale_factor * 2.f);
3970 EXPECT_TRANSFORMATION_MATRIX_EQ(
3971 expected_surface_screen_space_transform,
3972 child->render_surface()->screen_space_transform());
3974 gfx::Transform expected_replica_draw_transform;
3975 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
3976 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
3977 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
3978 EXPECT_TRANSFORMATION_MATRIX_EQ(
3979 expected_replica_draw_transform,
3980 child->render_surface()->replica_draw_transform());
3982 gfx::Transform expected_replica_screen_space_transform;
3983 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
3984 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
3985 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
3986 EXPECT_TRANSFORMATION_MATRIX_EQ(
3987 expected_replica_screen_space_transform,
3988 child->render_surface()->replica_screen_space_transform());
3989 EXPECT_TRANSFORMATION_MATRIX_EQ(
3990 expected_replica_screen_space_transform,
3991 child->render_surface()->replica_screen_space_transform());
3994 TEST_F(LayerTreeHostCommonTest,
3995 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
3996 gfx::Transform identity_matrix;
3998 LayerImpl* parent = root_layer();
3999 parent->SetDrawsContent(true);
4000 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4001 gfx::PointF(), gfx::Size(33, 31), false, true,
4002 true);
4004 LayerImpl* child = AddChildToRoot<LayerImpl>();
4005 child->SetDrawsContent(true);
4006 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4007 gfx::PointF(), gfx::Size(13, 11), false, true,
4008 true);
4010 gfx::Transform replica_transform;
4011 replica_transform.Scale(1.0, -1.0);
4012 scoped_ptr<LayerImpl> replica =
4013 LayerImpl::Create(host_impl()->active_tree(), 7);
4014 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(),
4015 gfx::PointF(), gfx::Size(13, 11), false, true,
4016 false);
4017 child->SetReplicaLayer(replica.Pass());
4019 float device_scale_factor = 1.7f;
4020 ExecuteCalculateDrawProperties(parent, device_scale_factor);
4022 // We should have two render surfaces. The root's render surface and child's
4023 // render surface (it needs one because it has a replica layer).
4024 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
4026 gfx::Transform identity_transform;
4027 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
4028 child->render_surface()->draw_transform());
4029 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
4030 child->render_surface()->draw_transform());
4031 EXPECT_TRANSFORMATION_MATRIX_EQ(
4032 identity_transform, child->render_surface()->screen_space_transform());
4034 gfx::Transform expected_replica_draw_transform;
4035 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
4036 EXPECT_TRANSFORMATION_MATRIX_EQ(
4037 expected_replica_draw_transform,
4038 child->render_surface()->replica_draw_transform());
4040 gfx::Transform expected_replica_screen_space_transform;
4041 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
4042 EXPECT_TRANSFORMATION_MATRIX_EQ(
4043 expected_replica_screen_space_transform,
4044 child->render_surface()->replica_screen_space_transform());
4047 TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
4048 scoped_refptr<Layer> root = Layer::Create(layer_settings());
4049 scoped_refptr<Layer> child = Layer::Create(layer_settings());
4050 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
4051 scoped_refptr<Layer> mask_layer = Layer::Create(layer_settings());
4052 scoped_refptr<Layer> replica_layer = Layer::Create(layer_settings());
4054 grand_child->SetReplicaLayer(replica_layer.get());
4055 child->AddChild(grand_child.get());
4056 child->SetMaskLayer(mask_layer.get());
4057 root->AddChild(child.get());
4059 host()->SetRootLayer(root);
4061 int nonexistent_id = -1;
4062 EXPECT_EQ(root.get(),
4063 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
4064 EXPECT_EQ(child.get(),
4065 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
4066 EXPECT_EQ(
4067 grand_child.get(),
4068 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
4069 EXPECT_EQ(
4070 mask_layer.get(),
4071 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
4072 EXPECT_EQ(
4073 replica_layer.get(),
4074 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
4075 EXPECT_EQ(
4076 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
4079 TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
4080 scoped_refptr<Layer> root = Layer::Create(layer_settings());
4081 scoped_refptr<Layer> child = Layer::Create(layer_settings());
4082 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
4083 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4085 const gfx::Transform identity_matrix;
4086 SetLayerPropertiesForTesting(root.get(),
4087 identity_matrix,
4088 gfx::Point3F(),
4089 gfx::PointF(),
4090 gfx::Size(100, 100),
4091 true,
4092 false);
4093 SetLayerPropertiesForTesting(child.get(),
4094 identity_matrix,
4095 gfx::Point3F(),
4096 gfx::PointF(),
4097 gfx::Size(10, 10),
4098 true,
4099 false);
4100 SetLayerPropertiesForTesting(grand_child.get(),
4101 identity_matrix,
4102 gfx::Point3F(),
4103 gfx::PointF(),
4104 gfx::Size(10, 10),
4105 true,
4106 false);
4108 root->AddChild(child);
4109 child->AddChild(grand_child);
4110 child->SetOpacity(0.5f);
4112 host()->SetRootLayer(root);
4114 ExecuteCalculateDrawProperties(root.get());
4116 EXPECT_FALSE(child->has_render_surface());
4119 TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
4120 FakeImplProxy proxy;
4121 TestSharedBitmapManager shared_bitmap_manager;
4122 TestTaskGraphRunner task_graph_runner;
4123 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
4124 &task_graph_runner);
4125 host_impl.CreatePendingTree();
4126 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
4128 const gfx::Transform identity_matrix;
4129 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
4130 gfx::PointF(), gfx::Size(100, 100), true, false,
4131 false);
4132 root->SetDrawsContent(true);
4134 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
4135 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
4136 gfx::PointF(), gfx::Size(50, 50), true, false,
4137 false);
4138 child->SetDrawsContent(true);
4139 child->SetOpacity(0.0f);
4141 // Add opacity animation.
4142 AddOpacityTransitionToController(
4143 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
4145 root->AddChild(child.Pass());
4146 root->SetHasRenderSurface(true);
4148 LayerImplList render_surface_layer_list;
4149 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4150 root.get(), root->bounds(), &render_surface_layer_list);
4151 inputs.can_adjust_raster_scales = true;
4152 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4154 // We should have one render surface and two layers. The child
4155 // layer should be included even though it is transparent.
4156 ASSERT_EQ(1u, render_surface_layer_list.size());
4157 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4160 using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
4161 class LCDTextTest : public LayerTreeHostCommonTestBase,
4162 public testing::TestWithParam<LCDTextTestParam> {
4163 public:
4164 LCDTextTest()
4165 : LayerTreeHostCommonTestBase(LayerTreeSettings()),
4166 host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_),
4167 root_(nullptr),
4168 child_(nullptr),
4169 grand_child_(nullptr) {}
4171 protected:
4172 void SetUp() override {
4173 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
4174 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
4176 scoped_ptr<LayerImpl> root_ptr =
4177 LayerImpl::Create(host_impl_.active_tree(), 1);
4178 scoped_ptr<LayerImpl> child_ptr =
4179 LayerImpl::Create(host_impl_.active_tree(), 2);
4180 scoped_ptr<LayerImpl> grand_child_ptr =
4181 LayerImpl::Create(host_impl_.active_tree(), 3);
4183 // Stash raw pointers to look at later.
4184 root_ = root_ptr.get();
4185 child_ = child_ptr.get();
4186 grand_child_ = grand_child_ptr.get();
4188 child_->AddChild(grand_child_ptr.Pass());
4189 root_->AddChild(child_ptr.Pass());
4190 host_impl_.active_tree()->SetRootLayer(root_ptr.Pass());
4192 root_->SetContentsOpaque(true);
4193 child_->SetContentsOpaque(true);
4194 grand_child_->SetContentsOpaque(true);
4196 root_->SetDrawsContent(true);
4197 child_->SetDrawsContent(true);
4198 grand_child_->SetDrawsContent(true);
4200 gfx::Transform identity_matrix;
4201 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(),
4202 gfx::PointF(), gfx::Size(1, 1), true, false,
4203 true);
4204 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(),
4205 gfx::PointF(), gfx::Size(1, 1), true, false,
4206 std::tr1::get<2>(GetParam()));
4207 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(),
4208 gfx::PointF(), gfx::Size(1, 1), true, false,
4209 false);
4212 bool can_use_lcd_text_;
4213 bool layers_always_allowed_lcd_text_;
4215 FakeImplProxy proxy_;
4216 TestSharedBitmapManager shared_bitmap_manager_;
4217 TestTaskGraphRunner task_graph_runner_;
4218 FakeLayerTreeHostImpl host_impl_;
4220 LayerImpl* root_;
4221 LayerImpl* child_;
4222 LayerImpl* grand_child_;
4225 TEST_P(LCDTextTest, CanUseLCDText) {
4226 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
4227 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
4229 // Case 1: Identity transform.
4230 gfx::Transform identity_matrix;
4231 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4232 layers_always_allowed_lcd_text_);
4233 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4234 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4235 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4237 // Case 2: Integral translation.
4238 gfx::Transform integral_translation;
4239 integral_translation.Translate(1.0, 2.0);
4240 child_->SetTransform(integral_translation);
4241 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4242 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4243 layers_always_allowed_lcd_text_);
4244 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4245 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4246 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4248 // Case 3: Non-integral translation.
4249 gfx::Transform non_integral_translation;
4250 non_integral_translation.Translate(1.5, 2.5);
4251 child_->SetTransform(non_integral_translation);
4252 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4253 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4254 layers_always_allowed_lcd_text_);
4255 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4256 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4257 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4259 // Case 4: Rotation.
4260 gfx::Transform rotation;
4261 rotation.Rotate(10.0);
4262 child_->SetTransform(rotation);
4263 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4264 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4265 layers_always_allowed_lcd_text_);
4266 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4267 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4268 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4270 // Case 5: Scale.
4271 gfx::Transform scale;
4272 scale.Scale(2.0, 2.0);
4273 child_->SetTransform(scale);
4274 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4275 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4276 layers_always_allowed_lcd_text_);
4277 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4278 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4279 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4281 // Case 6: Skew.
4282 gfx::Transform skew;
4283 skew.Skew(10.0, 0.0);
4284 child_->SetTransform(skew);
4285 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4286 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4287 layers_always_allowed_lcd_text_);
4288 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4289 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4290 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4292 // Case 7: Translucent.
4293 child_->SetTransform(identity_matrix);
4294 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4295 child_->SetOpacity(0.5f);
4296 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4297 layers_always_allowed_lcd_text_);
4298 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4299 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4300 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4302 // Case 8: Sanity check: restore transform and opacity.
4303 child_->SetTransform(identity_matrix);
4304 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4305 child_->SetOpacity(1.f);
4306 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4307 layers_always_allowed_lcd_text_);
4308 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4309 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4310 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4312 // Case 9: Non-opaque content.
4313 child_->SetContentsOpaque(false);
4314 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4315 layers_always_allowed_lcd_text_);
4316 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4317 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4318 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4320 // Case 10: Sanity check: restore content opaqueness.
4321 child_->SetContentsOpaque(true);
4322 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4323 layers_always_allowed_lcd_text_);
4324 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4325 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4326 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4329 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
4330 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
4331 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
4333 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4334 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4335 layers_always_allowed_lcd_text_);
4336 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4337 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4338 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4340 // Add opacity animation.
4341 child_->SetOpacity(0.9f);
4342 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4343 AddOpacityTransitionToController(
4344 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
4346 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4347 layers_always_allowed_lcd_text_);
4348 // Text LCD should be adjusted while animation is active.
4349 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4350 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4351 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4354 TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
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 // Mark contents non-opaque within the first animation frame.
4366 child_->SetContentsOpaque(false);
4367 AddOpacityTransitionToController(child_->layer_animation_controller(), 10.0,
4368 0.9f, 0.1f, false);
4370 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4371 layers_always_allowed_lcd_text_);
4372 // LCD text should be disabled for non-opaque layers even during animations.
4373 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4374 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4375 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4378 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
4379 LCDTextTest,
4380 testing::Combine(testing::Bool(),
4381 testing::Bool(),
4382 testing::Bool()));
4384 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
4385 FakeImplProxy proxy;
4386 TestSharedBitmapManager shared_bitmap_manager;
4387 TestTaskGraphRunner task_graph_runner;
4388 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
4389 &task_graph_runner);
4390 host_impl.CreatePendingTree();
4391 const gfx::Transform identity_matrix;
4393 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
4394 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
4395 gfx::PointF(), gfx::Size(50, 50), true, false,
4396 false);
4397 root->SetDrawsContent(true);
4399 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
4400 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
4401 gfx::PointF(), gfx::Size(40, 40), true, false,
4402 false);
4403 child->SetDrawsContent(true);
4405 scoped_ptr<LayerImpl> grand_child =
4406 LayerImpl::Create(host_impl.pending_tree(), 3);
4407 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
4408 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4409 true, false, false);
4410 grand_child->SetDrawsContent(true);
4411 grand_child->SetHideLayerAndSubtree(true);
4413 child->AddChild(grand_child.Pass());
4414 root->AddChild(child.Pass());
4415 root->SetHasRenderSurface(true);
4417 LayerImplList render_surface_layer_list;
4418 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4419 root.get(), root->bounds(), &render_surface_layer_list);
4420 inputs.can_adjust_raster_scales = true;
4421 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4423 // We should have one render surface and two layers. The grand child has
4424 // hidden itself.
4425 ASSERT_EQ(1u, render_surface_layer_list.size());
4426 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4427 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
4428 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
4431 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
4432 FakeImplProxy proxy;
4433 TestSharedBitmapManager shared_bitmap_manager;
4434 TestTaskGraphRunner task_graph_runner;
4435 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
4436 &task_graph_runner);
4437 host_impl.CreatePendingTree();
4438 const gfx::Transform identity_matrix;
4440 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
4441 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
4442 gfx::PointF(), gfx::Size(50, 50), true, false,
4443 true);
4444 root->SetDrawsContent(true);
4446 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
4447 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
4448 gfx::PointF(), gfx::Size(40, 40), true, false,
4449 false);
4450 child->SetDrawsContent(true);
4451 child->SetHideLayerAndSubtree(true);
4453 scoped_ptr<LayerImpl> grand_child =
4454 LayerImpl::Create(host_impl.pending_tree(), 3);
4455 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
4456 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4457 true, false, false);
4458 grand_child->SetDrawsContent(true);
4460 child->AddChild(grand_child.Pass());
4461 root->AddChild(child.Pass());
4463 LayerImplList render_surface_layer_list;
4464 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4465 root.get(), root->bounds(), &render_surface_layer_list);
4466 inputs.can_adjust_raster_scales = true;
4467 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4469 // We should have one render surface and one layers. The child has
4470 // hidden itself and the grand child.
4471 ASSERT_EQ(1u, render_surface_layer_list.size());
4472 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4473 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
4476 void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
4478 TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
4479 FakeImplProxy proxy;
4480 TestSharedBitmapManager shared_bitmap_manager;
4481 TestTaskGraphRunner task_graph_runner;
4482 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
4483 &task_graph_runner);
4484 host_impl.CreatePendingTree();
4485 const gfx::Transform identity_matrix;
4487 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
4488 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
4489 gfx::PointF(), gfx::Size(50, 50), true, false,
4490 true);
4491 root->SetDrawsContent(true);
4493 scoped_ptr<LayerImpl> copy_grand_parent =
4494 LayerImpl::Create(host_impl.pending_tree(), 2);
4495 SetLayerPropertiesForTesting(copy_grand_parent.get(), identity_matrix,
4496 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
4497 true, false, false);
4498 copy_grand_parent->SetDrawsContent(true);
4499 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get();
4501 scoped_ptr<LayerImpl> copy_parent =
4502 LayerImpl::Create(host_impl.pending_tree(), 3);
4503 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
4504 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4505 true, false, true);
4506 copy_parent->SetDrawsContent(true);
4507 LayerImpl* copy_parent_layer = copy_parent.get();
4509 scoped_ptr<LayerImpl> copy_request =
4510 LayerImpl::Create(host_impl.pending_tree(), 4);
4511 SetLayerPropertiesForTesting(copy_request.get(), identity_matrix,
4512 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4513 true, false, true);
4514 copy_request->SetDrawsContent(true);
4515 LayerImpl* copy_layer = copy_request.get();
4517 scoped_ptr<LayerImpl> copy_child =
4518 LayerImpl::Create(host_impl.pending_tree(), 5);
4519 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix,
4520 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4521 true, false, false);
4522 copy_child->SetDrawsContent(true);
4523 LayerImpl* copy_child_layer = copy_child.get();
4525 scoped_ptr<LayerImpl> copy_grand_parent_sibling_before =
4526 LayerImpl::Create(host_impl.pending_tree(), 6);
4527 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
4528 identity_matrix, gfx::Point3F(), gfx::PointF(),
4529 gfx::Size(40, 40), true, false, false);
4530 copy_grand_parent_sibling_before->SetDrawsContent(true);
4531 LayerImpl* copy_grand_parent_sibling_before_layer =
4532 copy_grand_parent_sibling_before.get();
4534 scoped_ptr<LayerImpl> copy_grand_parent_sibling_after =
4535 LayerImpl::Create(host_impl.pending_tree(), 7);
4536 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
4537 identity_matrix, gfx::Point3F(), gfx::PointF(),
4538 gfx::Size(40, 40), true, false, false);
4539 copy_grand_parent_sibling_after->SetDrawsContent(true);
4540 LayerImpl* copy_grand_parent_sibling_after_layer =
4541 copy_grand_parent_sibling_after.get();
4543 copy_request->AddChild(copy_child.Pass());
4544 copy_parent->AddChild(copy_request.Pass());
4545 copy_grand_parent->AddChild(copy_parent.Pass());
4546 root->AddChild(copy_grand_parent_sibling_before.Pass());
4547 root->AddChild(copy_grand_parent.Pass());
4548 root->AddChild(copy_grand_parent_sibling_after.Pass());
4550 // Hide the copy_grand_parent and its subtree. But make a copy request in that
4551 // hidden subtree on copy_layer.
4552 copy_grand_parent_layer->SetHideLayerAndSubtree(true);
4553 copy_grand_parent_sibling_before_layer->SetHideLayerAndSubtree(true);
4554 copy_grand_parent_sibling_after_layer->SetHideLayerAndSubtree(true);
4556 ScopedPtrVector<CopyOutputRequest> copy_requests;
4557 copy_requests.push_back(
4558 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
4559 copy_layer->PassCopyRequests(&copy_requests);
4560 EXPECT_TRUE(copy_layer->HasCopyRequest());
4562 LayerImplList render_surface_layer_list;
4563 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4564 root.get(), root->bounds(), &render_surface_layer_list);
4565 inputs.can_adjust_raster_scales = true;
4566 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4568 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
4569 EXPECT_TRUE(copy_grand_parent_layer->draw_properties()
4570 .layer_or_descendant_has_copy_request);
4571 EXPECT_TRUE(copy_parent_layer->draw_properties()
4572 .layer_or_descendant_has_copy_request);
4573 EXPECT_TRUE(
4574 copy_layer->draw_properties().layer_or_descendant_has_copy_request);
4575 EXPECT_FALSE(
4576 copy_child_layer->draw_properties().layer_or_descendant_has_copy_request);
4577 EXPECT_FALSE(copy_grand_parent_sibling_before_layer->draw_properties()
4578 .layer_or_descendant_has_copy_request);
4579 EXPECT_FALSE(copy_grand_parent_sibling_after_layer->draw_properties()
4580 .layer_or_descendant_has_copy_request);
4582 // We should have three render surfaces, one for the root, one for the parent
4583 // since it owns a surface, and one for the copy_layer.
4584 ASSERT_EQ(3u, render_surface_layer_list.size());
4585 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
4586 EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(1)->id());
4587 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
4589 // The root render surface should have 2 contributing layers. The
4590 // copy_grand_parent is hidden along with its siblings, but the copy_parent
4591 // will appear since something in its subtree needs to be drawn for a copy
4592 // request.
4593 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4594 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
4595 EXPECT_EQ(copy_parent_layer->id(),
4596 root->render_surface()->layer_list().at(1)->id());
4598 // Nothing actually draws into the copy parent, so only the copy_layer will
4599 // appear in its list, since it needs to be drawn for the copy request.
4600 ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size());
4601 EXPECT_EQ(copy_layer->id(),
4602 copy_parent_layer->render_surface()->layer_list().at(0)->id());
4604 // The copy_layer's render surface should have two contributing layers.
4605 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
4606 EXPECT_EQ(copy_layer->id(),
4607 copy_layer->render_surface()->layer_list().at(0)->id());
4608 EXPECT_EQ(copy_child_layer->id(),
4609 copy_layer->render_surface()->layer_list().at(1)->id());
4612 TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
4613 FakeImplProxy proxy;
4614 TestSharedBitmapManager shared_bitmap_manager;
4615 TestTaskGraphRunner task_graph_runner;
4616 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
4617 &task_graph_runner);
4618 host_impl.CreatePendingTree();
4619 const gfx::Transform identity_matrix;
4621 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
4622 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
4623 gfx::PointF(), gfx::Size(50, 50), true, false,
4624 true);
4625 root->SetDrawsContent(true);
4627 scoped_ptr<LayerImpl> copy_parent =
4628 LayerImpl::Create(host_impl.pending_tree(), 2);
4629 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
4630 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
4631 false, false);
4632 copy_parent->SetDrawsContent(true);
4633 copy_parent->SetMasksToBounds(true);
4635 scoped_ptr<LayerImpl> copy_layer =
4636 LayerImpl::Create(host_impl.pending_tree(), 3);
4637 SetLayerPropertiesForTesting(copy_layer.get(), identity_matrix,
4638 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4639 true, false, true);
4640 copy_layer->SetDrawsContent(true);
4642 scoped_ptr<LayerImpl> copy_child =
4643 LayerImpl::Create(host_impl.pending_tree(), 4);
4644 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix,
4645 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4646 true, false, false);
4647 copy_child->SetDrawsContent(true);
4649 ScopedPtrVector<CopyOutputRequest> copy_requests;
4650 copy_requests.push_back(
4651 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
4652 copy_layer->PassCopyRequests(&copy_requests);
4653 EXPECT_TRUE(copy_layer->HasCopyRequest());
4655 copy_layer->AddChild(copy_child.Pass());
4656 copy_parent->AddChild(copy_layer.Pass());
4657 root->AddChild(copy_parent.Pass());
4659 LayerImplList render_surface_layer_list;
4660 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4661 root.get(), root->bounds(), &render_surface_layer_list);
4662 inputs.can_adjust_raster_scales = true;
4663 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4665 // We should have one render surface, as the others are clipped out.
4666 ASSERT_EQ(1u, render_surface_layer_list.size());
4667 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
4669 // The root render surface should only have 1 contributing layer, since the
4670 // other layers are empty/clipped away.
4671 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4672 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
4675 TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
4676 FakeImplProxy proxy;
4677 TestSharedBitmapManager shared_bitmap_manager;
4678 TestTaskGraphRunner task_graph_runner;
4679 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
4680 &task_graph_runner);
4681 host_impl.CreatePendingTree();
4682 const gfx::Transform identity_matrix;
4684 scoped_refptr<Layer> root = Layer::Create(layer_settings());
4685 SetLayerPropertiesForTesting(root.get(),
4686 identity_matrix,
4687 gfx::Point3F(),
4688 gfx::PointF(),
4689 gfx::Size(50, 50),
4690 true,
4691 false);
4692 root->SetIsDrawable(true);
4694 // The surface is moved slightly outside of the viewport.
4695 scoped_refptr<Layer> surface = Layer::Create(layer_settings());
4696 SetLayerPropertiesForTesting(surface.get(),
4697 identity_matrix,
4698 gfx::Point3F(),
4699 gfx::PointF(-10, -20),
4700 gfx::Size(),
4701 true,
4702 false);
4703 surface->SetForceRenderSurface(true);
4705 scoped_refptr<Layer> surface_child = Layer::Create(layer_settings());
4706 SetLayerPropertiesForTesting(surface_child.get(),
4707 identity_matrix,
4708 gfx::Point3F(),
4709 gfx::PointF(),
4710 gfx::Size(50, 50),
4711 true,
4712 false);
4713 surface_child->SetIsDrawable(true);
4715 surface->AddChild(surface_child);
4716 root->AddChild(surface);
4718 host()->SetRootLayer(root);
4720 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(root.get(),
4721 root->bounds());
4722 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4724 // The visible_layer_rect for the |surface_child| should not be clipped by
4725 // the viewport.
4726 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
4727 surface_child->visible_rect_from_property_trees().ToString());
4730 TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
4731 // Ensure that a transform between the layer and its render surface is not a
4732 // problem. Constructs the following layer tree.
4734 // root (a render surface)
4735 // + render_surface
4736 // + clip_parent (scaled)
4737 // + intervening_clipping_layer
4738 // + clip_child
4740 // The render surface should be resized correctly and the clip child should
4741 // inherit the right clip rect.
4742 LayerImpl* root = root_layer();
4743 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4744 LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface);
4745 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
4746 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
4747 clip_child->SetDrawsContent(true);
4748 clip_child->SetClipParent(clip_parent);
4749 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
4750 clip_children->insert(clip_child);
4751 clip_parent->SetClipChildren(clip_children.release());
4753 intervening->SetMasksToBounds(true);
4754 clip_parent->SetMasksToBounds(true);
4756 gfx::Transform scale_transform;
4757 scale_transform.Scale(2, 2);
4759 gfx::Transform identity_transform;
4761 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
4762 gfx::PointF(), gfx::Size(50, 50), true, false,
4763 true);
4764 SetLayerPropertiesForTesting(render_surface, identity_transform,
4765 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4766 true, false, true);
4767 SetLayerPropertiesForTesting(clip_parent, scale_transform, gfx::Point3F(),
4768 gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true,
4769 false, false);
4770 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
4771 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
4772 false, false);
4773 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
4774 gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true,
4775 false, false);
4777 ExecuteCalculateDrawProperties(root);
4779 ASSERT_TRUE(root->render_surface());
4780 ASSERT_TRUE(render_surface->render_surface());
4782 // Ensure that we've inherited our clip parent's clip and weren't affected
4783 // by the intervening clip layer.
4784 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
4785 clip_parent->clip_rect().ToString());
4786 ASSERT_EQ(clip_parent->clip_rect().ToString(),
4787 clip_child->clip_rect().ToString());
4788 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
4789 intervening->clip_rect().ToString());
4791 // Ensure that the render surface reports a content rect that has been grown
4792 // to accomodate for the clip child.
4793 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
4794 render_surface->render_surface()->content_rect().ToString());
4796 // The above check implies the two below, but they nicely demonstrate that
4797 // we've grown, despite the intervening layer's clip.
4798 ASSERT_TRUE(clip_parent->clip_rect().Contains(
4799 render_surface->render_surface()->content_rect()));
4800 ASSERT_FALSE(intervening->clip_rect().Contains(
4801 render_surface->render_surface()->content_rect()));
4804 TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
4805 // Ensure that intervening render surfaces are not a problem in the basic
4806 // case. In the following tree, both render surfaces should be resized to
4807 // accomodate for the clip child, despite an intervening clip.
4809 // root (a render surface)
4810 // + clip_parent (masks to bounds)
4811 // + render_surface1 (sets opacity)
4812 // + intervening (masks to bounds)
4813 // + render_surface2 (also sets opacity)
4814 // + clip_child
4816 LayerImpl* root = root_layer();
4817 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
4818 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
4819 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
4820 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
4821 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
4822 clip_child->SetDrawsContent(true);
4824 clip_child->SetClipParent(clip_parent);
4826 intervening->SetMasksToBounds(true);
4827 clip_parent->SetMasksToBounds(true);
4829 gfx::Transform translation_transform;
4830 translation_transform.Translate(2, 2);
4832 gfx::Transform identity_transform;
4833 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
4834 gfx::PointF(), gfx::Size(50, 50), true, false,
4835 true);
4836 SetLayerPropertiesForTesting(clip_parent, translation_transform,
4837 gfx::Point3F(), gfx::PointF(1.f, 1.f),
4838 gfx::Size(40, 40), true, false, false);
4839 SetLayerPropertiesForTesting(render_surface1, identity_transform,
4840 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4841 true, false, true);
4842 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
4843 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
4844 false, false);
4845 SetLayerPropertiesForTesting(render_surface2, identity_transform,
4846 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4847 true, false, true);
4848 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
4849 gfx::PointF(-10.f, -10.f), gfx::Size(60, 60),
4850 true, false, false);
4852 ExecuteCalculateDrawProperties(root);
4854 EXPECT_TRUE(root->render_surface());
4855 EXPECT_TRUE(render_surface1->render_surface());
4856 EXPECT_TRUE(render_surface2->render_surface());
4858 // Since the render surfaces could have expanded, they should not clip (their
4859 // bounds would no longer be reliable). We should resort to layer clipping
4860 // in this case.
4861 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4862 render_surface1->render_surface()->clip_rect().ToString());
4863 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
4864 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4865 render_surface2->render_surface()->clip_rect().ToString());
4866 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
4868 // NB: clip rects are in target space.
4869 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4870 render_surface1->clip_rect().ToString());
4871 EXPECT_TRUE(render_surface1->is_clipped());
4873 // This value is inherited from the clipping ancestor layer, 'intervening'.
4874 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
4875 render_surface2->clip_rect().ToString());
4876 EXPECT_TRUE(render_surface2->is_clipped());
4878 // The content rects of both render surfaces should both have expanded to
4879 // contain the clip child.
4880 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4881 render_surface1->render_surface()->content_rect().ToString());
4882 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
4883 render_surface2->render_surface()->content_rect().ToString());
4885 // The clip child should have inherited the clip parent's clip (projected to
4886 // the right space, of course), and should have the correctly sized visible
4887 // content rect.
4888 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
4889 clip_child->clip_rect().ToString());
4890 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
4891 clip_child->visible_layer_rect().ToString());
4892 EXPECT_TRUE(clip_child->is_clipped());
4895 TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
4896 // Ensure that intervening render surfaces are not a problem, even if there
4897 // is a scroll involved. Note, we do _not_ have to consider any other sort
4898 // of transform.
4900 // root (a render surface)
4901 // + clip_parent (masks to bounds)
4902 // + render_surface1 (sets opacity)
4903 // + intervening (masks to bounds AND scrolls)
4904 // + render_surface2 (also sets opacity)
4905 // + clip_child
4907 LayerImpl* root = root_layer();
4908 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
4909 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
4910 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
4911 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
4912 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
4913 clip_child->SetDrawsContent(true);
4915 clip_child->SetClipParent(clip_parent);
4917 intervening->SetMasksToBounds(true);
4918 clip_parent->SetMasksToBounds(true);
4919 intervening->SetScrollClipLayer(clip_parent->id());
4920 intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
4922 gfx::Transform translation_transform;
4923 translation_transform.Translate(2, 2);
4925 gfx::Transform identity_transform;
4926 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
4927 gfx::PointF(), gfx::Size(50, 50), true, false,
4928 true);
4929 SetLayerPropertiesForTesting(clip_parent, translation_transform,
4930 gfx::Point3F(), gfx::PointF(1.f, 1.f),
4931 gfx::Size(40, 40), true, false, false);
4932 SetLayerPropertiesForTesting(render_surface1, identity_transform,
4933 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4934 true, false, true);
4935 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
4936 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
4937 false, false);
4938 SetLayerPropertiesForTesting(render_surface2, identity_transform,
4939 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4940 true, false, true);
4941 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
4942 gfx::PointF(-10.f, -10.f), gfx::Size(60, 60),
4943 true, false, false);
4945 ExecuteCalculateDrawProperties(root);
4947 EXPECT_TRUE(root->render_surface());
4948 EXPECT_TRUE(render_surface1->render_surface());
4949 EXPECT_TRUE(render_surface2->render_surface());
4951 // Since the render surfaces could have expanded, they should not clip (their
4952 // bounds would no longer be reliable). We should resort to layer clipping
4953 // in this case.
4954 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4955 render_surface1->render_surface()->clip_rect().ToString());
4956 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
4957 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4958 render_surface2->render_surface()->clip_rect().ToString());
4959 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
4961 // NB: clip rects are in target space.
4962 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4963 render_surface1->clip_rect().ToString());
4964 EXPECT_TRUE(render_surface1->is_clipped());
4966 // This value is inherited from the clipping ancestor layer, 'intervening'.
4967 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
4968 render_surface2->clip_rect().ToString());
4969 EXPECT_TRUE(render_surface2->is_clipped());
4971 // The content rects of both render surfaces should both have expanded to
4972 // contain the clip child.
4973 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4974 render_surface1->render_surface()->content_rect().ToString());
4975 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
4976 render_surface2->render_surface()->content_rect().ToString());
4978 // The clip child should have inherited the clip parent's clip (projected to
4979 // the right space, of course), and should have the correctly sized visible
4980 // content rect.
4981 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
4982 clip_child->clip_rect().ToString());
4983 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
4984 clip_child->visible_layer_rect().ToString());
4985 EXPECT_TRUE(clip_child->is_clipped());
4988 TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
4989 // Ensures that descendants of the clip child inherit the correct clip.
4991 // root (a render surface)
4992 // + clip_parent (masks to bounds)
4993 // + intervening (masks to bounds)
4994 // + clip_child
4995 // + child
4997 LayerImpl* root = root_layer();
4998 LayerImpl* clip_parent = AddChild<LayerImpl>(root);
4999 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
5000 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5001 LayerImpl* child = AddChild<LayerImpl>(clip_child);
5002 child->SetDrawsContent(true);
5004 clip_child->SetClipParent(clip_parent);
5005 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
5006 clip_children->insert(clip_child);
5007 clip_parent->SetClipChildren(clip_children.release());
5009 intervening->SetMasksToBounds(true);
5010 clip_parent->SetMasksToBounds(true);
5012 gfx::Transform identity_transform;
5013 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5014 gfx::PointF(), gfx::Size(50, 50), true, false,
5015 true);
5016 SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(),
5017 gfx::PointF(), gfx::Size(40, 40), true, false,
5018 false);
5019 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5020 gfx::PointF(), gfx::Size(5, 5), true, false,
5021 false);
5022 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5023 gfx::PointF(), gfx::Size(60, 60), true, false,
5024 false);
5025 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
5026 gfx::PointF(), gfx::Size(60, 60), true, false,
5027 false);
5029 ExecuteCalculateDrawProperties(root);
5031 EXPECT_TRUE(root->render_surface());
5033 // Neither the clip child nor its descendant should have inherited the clip
5034 // from |intervening|.
5035 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5036 clip_child->clip_rect().ToString());
5037 EXPECT_TRUE(clip_child->is_clipped());
5038 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5039 child->visible_layer_rect().ToString());
5040 EXPECT_TRUE(child->is_clipped());
5043 TEST_F(LayerTreeHostCommonTest,
5044 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
5045 // Ensures that non-descendant clip children in the tree do not affect
5046 // render surfaces.
5048 // root (a render surface)
5049 // + clip_parent (masks to bounds)
5050 // + render_surface1
5051 // + clip_child
5052 // + render_surface2
5053 // + non_clip_child
5055 // In this example render_surface2 should be unaffected by clip_child.
5056 LayerImpl* root = root_layer();
5057 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5058 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5059 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
5060 clip_child->SetDrawsContent(true);
5061 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent);
5062 LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2);
5063 non_clip_child->SetDrawsContent(true);
5065 clip_child->SetClipParent(clip_parent);
5066 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
5067 clip_children->insert(clip_child);
5068 clip_parent->SetClipChildren(clip_children.release());
5070 clip_parent->SetMasksToBounds(true);
5071 render_surface1->SetMasksToBounds(true);
5073 gfx::Transform identity_transform;
5074 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5075 gfx::PointF(), gfx::Size(15, 15), true, false,
5076 true);
5077 SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(),
5078 gfx::PointF(), gfx::Size(10, 10), true, false,
5079 false);
5080 SetLayerPropertiesForTesting(render_surface1, identity_transform,
5081 gfx::Point3F(), gfx::PointF(5, 5),
5082 gfx::Size(5, 5), true, false, true);
5083 SetLayerPropertiesForTesting(render_surface2, identity_transform,
5084 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
5085 true, false, true);
5086 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5087 gfx::PointF(-1, 1), gfx::Size(10, 10), true,
5088 false, false);
5089 SetLayerPropertiesForTesting(non_clip_child, identity_transform,
5090 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
5091 true, false, false);
5093 ExecuteCalculateDrawProperties(root);
5095 EXPECT_TRUE(root->render_surface());
5096 EXPECT_TRUE(render_surface1->render_surface());
5097 EXPECT_TRUE(render_surface2->render_surface());
5099 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5100 render_surface1->clip_rect().ToString());
5101 EXPECT_TRUE(render_surface1->is_clipped());
5103 // The render surface should not clip (it has unclipped descendants), instead
5104 // it should rely on layer clipping.
5105 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5106 render_surface1->render_surface()->clip_rect().ToString());
5107 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
5109 // That said, it should have grown to accomodate the unclipped descendant.
5110 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
5111 render_surface1->render_surface()->content_rect().ToString());
5113 // This render surface should clip. It has no unclipped descendants.
5114 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5115 render_surface2->clip_rect().ToString());
5116 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
5118 // It also shouldn't have grown to accomodate the clip child.
5119 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5120 render_surface2->render_surface()->content_rect().ToString());
5122 // Sanity check our num_unclipped_descendants values.
5123 EXPECT_EQ(1u, render_surface1->num_unclipped_descendants());
5124 EXPECT_EQ(0u, render_surface2->num_unclipped_descendants());
5127 TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
5128 FakeImplProxy proxy;
5129 TestSharedBitmapManager shared_bitmap_manager;
5130 TestTaskGraphRunner task_graph_runner;
5131 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
5132 &task_graph_runner);
5133 scoped_ptr<LayerImpl> root =
5134 LayerImpl::Create(host_impl.active_tree(), 12345);
5135 scoped_ptr<LayerImpl> child1 =
5136 LayerImpl::Create(host_impl.active_tree(), 123456);
5137 scoped_ptr<LayerImpl> child2 =
5138 LayerImpl::Create(host_impl.active_tree(), 1234567);
5139 scoped_ptr<LayerImpl> child3 =
5140 LayerImpl::Create(host_impl.active_tree(), 12345678);
5142 gfx::Transform identity_matrix;
5143 gfx::Point3F transform_origin;
5144 gfx::PointF position;
5145 gfx::Size bounds(100, 100);
5146 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
5147 position, bounds, true, false, true);
5148 root->SetDrawsContent(true);
5150 // This layer structure normally forces render surface due to preserves3d
5151 // behavior.
5152 SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin,
5153 position, bounds, false, true, true);
5154 child1->SetDrawsContent(true);
5155 SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin,
5156 position, bounds, true, false, false);
5157 child2->SetDrawsContent(true);
5158 SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin,
5159 position, bounds, true, false, false);
5160 child3->SetDrawsContent(true);
5162 child2->Set3dSortingContextId(1);
5163 child3->Set3dSortingContextId(1);
5165 child2->AddChild(child3.Pass());
5166 child1->AddChild(child2.Pass());
5167 root->AddChild(child1.Pass());
5170 LayerImplList render_surface_layer_list;
5171 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get());
5172 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5173 root.get(), root->bounds(), &render_surface_layer_list);
5174 inputs.can_render_to_separate_surface = true;
5175 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5177 EXPECT_EQ(2u, render_surface_layer_list.size());
5179 int count_represents_target_render_surface = 0;
5180 int count_represents_contributing_render_surface = 0;
5181 int count_represents_itself = 0;
5182 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
5183 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
5184 it != end; ++it) {
5185 if (it.represents_target_render_surface())
5186 count_represents_target_render_surface++;
5187 if (it.represents_contributing_render_surface())
5188 count_represents_contributing_render_surface++;
5189 if (it.represents_itself())
5190 count_represents_itself++;
5193 // Two render surfaces.
5194 EXPECT_EQ(2, count_represents_target_render_surface);
5195 // Second render surface contributes to root render surface.
5196 EXPECT_EQ(1, count_represents_contributing_render_surface);
5197 // All 4 layers represent itself.
5198 EXPECT_EQ(4, count_represents_itself);
5202 LayerImplList render_surface_layer_list;
5203 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5204 root.get(), root->bounds(), &render_surface_layer_list);
5205 inputs.can_render_to_separate_surface = false;
5206 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5208 EXPECT_EQ(1u, render_surface_layer_list.size());
5210 int count_represents_target_render_surface = 0;
5211 int count_represents_contributing_render_surface = 0;
5212 int count_represents_itself = 0;
5213 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
5214 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
5215 it != end; ++it) {
5216 if (it.represents_target_render_surface())
5217 count_represents_target_render_surface++;
5218 if (it.represents_contributing_render_surface())
5219 count_represents_contributing_render_surface++;
5220 if (it.represents_itself())
5221 count_represents_itself++;
5224 // Only root layer has a render surface.
5225 EXPECT_EQ(1, count_represents_target_render_surface);
5226 // No layer contributes a render surface to root render surface.
5227 EXPECT_EQ(0, count_represents_contributing_render_surface);
5228 // All 4 layers represent itself.
5229 EXPECT_EQ(4, count_represents_itself);
5233 TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
5234 LayerImpl* root = root_layer();
5235 LayerImpl* render_surface = AddChild<LayerImpl>(root);
5236 LayerImpl* child = AddChild<LayerImpl>(render_surface);
5237 child->SetDrawsContent(true);
5239 gfx::Transform identity_transform;
5240 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5241 gfx::PointF(), gfx::Size(50, 50), true, false,
5242 true);
5243 SetLayerPropertiesForTesting(render_surface, identity_transform,
5244 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5245 false, true, true);
5246 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
5247 gfx::PointF(), gfx::Size(20, 20), true, false,
5248 false);
5250 root->SetShouldFlattenTransform(false);
5251 root->Set3dSortingContextId(1);
5252 render_surface->SetDoubleSided(false);
5254 ExecuteCalculateDrawProperties(root);
5256 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
5257 EXPECT_EQ(1u, render_surface_layer_list_impl()
5258 ->at(0)
5259 ->render_surface()
5260 ->layer_list()
5261 .size());
5262 EXPECT_EQ(1u, render_surface_layer_list_impl()
5263 ->at(1)
5264 ->render_surface()
5265 ->layer_list()
5266 .size());
5268 gfx::Transform rotation_transform = identity_transform;
5269 rotation_transform.RotateAboutXAxis(180.0);
5271 render_surface->SetTransform(rotation_transform);
5273 ExecuteCalculateDrawProperties(root);
5275 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
5276 EXPECT_EQ(0u, render_surface_layer_list_impl()
5277 ->at(0)
5278 ->render_surface()
5279 ->layer_list()
5280 .size());
5283 TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
5284 // Checks that the simple case (being clipped by a scroll parent that would
5285 // have been processed before you anyhow) results in the right clips.
5287 // + root
5288 // + scroll_parent_border
5289 // | + scroll_parent_clip
5290 // | + scroll_parent
5291 // + scroll_child
5293 LayerImpl* root = root_layer();
5294 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
5295 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5296 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5297 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
5299 scroll_parent->SetDrawsContent(true);
5300 scroll_child->SetDrawsContent(true);
5301 scroll_parent_clip->SetMasksToBounds(true);
5303 scroll_child->SetScrollParent(scroll_parent);
5304 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
5305 scroll_children->insert(scroll_child);
5306 scroll_parent->SetScrollChildren(scroll_children.release());
5308 gfx::Transform identity_transform;
5309 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5310 gfx::PointF(), gfx::Size(50, 50), true, false,
5311 true);
5312 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
5313 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5314 true, false, false);
5315 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
5316 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5317 true, false, false);
5318 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
5319 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5320 true, false, false);
5321 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
5322 gfx::PointF(), gfx::Size(50, 50), true, false,
5323 false);
5325 ExecuteCalculateDrawProperties(root);
5327 EXPECT_TRUE(root->render_surface());
5329 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
5330 scroll_child->clip_rect().ToString());
5331 EXPECT_TRUE(scroll_child->is_clipped());
5334 TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
5335 LayerImpl* root = root_layer();
5336 root->SetDrawsContent(true);
5337 LayerImpl* parent = AddChildToRoot<LayerImpl>();
5338 parent->SetDrawsContent(true);
5339 LayerImpl* child = AddChild<LayerImpl>(parent);
5340 child->SetDrawsContent(true);
5342 gfx::Transform identity_transform;
5343 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5344 gfx::PointF(), gfx::Size(50, 50), true, true,
5345 true);
5346 SetLayerPropertiesForTesting(parent, identity_transform, gfx::Point3F(),
5347 gfx::PointF(), gfx::Size(30, 30), true, true,
5348 true);
5349 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
5350 gfx::PointF(), gfx::Size(20, 20), true, true,
5351 true);
5353 ExecuteCalculateDrawProperties(root);
5355 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
5357 gfx::Transform singular_transform;
5358 singular_transform.Scale3d(
5359 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
5361 child->SetTransform(singular_transform);
5363 ExecuteCalculateDrawProperties(root);
5365 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
5367 // Ensure that the entire subtree under a layer with singular transform does
5368 // not get rendered.
5369 parent->SetTransform(singular_transform);
5370 child->SetTransform(identity_transform);
5372 ExecuteCalculateDrawProperties(root);
5374 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
5377 TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
5378 // Checks that clipping by a scroll parent that follows you in paint order
5379 // still results in correct clipping.
5381 // + root
5382 // + scroll_parent_border
5383 // + scroll_parent_clip
5384 // + scroll_parent
5385 // + scroll_child
5387 LayerImpl* root = root_layer();
5388 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
5389 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5390 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5391 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
5393 scroll_parent->SetDrawsContent(true);
5394 scroll_child->SetDrawsContent(true);
5396 scroll_parent_clip->SetMasksToBounds(true);
5398 scroll_child->SetScrollParent(scroll_parent);
5399 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
5400 scroll_children->insert(scroll_child);
5401 scroll_parent->SetScrollChildren(scroll_children.release());
5403 gfx::Transform identity_transform;
5404 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5405 gfx::PointF(), gfx::Size(50, 50), true, false,
5406 true);
5407 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
5408 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5409 true, false, false);
5410 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
5411 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5412 true, false, false);
5413 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
5414 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5415 true, false, false);
5416 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
5417 gfx::PointF(), gfx::Size(50, 50), true, false,
5418 false);
5420 ExecuteCalculateDrawProperties(root);
5422 EXPECT_TRUE(root->render_surface());
5424 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
5425 scroll_child->clip_rect().ToString());
5426 EXPECT_TRUE(scroll_child->is_clipped());
5429 TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
5430 // Checks that clipping by a scroll parent and scroll grandparent that follow
5431 // you in paint order still results in correct clipping.
5433 // + root
5434 // + scroll_child
5435 // + scroll_parent_border
5436 // | + scroll_parent_clip
5437 // | + scroll_parent
5438 // + scroll_grandparent_border
5439 // + scroll_grandparent_clip
5440 // + scroll_grandparent
5442 LayerImpl* root = root_layer();
5443 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
5444 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
5445 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5446 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5447 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
5448 LayerImpl* scroll_grandparent_clip =
5449 AddChild<LayerImpl>(scroll_grandparent_border);
5450 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
5452 scroll_parent->SetDrawsContent(true);
5453 scroll_grandparent->SetDrawsContent(true);
5454 scroll_child->SetDrawsContent(true);
5456 scroll_parent_clip->SetMasksToBounds(true);
5457 scroll_grandparent_clip->SetMasksToBounds(true);
5459 scroll_child->SetScrollParent(scroll_parent);
5460 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
5461 scroll_children->insert(scroll_child);
5462 scroll_parent->SetScrollChildren(scroll_children.release());
5464 scroll_parent_border->SetScrollParent(scroll_grandparent);
5465 scroll_children.reset(new std::set<LayerImpl*>);
5466 scroll_children->insert(scroll_parent_border);
5467 scroll_grandparent->SetScrollChildren(scroll_children.release());
5469 gfx::Transform identity_transform;
5470 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5471 gfx::PointF(), gfx::Size(50, 50), true, false,
5472 true);
5473 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
5474 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5475 true, false, false);
5476 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
5477 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5478 true, false, false);
5479 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
5480 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5481 true, false, false);
5482 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
5483 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5484 true, false, false);
5485 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
5486 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5487 true, false, false);
5488 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
5489 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5490 true, false, false);
5491 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
5492 gfx::PointF(), gfx::Size(50, 50), true, false,
5493 false);
5495 ExecuteCalculateDrawProperties(root);
5497 EXPECT_TRUE(root->render_surface());
5499 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
5500 scroll_child->clip_rect().ToString());
5501 EXPECT_TRUE(scroll_child->is_clipped());
5503 // Despite the fact that we visited the above layers out of order to get the
5504 // correct clip, the layer lists should be unaffected.
5505 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
5506 EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0));
5507 EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1));
5508 EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2));
5511 TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
5512 // Ensures that even if we visit layers out of order, we still produce a
5513 // correctly ordered render surface layer list.
5514 // + root
5515 // + scroll_child
5516 // + scroll_parent_border
5517 // + scroll_parent_clip
5518 // + scroll_parent
5519 // + render_surface2
5520 // + scroll_grandparent_border
5521 // + scroll_grandparent_clip
5522 // + scroll_grandparent
5523 // + render_surface1
5525 LayerImpl* root = root_layer();
5526 root->SetDrawsContent(true);
5528 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
5529 scroll_child->SetDrawsContent(true);
5531 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
5532 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5533 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5534 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
5535 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
5536 LayerImpl* scroll_grandparent_clip =
5537 AddChild<LayerImpl>(scroll_grandparent_border);
5538 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
5539 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
5541 scroll_parent->SetDrawsContent(true);
5542 render_surface1->SetDrawsContent(true);
5543 scroll_grandparent->SetDrawsContent(true);
5544 render_surface2->SetDrawsContent(true);
5546 scroll_parent_clip->SetMasksToBounds(true);
5547 scroll_grandparent_clip->SetMasksToBounds(true);
5549 scroll_child->SetScrollParent(scroll_parent);
5550 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
5551 scroll_children->insert(scroll_child);
5552 scroll_parent->SetScrollChildren(scroll_children.release());
5554 scroll_parent_border->SetScrollParent(scroll_grandparent);
5555 scroll_children.reset(new std::set<LayerImpl*>);
5556 scroll_children->insert(scroll_parent_border);
5557 scroll_grandparent->SetScrollChildren(scroll_children.release());
5559 gfx::Transform identity_transform;
5560 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5561 gfx::PointF(), gfx::Size(50, 50), true, false,
5562 true);
5563 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
5564 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5565 true, false, false);
5566 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
5567 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5568 true, false, false);
5569 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
5570 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5571 true, false, false);
5572 SetLayerPropertiesForTesting(render_surface1, identity_transform,
5573 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5574 true, false, true);
5575 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
5576 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5577 true, false, false);
5578 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
5579 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5580 true, false, false);
5581 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
5582 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5583 true, false, false);
5584 SetLayerPropertiesForTesting(render_surface2, identity_transform,
5585 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5586 true, false, true);
5587 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
5588 gfx::PointF(), gfx::Size(50, 50), true, false,
5589 false);
5591 ExecuteCalculateDrawProperties(root);
5593 EXPECT_TRUE(root->render_surface());
5595 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
5596 scroll_child->clip_rect().ToString());
5597 EXPECT_TRUE(scroll_child->is_clipped());
5599 // Despite the fact that we had to process the layers out of order to get the
5600 // right clip, our render_surface_layer_list's order should be unaffected.
5601 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
5602 EXPECT_EQ(root, render_surface_layer_list_impl()->at(0));
5603 EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1));
5604 EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2));
5605 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
5606 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
5607 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
5610 TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
5611 // Ensures that when we have a render surface between a fixed position layer
5612 // and its container, we compute the fixed position layer's draw transform
5613 // with respect to that intervening render surface, not with respect to its
5614 // container's render target.
5616 // + root
5617 // + render_surface
5618 // + fixed
5619 // + child
5621 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5622 scoped_refptr<LayerWithForcedDrawsContent> render_surface =
5623 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5624 scoped_refptr<LayerWithForcedDrawsContent> fixed =
5625 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5626 scoped_refptr<LayerWithForcedDrawsContent> child =
5627 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5629 root->AddChild(render_surface);
5630 render_surface->AddChild(fixed);
5631 fixed->AddChild(child);
5633 root->SetIsContainerForFixedPositionLayers(true);
5634 render_surface->SetForceRenderSurface(true);
5636 LayerPositionConstraint constraint;
5637 constraint.set_is_fixed_position(true);
5638 fixed->SetPositionConstraint(constraint);
5640 SetLayerPropertiesForTesting(root.get(), gfx::Transform(), gfx::Point3F(),
5641 gfx::PointF(), gfx::Size(50, 50), true, false);
5642 SetLayerPropertiesForTesting(render_surface.get(), gfx::Transform(),
5643 gfx::Point3F(), gfx::PointF(7.f, 9.f),
5644 gfx::Size(50, 50), true, false);
5645 SetLayerPropertiesForTesting(fixed.get(), gfx::Transform(), gfx::Point3F(),
5646 gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true,
5647 false);
5648 SetLayerPropertiesForTesting(child.get(), gfx::Transform(), gfx::Point3F(),
5649 gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true,
5650 false);
5652 host()->SetRootLayer(root);
5654 ExecuteCalculateDrawProperties(root.get());
5656 TransformTree& tree = host()->property_trees()->transform_tree;
5658 gfx::Transform expected_fixed_draw_transform;
5659 expected_fixed_draw_transform.Translate(10.f, 15.f);
5660 EXPECT_EQ(expected_fixed_draw_transform,
5661 DrawTransformFromPropertyTrees(fixed.get(), tree));
5663 gfx::Transform expected_fixed_screen_space_transform;
5664 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
5665 EXPECT_EQ(expected_fixed_screen_space_transform,
5666 ScreenSpaceTransformFromPropertyTrees(fixed.get(), tree));
5668 gfx::Transform expected_child_draw_transform;
5669 expected_child_draw_transform.Translate(11.f, 17.f);
5670 EXPECT_EQ(expected_child_draw_transform,
5671 DrawTransformFromPropertyTrees(child.get(), tree));
5673 gfx::Transform expected_child_screen_space_transform;
5674 expected_child_screen_space_transform.Translate(18.f, 26.f);
5675 EXPECT_EQ(expected_child_screen_space_transform,
5676 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
5679 TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
5680 // This test verifies that a scrolling layer that gets snapped to
5681 // integer coordinates doesn't move a fixed position child.
5683 // + root
5684 // + container
5685 // + scroller
5686 // + fixed
5688 FakeImplProxy proxy;
5689 TestSharedBitmapManager shared_bitmap_manager;
5690 TestTaskGraphRunner task_graph_runner;
5691 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
5692 &task_graph_runner);
5693 host_impl.CreatePendingTree();
5694 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5695 scoped_ptr<LayerImpl> container =
5696 LayerImpl::Create(host_impl.active_tree(), 2);
5697 LayerImpl* container_layer = container.get();
5698 scoped_ptr<LayerImpl> scroller =
5699 LayerImpl::Create(host_impl.active_tree(), 3);
5700 LayerImpl* scroll_layer = scroller.get();
5701 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
5702 LayerImpl* fixed_layer = fixed.get();
5704 container->SetIsContainerForFixedPositionLayers(true);
5706 LayerPositionConstraint constraint;
5707 constraint.set_is_fixed_position(true);
5708 fixed->SetPositionConstraint(constraint);
5710 scroller->SetScrollClipLayer(container->id());
5712 gfx::Transform identity_transform;
5713 gfx::Transform container_transform;
5714 container_transform.Translate3d(10.0, 20.0, 0.0);
5715 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
5717 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
5718 gfx::PointF(), gfx::Size(50, 50), true, false,
5719 true);
5720 SetLayerPropertiesForTesting(container.get(), container_transform,
5721 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5722 true, false, false);
5723 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
5724 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5725 true, false, false);
5726 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
5727 gfx::PointF(), gfx::Size(50, 50), true, false,
5728 false);
5730 scroller->AddChild(fixed.Pass());
5731 container->AddChild(scroller.Pass());
5732 root->AddChild(container.Pass());
5734 // Rounded to integers already.
5736 gfx::Vector2dF scroll_delta(3.0, 5.0);
5737 scroll_layer->SetScrollDelta(scroll_delta);
5739 LayerImplList render_surface_layer_list;
5740 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5741 root.get(), root->bounds(), &render_surface_layer_list);
5742 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5744 EXPECT_TRANSFORMATION_MATRIX_EQ(
5745 container_layer->draw_properties().screen_space_transform,
5746 fixed_layer->draw_properties().screen_space_transform);
5747 EXPECT_VECTOR_EQ(
5748 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
5749 container_offset);
5750 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
5751 .screen_space_transform.To2dTranslation(),
5752 container_offset - scroll_delta);
5755 // Scroll delta requiring rounding.
5757 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
5758 scroll_layer->SetScrollDelta(scroll_delta);
5760 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
5762 LayerImplList render_surface_layer_list;
5763 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5764 root.get(), root->bounds(), &render_surface_layer_list);
5765 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5767 EXPECT_TRANSFORMATION_MATRIX_EQ(
5768 container_layer->draw_properties().screen_space_transform,
5769 fixed_layer->draw_properties().screen_space_transform);
5770 EXPECT_VECTOR_EQ(
5771 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
5772 container_offset);
5773 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
5774 .screen_space_transform.To2dTranslation(),
5775 container_offset - rounded_scroll_delta);
5778 // Scale is applied earlier in the tree.
5780 gfx::Transform scaled_container_transform = container_transform;
5781 scaled_container_transform.Scale3d(3.0, 3.0, 1.0);
5782 container_layer->SetTransform(scaled_container_transform);
5784 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
5785 scroll_layer->SetScrollDelta(scroll_delta);
5787 LayerImplList render_surface_layer_list;
5788 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5789 root.get(), root->bounds(), &render_surface_layer_list);
5790 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5792 EXPECT_TRANSFORMATION_MATRIX_EQ(
5793 container_layer->draw_properties().screen_space_transform,
5794 fixed_layer->draw_properties().screen_space_transform);
5795 EXPECT_VECTOR_EQ(
5796 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
5797 container_offset);
5799 container_layer->SetTransform(container_transform);
5802 // Scale is applied on the scroll layer itself.
5804 gfx::Transform scale_transform;
5805 scale_transform.Scale3d(3.0, 3.0, 1.0);
5806 scroll_layer->SetTransform(scale_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_VECTOR_EQ(
5817 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
5818 container_offset);
5820 scroll_layer->SetTransform(identity_transform);
5824 TEST_F(LayerTreeHostCommonTest,
5825 ScrollCompensationMainScrollOffsetFractionalPart) {
5826 // This test verifies that a scrolling layer that has fractional scroll offset
5827 // from main doesn't move a fixed position child.
5829 // + root
5830 // + container
5831 // + scroller
5832 // + fixed
5834 FakeImplProxy proxy;
5835 TestSharedBitmapManager shared_bitmap_manager;
5836 TestTaskGraphRunner task_graph_runner;
5837 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
5838 &task_graph_runner);
5839 host_impl.CreatePendingTree();
5840 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5841 scoped_ptr<LayerImpl> container =
5842 LayerImpl::Create(host_impl.active_tree(), 2);
5843 LayerImpl* container_layer = container.get();
5844 scoped_ptr<LayerImpl> scroller =
5845 LayerImpl::Create(host_impl.active_tree(), 3);
5846 LayerImpl* scroll_layer = scroller.get();
5847 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
5848 LayerImpl* fixed_layer = fixed.get();
5850 container->SetIsContainerForFixedPositionLayers(true);
5852 LayerPositionConstraint constraint;
5853 constraint.set_is_fixed_position(true);
5854 fixed->SetPositionConstraint(constraint);
5856 scroller->SetScrollClipLayer(container->id());
5858 gfx::Transform identity_transform;
5859 gfx::Transform container_transform;
5860 container_transform.Translate3d(10.0, 20.0, 0.0);
5861 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
5863 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
5864 gfx::PointF(), gfx::Size(50, 50), true, false,
5865 true);
5866 SetLayerPropertiesForTesting(container.get(), container_transform,
5867 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5868 true, false, false);
5869 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
5870 gfx::Point3F(), gfx::PointF(0.0, 0.0),
5871 gfx::Size(30, 30), true, false, false);
5873 gfx::ScrollOffset scroll_offset(3.3, 4.2);
5874 gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f);
5875 gfx::Vector2dF scroll_delta(0.1f, 0.4f);
5876 // Blink only uses the integer part of the scroll_offset for fixed
5877 // position layer.
5878 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
5879 gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true,
5880 false, false);
5881 scroll_layer->PushScrollOffsetFromMainThread(scroll_offset);
5882 scroll_layer->SetScrollDelta(scroll_delta);
5883 scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part);
5885 scroller->AddChild(fixed.Pass());
5886 container->AddChild(scroller.Pass());
5887 root->AddChild(container.Pass());
5889 LayerImplList render_surface_layer_list;
5890 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5891 root.get(), root->bounds(), &render_surface_layer_list);
5892 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5894 EXPECT_TRANSFORMATION_MATRIX_EQ(
5895 container_layer->draw_properties().screen_space_transform,
5896 fixed_layer->draw_properties().screen_space_transform);
5897 EXPECT_VECTOR_EQ(
5898 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
5899 container_offset);
5901 gfx::ScrollOffset effective_scroll_offset =
5902 ScrollOffsetWithDelta(scroll_offset, scroll_delta);
5903 gfx::Vector2d rounded_effective_scroll_offset =
5904 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset));
5905 EXPECT_VECTOR_EQ(
5906 scroll_layer->draw_properties().screen_space_transform.To2dTranslation(),
5907 container_offset - rounded_effective_scroll_offset);
5910 TEST_F(LayerTreeHostCommonTest,
5911 ScrollSnappingWithAnimatedScreenSpaceTransform) {
5912 // This test verifies that a scrolling layer whose screen space transform is
5913 // animating doesn't get snapped to integer coordinates.
5915 // + root
5916 // + animated layer
5917 // + surface
5918 // + container
5919 // + scroller
5921 LayerImpl* root = root_layer();
5922 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
5923 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
5924 LayerImpl* container = AddChild<LayerImpl>(surface);
5925 LayerImpl* scroller = AddChild<LayerImpl>(container);
5926 scroller->SetScrollClipLayer(container->id());
5927 scroller->SetDrawsContent(true);
5929 gfx::Transform identity_transform;
5930 gfx::Transform start_scale;
5931 start_scale.Scale(1.5f, 1.5f);
5932 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5933 gfx::PointF(), gfx::Size(50, 50), true, false,
5934 true);
5935 SetLayerPropertiesForTesting(animated_layer, start_scale, gfx::Point3F(),
5936 gfx::PointF(), gfx::Size(50, 50), true, false,
5937 false);
5938 SetLayerPropertiesForTesting(surface, identity_transform, gfx::Point3F(),
5939 gfx::PointF(), gfx::Size(50, 50), true, false,
5940 true);
5941 SetLayerPropertiesForTesting(container, identity_transform, gfx::Point3F(),
5942 gfx::PointF(), gfx::Size(50, 50), true, false,
5943 false);
5944 SetLayerPropertiesForTesting(scroller, identity_transform, gfx::Point3F(),
5945 gfx::PointF(), gfx::Size(100, 100), true, false,
5946 false);
5948 gfx::Transform end_scale;
5949 end_scale.Scale(2.f, 2.f);
5950 TransformOperations start_operations;
5951 start_operations.AppendMatrix(start_scale);
5952 TransformOperations end_operations;
5953 end_operations.AppendMatrix(end_scale);
5954 AddAnimatedTransformToLayer(animated_layer, 1.0, start_operations,
5955 end_operations);
5957 gfx::Vector2dF scroll_delta(5.f, 9.f);
5958 scroller->SetScrollDelta(scroll_delta);
5960 ExecuteCalculateDrawProperties(root);
5962 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
5963 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
5964 scroller->draw_transform().To2dTranslation());
5967 class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
5968 public:
5969 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
5970 LayerTreeImpl* tree_impl,
5971 int id) {
5972 return make_scoped_ptr(
5973 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
5976 ~AnimationScaleFactorTrackingLayerImpl() override {}
5978 private:
5979 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
5980 int id)
5981 : LayerImpl(tree_impl, id) {
5982 SetDrawsContent(true);
5986 TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
5987 FakeImplProxy proxy;
5988 TestSharedBitmapManager shared_bitmap_manager;
5989 TestTaskGraphRunner task_graph_runner;
5990 LayerTreeSettings settings;
5991 settings.layer_transforms_should_scale_layer_contents = true;
5992 FakeLayerTreeHostImpl host_impl(settings, &proxy, &shared_bitmap_manager,
5993 &task_graph_runner);
5994 gfx::Transform identity_matrix;
5995 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
5996 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
5997 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
5998 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
5999 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
6000 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
6001 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
6002 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
6004 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
6005 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
6006 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
6008 child->AddChild(grand_child.Pass());
6009 parent->AddChild(child.Pass());
6010 grand_parent->AddChild(parent.Pass());
6012 SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix,
6013 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6014 true, false, true);
6015 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
6016 gfx::PointF(), gfx::Size(1, 2), true, false,
6017 false);
6018 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
6019 gfx::PointF(), gfx::Size(1, 2), true, false,
6020 false);
6022 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(),
6023 gfx::PointF(), gfx::Size(1, 2), true, false,
6024 false);
6026 ExecuteCalculateDrawProperties(grand_parent.get());
6028 // No layers have animations.
6029 EXPECT_EQ(0.f,
6030 grand_parent->draw_properties().maximum_animation_contents_scale);
6031 EXPECT_EQ(0.f,
6032 parent_raw->draw_properties().maximum_animation_contents_scale);
6033 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6034 EXPECT_EQ(
6035 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6037 EXPECT_EQ(0.f,
6038 grand_parent->draw_properties().starting_animation_contents_scale);
6039 EXPECT_EQ(0.f,
6040 parent_raw->draw_properties().starting_animation_contents_scale);
6041 EXPECT_EQ(0.f,
6042 child_raw->draw_properties().starting_animation_contents_scale);
6043 EXPECT_EQ(
6044 0.f,
6045 grand_child_raw->draw_properties().starting_animation_contents_scale);
6047 TransformOperations translation;
6048 translation.AppendTranslate(1.f, 2.f, 3.f);
6050 AddAnimatedTransformToLayer(
6051 parent_raw, 1.0, TransformOperations(), translation);
6053 // No layers have scale-affecting animations.
6054 EXPECT_EQ(0.f,
6055 grand_parent->draw_properties().maximum_animation_contents_scale);
6056 EXPECT_EQ(0.f,
6057 parent_raw->draw_properties().maximum_animation_contents_scale);
6058 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6059 EXPECT_EQ(
6060 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6062 EXPECT_EQ(0.f,
6063 grand_parent->draw_properties().starting_animation_contents_scale);
6064 EXPECT_EQ(0.f,
6065 parent_raw->draw_properties().starting_animation_contents_scale);
6066 EXPECT_EQ(0.f,
6067 child_raw->draw_properties().starting_animation_contents_scale);
6068 EXPECT_EQ(
6069 0.f,
6070 grand_child_raw->draw_properties().starting_animation_contents_scale);
6072 TransformOperations scale;
6073 scale.AppendScale(5.f, 4.f, 3.f);
6075 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
6076 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
6077 ExecuteCalculateDrawProperties(grand_parent.get());
6079 // Only |child| has a scale-affecting animation.
6080 EXPECT_EQ(0.f,
6081 grand_parent->draw_properties().maximum_animation_contents_scale);
6082 EXPECT_EQ(0.f,
6083 parent_raw->draw_properties().maximum_animation_contents_scale);
6084 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
6085 EXPECT_EQ(
6086 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6088 EXPECT_EQ(0.f,
6089 grand_parent->draw_properties().starting_animation_contents_scale);
6090 EXPECT_EQ(0.f,
6091 parent_raw->draw_properties().starting_animation_contents_scale);
6092 EXPECT_EQ(1.f,
6093 child_raw->draw_properties().starting_animation_contents_scale);
6094 EXPECT_EQ(
6095 1.f,
6096 grand_child_raw->draw_properties().starting_animation_contents_scale);
6098 AddAnimatedTransformToLayer(
6099 grand_parent.get(), 1.0, TransformOperations(), scale);
6100 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
6101 ExecuteCalculateDrawProperties(grand_parent.get());
6103 // |grand_parent| and |child| have scale-affecting animations.
6104 EXPECT_EQ(5.f,
6105 grand_parent->draw_properties().maximum_animation_contents_scale);
6106 EXPECT_EQ(5.f,
6107 parent_raw->draw_properties().maximum_animation_contents_scale);
6108 // We don't support combining animated scales from two nodes; 0.f means
6109 // that the maximum scale could not be computed.
6110 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6111 EXPECT_EQ(
6112 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6114 EXPECT_EQ(1.f,
6115 grand_parent->draw_properties().starting_animation_contents_scale);
6116 EXPECT_EQ(1.f,
6117 parent_raw->draw_properties().starting_animation_contents_scale);
6118 EXPECT_EQ(0.f,
6119 child_raw->draw_properties().starting_animation_contents_scale);
6120 EXPECT_EQ(
6121 0.f,
6122 grand_child_raw->draw_properties().starting_animation_contents_scale);
6124 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
6125 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
6126 ExecuteCalculateDrawProperties(grand_parent.get());
6128 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
6129 EXPECT_EQ(5.f,
6130 grand_parent->draw_properties().maximum_animation_contents_scale);
6131 EXPECT_EQ(0.f,
6132 parent_raw->draw_properties().maximum_animation_contents_scale);
6133 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6134 EXPECT_EQ(
6135 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6137 EXPECT_EQ(1.f,
6138 grand_parent->draw_properties().starting_animation_contents_scale);
6139 EXPECT_EQ(0.f,
6140 parent_raw->draw_properties().starting_animation_contents_scale);
6141 EXPECT_EQ(0.f,
6142 child_raw->draw_properties().starting_animation_contents_scale);
6143 EXPECT_EQ(
6144 0.f,
6145 grand_child_raw->draw_properties().starting_animation_contents_scale);
6147 grand_parent->layer_animation_controller()->AbortAnimations(
6148 Animation::TRANSFORM);
6149 parent_raw->layer_animation_controller()->AbortAnimations(
6150 Animation::TRANSFORM);
6151 child_raw->layer_animation_controller()->AbortAnimations(
6152 Animation::TRANSFORM);
6154 TransformOperations perspective;
6155 perspective.AppendPerspective(10.f);
6157 AddAnimatedTransformToLayer(
6158 child_raw, 1.0, TransformOperations(), perspective);
6159 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
6160 ExecuteCalculateDrawProperties(grand_parent.get());
6162 // |child| has a scale-affecting animation but computing the maximum of this
6163 // animation is not supported.
6164 EXPECT_EQ(0.f,
6165 grand_parent->draw_properties().maximum_animation_contents_scale);
6166 EXPECT_EQ(0.f,
6167 parent_raw->draw_properties().maximum_animation_contents_scale);
6168 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6169 EXPECT_EQ(
6170 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6172 EXPECT_EQ(0.f,
6173 grand_parent->draw_properties().starting_animation_contents_scale);
6174 EXPECT_EQ(0.f,
6175 parent_raw->draw_properties().starting_animation_contents_scale);
6176 EXPECT_EQ(0.f,
6177 child_raw->draw_properties().starting_animation_contents_scale);
6178 EXPECT_EQ(
6179 0.f,
6180 grand_child_raw->draw_properties().starting_animation_contents_scale);
6182 child_raw->layer_animation_controller()->AbortAnimations(
6183 Animation::TRANSFORM);
6185 gfx::Transform scale_matrix;
6186 scale_matrix.Scale(1.f, 2.f);
6187 grand_parent->SetTransform(scale_matrix);
6188 parent_raw->SetTransform(scale_matrix);
6189 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
6190 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
6191 ExecuteCalculateDrawProperties(grand_parent.get());
6193 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
6194 // animation with maximum scale 5.f.
6195 EXPECT_EQ(0.f,
6196 grand_parent->draw_properties().maximum_animation_contents_scale);
6197 EXPECT_EQ(10.f,
6198 parent_raw->draw_properties().maximum_animation_contents_scale);
6199 EXPECT_EQ(10.f,
6200 child_raw->draw_properties().maximum_animation_contents_scale);
6201 EXPECT_EQ(
6202 10.f,
6203 grand_child_raw->draw_properties().maximum_animation_contents_scale);
6205 EXPECT_EQ(0.f,
6206 grand_parent->draw_properties().starting_animation_contents_scale);
6207 EXPECT_EQ(2.f,
6208 parent_raw->draw_properties().starting_animation_contents_scale);
6209 EXPECT_EQ(2.f,
6210 child_raw->draw_properties().starting_animation_contents_scale);
6211 EXPECT_EQ(
6212 2.f,
6213 grand_child_raw->draw_properties().starting_animation_contents_scale);
6215 gfx::Transform perspective_matrix;
6216 perspective_matrix.ApplyPerspectiveDepth(2.f);
6217 child_raw->SetTransform(perspective_matrix);
6218 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
6219 ExecuteCalculateDrawProperties(grand_parent.get());
6221 // |child| has a transform that's neither a translation nor a scale.
6222 EXPECT_EQ(0.f,
6223 grand_parent->draw_properties().maximum_animation_contents_scale);
6224 EXPECT_EQ(10.f,
6225 parent_raw->draw_properties().maximum_animation_contents_scale);
6226 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6227 EXPECT_EQ(
6228 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6230 EXPECT_EQ(0.f,
6231 grand_parent->draw_properties().starting_animation_contents_scale);
6232 EXPECT_EQ(2.f,
6233 parent_raw->draw_properties().starting_animation_contents_scale);
6234 EXPECT_EQ(0.f,
6235 child_raw->draw_properties().starting_animation_contents_scale);
6236 EXPECT_EQ(
6237 0.f,
6238 grand_child_raw->draw_properties().starting_animation_contents_scale);
6240 parent_raw->SetTransform(perspective_matrix);
6241 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
6242 ExecuteCalculateDrawProperties(grand_parent.get());
6244 // |parent| and |child| have transforms that are neither translations nor
6245 // scales.
6246 EXPECT_EQ(0.f,
6247 grand_parent->draw_properties().maximum_animation_contents_scale);
6248 EXPECT_EQ(0.f,
6249 parent_raw->draw_properties().maximum_animation_contents_scale);
6250 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6251 EXPECT_EQ(
6252 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6254 EXPECT_EQ(0.f,
6255 grand_parent->draw_properties().starting_animation_contents_scale);
6256 EXPECT_EQ(0.f,
6257 parent_raw->draw_properties().starting_animation_contents_scale);
6258 EXPECT_EQ(0.f,
6259 child_raw->draw_properties().starting_animation_contents_scale);
6260 EXPECT_EQ(
6261 0.f,
6262 grand_child_raw->draw_properties().starting_animation_contents_scale);
6264 parent_raw->SetTransform(identity_matrix);
6265 child_raw->SetTransform(identity_matrix);
6266 grand_parent->SetTransform(perspective_matrix);
6267 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
6269 ExecuteCalculateDrawProperties(grand_parent.get());
6271 // |grand_parent| has a transform that's neither a translation nor a scale.
6272 EXPECT_EQ(0.f,
6273 grand_parent->draw_properties().maximum_animation_contents_scale);
6274 EXPECT_EQ(0.f,
6275 parent_raw->draw_properties().maximum_animation_contents_scale);
6276 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6277 EXPECT_EQ(
6278 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6280 EXPECT_EQ(0.f,
6281 grand_parent->draw_properties().starting_animation_contents_scale);
6282 EXPECT_EQ(0.f,
6283 parent_raw->draw_properties().starting_animation_contents_scale);
6284 EXPECT_EQ(0.f,
6285 child_raw->draw_properties().starting_animation_contents_scale);
6286 EXPECT_EQ(
6287 0.f,
6288 grand_child_raw->draw_properties().starting_animation_contents_scale);
6291 static int membership_id(LayerImpl* layer) {
6292 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
6295 static void GatherDrawnLayers(LayerImplList* rsll,
6296 std::set<LayerImpl*>* drawn_layers) {
6297 for (LayerIterator it = LayerIterator::Begin(rsll),
6298 end = LayerIterator::End(rsll);
6299 it != end; ++it) {
6300 LayerImpl* layer = *it;
6301 if (it.represents_itself())
6302 drawn_layers->insert(layer);
6304 if (!it.represents_contributing_render_surface())
6305 continue;
6307 if (layer->mask_layer())
6308 drawn_layers->insert(layer->mask_layer());
6309 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
6310 drawn_layers->insert(layer->replica_layer()->mask_layer());
6314 TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
6315 FakeImplProxy proxy;
6316 TestSharedBitmapManager shared_bitmap_manager;
6317 TestTaskGraphRunner task_graph_runner;
6318 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
6319 &task_graph_runner);
6320 gfx::Transform identity_matrix;
6322 scoped_ptr<LayerImpl> grand_parent =
6323 LayerImpl::Create(host_impl.active_tree(), 1);
6324 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3);
6325 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5);
6326 scoped_ptr<LayerImpl> grand_child1 =
6327 LayerImpl::Create(host_impl.active_tree(), 7);
6328 scoped_ptr<LayerImpl> grand_child2 =
6329 LayerImpl::Create(host_impl.active_tree(), 9);
6331 LayerImpl* grand_parent_raw = grand_parent.get();
6332 LayerImpl* parent_raw = parent.get();
6333 LayerImpl* child_raw = child.get();
6334 LayerImpl* grand_child1_raw = grand_child1.get();
6335 LayerImpl* grand_child2_raw = grand_child2.get();
6337 child->AddChild(grand_child1.Pass());
6338 child->AddChild(grand_child2.Pass());
6339 parent->AddChild(child.Pass());
6340 grand_parent->AddChild(parent.Pass());
6342 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
6343 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6344 true, false, true);
6345 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
6346 gfx::PointF(), gfx::Size(1, 2), true, false,
6347 false);
6349 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
6350 gfx::PointF(), gfx::Size(1, 2), true, false,
6351 false);
6353 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix,
6354 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6355 true, false, false);
6357 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix,
6358 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6359 true, false, false);
6361 // Start with nothing being drawn.
6362 ExecuteCalculateDrawProperties(grand_parent_raw);
6363 int member_id = render_surface_layer_list_count();
6365 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6366 EXPECT_NE(member_id, membership_id(parent_raw));
6367 EXPECT_NE(member_id, membership_id(child_raw));
6368 EXPECT_NE(member_id, membership_id(grand_child1_raw));
6369 EXPECT_NE(member_id, membership_id(grand_child2_raw));
6371 std::set<LayerImpl*> expected;
6372 std::set<LayerImpl*> actual;
6373 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6374 EXPECT_EQ(expected, actual);
6376 // If we force render surface, but none of the layers are in the layer list,
6377 // then this layer should not appear in RSLL.
6378 grand_child1_raw->SetHasRenderSurface(true);
6379 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
6381 ExecuteCalculateDrawProperties(grand_parent_raw);
6382 member_id = render_surface_layer_list_count();
6384 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6385 EXPECT_NE(member_id, membership_id(parent_raw));
6386 EXPECT_NE(member_id, membership_id(child_raw));
6387 EXPECT_NE(member_id, membership_id(grand_child1_raw));
6388 EXPECT_NE(member_id, membership_id(grand_child2_raw));
6390 expected.clear();
6391 actual.clear();
6392 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6393 EXPECT_EQ(expected, actual);
6395 // However, if we say that this layer also draws content, it will appear in
6396 // RSLL.
6397 grand_child1_raw->SetDrawsContent(true);
6399 ExecuteCalculateDrawProperties(grand_parent_raw);
6400 member_id = render_surface_layer_list_count();
6402 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6403 EXPECT_NE(member_id, membership_id(parent_raw));
6404 EXPECT_NE(member_id, membership_id(child_raw));
6405 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
6406 EXPECT_NE(member_id, membership_id(grand_child2_raw));
6408 expected.clear();
6409 expected.insert(grand_child1_raw);
6411 actual.clear();
6412 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6413 EXPECT_EQ(expected, actual);
6415 // Now child is forced to have a render surface, and one if its children draws
6416 // content.
6417 grand_child1_raw->SetDrawsContent(false);
6418 grand_child1_raw->SetHasRenderSurface(false);
6419 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
6420 child_raw->SetHasRenderSurface(true);
6421 grand_child2_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_NE(member_id, membership_id(grand_child1_raw));
6430 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
6432 expected.clear();
6433 expected.insert(grand_child2_raw);
6435 actual.clear();
6436 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6437 EXPECT_EQ(expected, actual);
6439 // Add a mask layer to child.
6440 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass());
6441 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
6443 ExecuteCalculateDrawProperties(grand_parent_raw);
6444 member_id = render_surface_layer_list_count();
6446 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6447 EXPECT_NE(member_id, membership_id(parent_raw));
6448 EXPECT_NE(member_id, membership_id(child_raw));
6449 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
6450 EXPECT_NE(member_id, membership_id(grand_child1_raw));
6451 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
6453 expected.clear();
6454 expected.insert(grand_child2_raw);
6455 expected.insert(child_raw->mask_layer());
6457 expected.clear();
6458 expected.insert(grand_child2_raw);
6459 expected.insert(child_raw->mask_layer());
6461 actual.clear();
6462 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6463 EXPECT_EQ(expected, actual);
6465 // Add replica mask layer.
6466 scoped_ptr<LayerImpl> replica_layer =
6467 LayerImpl::Create(host_impl.active_tree(), 20);
6468 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
6469 child_raw->SetReplicaLayer(replica_layer.Pass());
6470 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
6472 ExecuteCalculateDrawProperties(grand_parent_raw);
6473 member_id = render_surface_layer_list_count();
6475 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6476 EXPECT_NE(member_id, membership_id(parent_raw));
6477 EXPECT_NE(member_id, membership_id(child_raw));
6478 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
6479 EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer()));
6480 EXPECT_NE(member_id, membership_id(grand_child1_raw));
6481 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
6483 expected.clear();
6484 expected.insert(grand_child2_raw);
6485 expected.insert(child_raw->mask_layer());
6486 expected.insert(child_raw->replica_layer()->mask_layer());
6488 actual.clear();
6489 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6490 EXPECT_EQ(expected, actual);
6492 child_raw->TakeReplicaLayer();
6494 // With nothing drawing, we should have no layers.
6495 grand_child2_raw->SetDrawsContent(false);
6497 ExecuteCalculateDrawProperties(grand_parent_raw);
6498 member_id = render_surface_layer_list_count();
6500 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6501 EXPECT_NE(member_id, membership_id(parent_raw));
6502 EXPECT_NE(member_id, membership_id(child_raw));
6503 EXPECT_NE(member_id, membership_id(child_raw->mask_layer()));
6504 EXPECT_NE(member_id, membership_id(grand_child1_raw));
6505 EXPECT_NE(member_id, membership_id(grand_child2_raw));
6507 expected.clear();
6508 actual.clear();
6509 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6510 EXPECT_EQ(expected, actual);
6512 // Child itself draws means that we should have the child and the mask in the
6513 // list.
6514 child_raw->SetDrawsContent(true);
6516 ExecuteCalculateDrawProperties(grand_parent_raw);
6517 member_id = render_surface_layer_list_count();
6519 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6520 EXPECT_NE(member_id, membership_id(parent_raw));
6521 EXPECT_EQ(member_id, membership_id(child_raw));
6522 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
6523 EXPECT_NE(member_id, membership_id(grand_child1_raw));
6524 EXPECT_NE(member_id, membership_id(grand_child2_raw));
6526 expected.clear();
6527 expected.insert(child_raw);
6528 expected.insert(child_raw->mask_layer());
6529 actual.clear();
6530 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6531 EXPECT_EQ(expected, actual);
6533 child_raw->TakeMaskLayer();
6534 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
6536 // Now everyone's a member!
6537 grand_parent_raw->SetDrawsContent(true);
6538 parent_raw->SetDrawsContent(true);
6539 child_raw->SetDrawsContent(true);
6540 grand_child1_raw->SetDrawsContent(true);
6541 grand_child2_raw->SetDrawsContent(true);
6543 ExecuteCalculateDrawProperties(grand_parent_raw);
6544 member_id = render_surface_layer_list_count();
6546 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
6547 EXPECT_EQ(member_id, membership_id(parent_raw));
6548 EXPECT_EQ(member_id, membership_id(child_raw));
6549 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
6550 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
6552 expected.clear();
6553 expected.insert(grand_parent_raw);
6554 expected.insert(parent_raw);
6555 expected.insert(child_raw);
6556 expected.insert(grand_child1_raw);
6557 expected.insert(grand_child2_raw);
6559 actual.clear();
6560 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6561 EXPECT_EQ(expected, actual);
6564 TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
6565 FakeImplProxy proxy;
6566 TestSharedBitmapManager shared_bitmap_manager;
6567 TestTaskGraphRunner task_graph_runner;
6568 LayerTreeSettings settings;
6569 settings.layer_transforms_should_scale_layer_contents = true;
6570 FakeLayerTreeHostImpl host_impl(settings, &proxy, &shared_bitmap_manager,
6571 &task_graph_runner);
6573 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
6574 LayerImpl* root_layer = root.get();
6575 scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2);
6576 LayerImpl* child1_layer = child1.get();
6577 scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3);
6578 LayerImpl* child2_layer = child2.get();
6580 root->AddChild(child1.Pass());
6581 root->AddChild(child2.Pass());
6582 root->SetHasRenderSurface(true);
6584 gfx::Transform identity_matrix, scale_transform_child1,
6585 scale_transform_child2;
6586 scale_transform_child1.Scale(2, 3);
6587 scale_transform_child2.Scale(4, 5);
6589 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(),
6590 gfx::PointF(), gfx::Size(1, 1), true, false,
6591 true);
6592 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1,
6593 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
6594 false, false);
6596 child1_layer->SetMaskLayer(
6597 LayerImpl::Create(host_impl.active_tree(), 4).Pass());
6599 scoped_ptr<LayerImpl> replica_layer =
6600 LayerImpl::Create(host_impl.active_tree(), 5);
6601 replica_layer->SetHasRenderSurface(true);
6602 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
6603 child1_layer->SetReplicaLayer(replica_layer.Pass());
6604 child1_layer->SetHasRenderSurface(true);
6606 ExecuteCalculateDrawProperties(root_layer);
6608 TransformOperations scale;
6609 scale.AppendScale(5.f, 8.f, 3.f);
6611 AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale);
6612 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2,
6613 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
6614 false, false);
6616 ExecuteCalculateDrawProperties(root_layer);
6618 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
6619 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
6620 EXPECT_FLOAT_EQ(3.f, child1_layer->mask_layer()->GetIdealContentsScale());
6621 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
6623 EXPECT_FLOAT_EQ(
6624 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
6625 EXPECT_FLOAT_EQ(
6626 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
6627 EXPECT_FLOAT_EQ(0.f,
6628 child1_layer->mask_layer()
6629 ->draw_properties()
6630 .maximum_animation_contents_scale);
6631 EXPECT_FLOAT_EQ(0.f,
6632 child1_layer->replica_layer()
6633 ->mask_layer()
6634 ->draw_properties()
6635 .maximum_animation_contents_scale);
6636 EXPECT_FLOAT_EQ(
6637 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
6639 // Changing page-scale would affect ideal_contents_scale and
6640 // maximum_animation_contents_scale.
6642 float page_scale_factor = 3.f;
6643 float device_scale_factor = 1.0f;
6644 std::vector<LayerImpl*> render_surface_layer_list;
6645 gfx::Size device_viewport_size =
6646 gfx::Size(root_layer->bounds().width() * device_scale_factor,
6647 root_layer->bounds().height() * device_scale_factor);
6648 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6649 root_layer, device_viewport_size, &render_surface_layer_list);
6651 inputs.page_scale_factor = page_scale_factor;
6652 inputs.can_adjust_raster_scales = true;
6653 inputs.page_scale_layer = root_layer;
6654 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6656 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
6657 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
6658 EXPECT_FLOAT_EQ(9.f, child1_layer->mask_layer()->GetIdealContentsScale());
6659 EXPECT_FLOAT_EQ(
6660 9.f,
6661 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
6662 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
6664 EXPECT_FLOAT_EQ(
6665 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
6666 EXPECT_FLOAT_EQ(
6667 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
6668 EXPECT_FLOAT_EQ(0.f,
6669 child1_layer->mask_layer()
6670 ->draw_properties()
6671 .maximum_animation_contents_scale);
6672 EXPECT_FLOAT_EQ(0.f,
6673 child1_layer->replica_layer()
6674 ->mask_layer()
6675 ->draw_properties()
6676 .maximum_animation_contents_scale);
6677 EXPECT_FLOAT_EQ(
6678 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
6680 // Changing device-scale would affect ideal_contents_scale and
6681 // maximum_animation_contents_scale.
6683 device_scale_factor = 4.0f;
6684 inputs.device_scale_factor = device_scale_factor;
6685 inputs.can_adjust_raster_scales = true;
6686 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6688 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
6689 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
6690 EXPECT_FLOAT_EQ(36.f, child1_layer->mask_layer()->GetIdealContentsScale());
6691 EXPECT_FLOAT_EQ(
6692 36.f,
6693 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
6694 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
6696 EXPECT_FLOAT_EQ(
6697 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
6698 EXPECT_FLOAT_EQ(
6699 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
6700 EXPECT_FLOAT_EQ(0.f,
6701 child1_layer->mask_layer()
6702 ->draw_properties()
6703 .maximum_animation_contents_scale);
6704 EXPECT_FLOAT_EQ(0.f,
6705 child1_layer->replica_layer()
6706 ->mask_layer()
6707 ->draw_properties()
6708 .maximum_animation_contents_scale);
6709 EXPECT_FLOAT_EQ(
6710 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
6713 TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
6714 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6715 SetLayerPropertiesForTesting(root.get(),
6716 gfx::Transform(),
6717 gfx::Point3F(),
6718 gfx::PointF(),
6719 gfx::Size(768 / 2, 3000),
6720 true,
6721 false);
6722 root->SetIsDrawable(true);
6724 scoped_refptr<Layer> clip = Layer::Create(layer_settings());
6725 SetLayerPropertiesForTesting(clip.get(),
6726 gfx::Transform(),
6727 gfx::Point3F(),
6728 gfx::PointF(),
6729 gfx::Size(768 / 2, 10000),
6730 true,
6731 false);
6732 clip->SetMasksToBounds(true);
6734 scoped_refptr<Layer> content = Layer::Create(layer_settings());
6735 SetLayerPropertiesForTesting(content.get(),
6736 gfx::Transform(),
6737 gfx::Point3F(),
6738 gfx::PointF(),
6739 gfx::Size(768 / 2, 10000),
6740 true,
6741 false);
6742 content->SetIsDrawable(true);
6743 content->SetForceRenderSurface(true);
6745 root->AddChild(clip);
6746 clip->AddChild(content);
6748 host()->SetRootLayer(root);
6750 gfx::Size device_viewport_size(768, 582);
6751 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(host()->root_layer(),
6752 device_viewport_size);
6753 inputs.device_scale_factor = 2.f;
6754 inputs.page_scale_factor = 1.f;
6755 inputs.page_scale_layer = NULL;
6756 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6758 // Layers in the root render surface have their visible content rect clipped
6759 // by the viewport.
6760 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
6761 root->visible_rect_from_property_trees());
6763 // Layers drawing to a child render surface should still have their visible
6764 // content rect clipped by the viewport.
6765 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
6766 content->visible_rect_from_property_trees());
6769 TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
6770 FakeImplProxy proxy;
6771 TestSharedBitmapManager shared_bitmap_manager;
6772 TestTaskGraphRunner task_graph_runner;
6773 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
6774 &task_graph_runner);
6776 // Set two layers: the root layer clips it's child,
6777 // the child draws its content.
6779 gfx::Size root_size = gfx::Size(300, 500);
6781 // Sublayer should be bigger than the root enlarged by bounds_delta.
6782 gfx::Size sublayer_size = gfx::Size(300, 1000);
6784 // Device viewport accomidated the root and the top controls.
6785 gfx::Size device_viewport_size = gfx::Size(300, 600);
6786 gfx::Transform identity_matrix;
6788 host_impl.SetViewportSize(device_viewport_size);
6789 host_impl.active_tree()->SetRootLayer(
6790 LayerImpl::Create(host_impl.active_tree(), 1));
6792 LayerImpl* root = host_impl.active_tree()->root_layer();
6793 SetLayerPropertiesForTesting(root,
6794 identity_matrix,
6795 gfx::Point3F(),
6796 gfx::PointF(),
6797 root_size,
6798 false,
6799 false,
6800 true);
6801 root->SetMasksToBounds(true);
6803 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2));
6805 LayerImpl* sublayer = root->child_at(0);
6806 SetLayerPropertiesForTesting(sublayer,
6807 identity_matrix,
6808 gfx::Point3F(),
6809 gfx::PointF(),
6810 sublayer_size,
6811 false,
6812 false,
6813 false);
6814 sublayer->SetDrawsContent(true);
6816 LayerImplList layer_impl_list;
6817 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6818 root, device_viewport_size, &layer_impl_list);
6820 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6821 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
6823 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
6824 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6826 gfx::Rect affected_by_delta(0, 0, root_size.width(),
6827 root_size.height() + 50);
6828 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
6831 TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) {
6832 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6833 scoped_refptr<Layer> inner_viewport_container_layer =
6834 Layer::Create(layer_settings());
6835 scoped_refptr<Layer> inner_viewport_scroll_layer =
6836 Layer::Create(layer_settings());
6837 scoped_refptr<Layer> outer_viewport_container_layer =
6838 Layer::Create(layer_settings());
6839 scoped_refptr<Layer> outer_viewport_scroll_layer =
6840 Layer::Create(layer_settings());
6842 root->AddChild(inner_viewport_container_layer);
6843 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer);
6844 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
6845 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
6847 inner_viewport_scroll_layer->SetScrollClipLayerId(
6848 inner_viewport_container_layer->id());
6849 outer_viewport_scroll_layer->SetScrollClipLayerId(
6850 outer_viewport_container_layer->id());
6852 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
6853 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
6855 host()->SetRootLayer(root);
6856 host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer,
6857 outer_viewport_scroll_layer);
6859 scoped_refptr<Layer> fixed_to_inner = Layer::Create(layer_settings());
6860 scoped_refptr<Layer> fixed_to_outer = Layer::Create(layer_settings());
6862 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
6863 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
6865 LayerPositionConstraint fixed_to_right;
6866 fixed_to_right.set_is_fixed_position(true);
6867 fixed_to_right.set_is_fixed_to_right_edge(true);
6869 fixed_to_inner->SetPositionConstraint(fixed_to_right);
6870 fixed_to_outer->SetPositionConstraint(fixed_to_right);
6872 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
6874 TransformTree& transform_tree = host()->property_trees()->transform_tree;
6875 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
6876 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
6878 LayerPositionConstraint fixed_to_left;
6879 fixed_to_left.set_is_fixed_position(true);
6880 fixed_to_inner->SetPositionConstraint(fixed_to_left);
6882 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
6883 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
6884 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
6886 fixed_to_outer->SetPositionConstraint(fixed_to_left);
6888 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
6889 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
6890 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
6893 TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
6894 const gfx::Transform identity_matrix;
6895 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6896 scoped_refptr<LayerWithForcedDrawsContent> animated =
6897 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6899 root->AddChild(animated);
6901 host()->SetRootLayer(root);
6903 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
6904 gfx::PointF(), gfx::Size(100, 100), true, false);
6905 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
6906 gfx::PointF(), gfx::Size(20, 20), true, false);
6908 root->SetMasksToBounds(true);
6909 root->SetForceRenderSurface(true);
6910 animated->SetOpacity(0.f);
6912 AddOpacityTransitionToController(animated->layer_animation_controller(), 10.0,
6913 0.f, 1.f, false);
6915 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
6917 EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty());
6920 TEST_F(LayerTreeHostCommonTest,
6921 VisibleContentRectForAnimatedLayerWithSingularTransform) {
6922 const gfx::Transform identity_matrix;
6923 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6924 scoped_refptr<Layer> clip = Layer::Create(layer_settings());
6925 scoped_refptr<LayerWithForcedDrawsContent> animated =
6926 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6927 scoped_refptr<LayerWithForcedDrawsContent> surface =
6928 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6929 scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation =
6930 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6932 root->AddChild(clip);
6933 clip->AddChild(animated);
6934 animated->AddChild(surface);
6935 surface->AddChild(descendant_of_animation);
6937 clip->SetMasksToBounds(true);
6938 surface->SetForceRenderSurface(true);
6940 host()->SetRootLayer(root);
6942 gfx::Transform uninvertible_matrix;
6943 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
6945 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
6946 gfx::PointF(), gfx::Size(100, 100), true, false);
6947 SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(),
6948 gfx::PointF(), gfx::Size(10, 10), true, false);
6949 SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix,
6950 gfx::Point3F(), gfx::PointF(),
6951 gfx::Size(120, 120), true, false);
6952 SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(),
6953 gfx::PointF(), gfx::Size(100, 100), true, false);
6954 SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix,
6955 gfx::Point3F(), gfx::PointF(),
6956 gfx::Size(200, 200), true, false);
6958 TransformOperations start_transform_operations;
6959 start_transform_operations.AppendMatrix(uninvertible_matrix);
6960 TransformOperations end_transform_operations;
6962 AddAnimatedTransformToLayer(animated.get(), 10.0, start_transform_operations,
6963 end_transform_operations);
6965 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
6967 // The animated layer has a singular transform and maps to a non-empty rect in
6968 // clipped target space, so is treated as fully visible.
6969 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_rect_from_property_trees());
6971 // The singular transform on |animated| is flattened when inherited by
6972 // |surface|, and this happens to make it invertible.
6973 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_rect_from_property_trees());
6974 EXPECT_EQ(gfx::Rect(2, 2),
6975 descendant_of_animation->visible_rect_from_property_trees());
6977 gfx::Transform zero_matrix;
6978 zero_matrix.Scale3d(0.f, 0.f, 0.f);
6979 SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(),
6980 gfx::PointF(), gfx::Size(120, 120), true, false);
6982 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
6984 // The animated layer maps to the empty rect in clipped target space, so is
6985 // treated as having an empty visible rect.
6986 EXPECT_EQ(gfx::Rect(), animated->visible_rect_from_property_trees());
6988 // This time, flattening does not make |animated|'s transform invertible. This
6989 // means the clip cannot be projected into |surface|'s space, so we treat
6990 // |surface| and layers that draw into it as having empty visible rect.
6991 EXPECT_EQ(gfx::Rect(), surface->visible_rect_from_property_trees());
6992 EXPECT_EQ(gfx::Rect(),
6993 descendant_of_animation->visible_rect_from_property_trees());
6996 // Verify that having an animated filter (but no current filter, as these
6997 // are mutually exclusive) correctly creates a render surface.
6998 TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
6999 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7000 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7001 scoped_refptr<Layer> grandchild = Layer::Create(layer_settings());
7002 root->AddChild(child);
7003 child->AddChild(grandchild);
7005 gfx::Transform identity_transform;
7006 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7007 gfx::PointF(), gfx::Size(50, 50), true, false);
7008 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
7009 gfx::PointF(), gfx::Size(50, 50), true, false);
7010 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
7011 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7012 true, false);
7013 host()->SetRootLayer(root);
7015 AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f);
7017 ExecuteCalculateDrawProperties(root.get());
7019 EXPECT_TRUE(root->has_render_surface());
7020 EXPECT_TRUE(child->has_render_surface());
7021 EXPECT_FALSE(grandchild->has_render_surface());
7023 EXPECT_TRUE(root->filters().IsEmpty());
7024 EXPECT_TRUE(child->filters().IsEmpty());
7025 EXPECT_TRUE(grandchild->filters().IsEmpty());
7027 EXPECT_FALSE(root->FilterIsAnimating());
7028 EXPECT_TRUE(child->FilterIsAnimating());
7029 EXPECT_FALSE(grandchild->FilterIsAnimating());
7032 // Verify that having a filter animation with a delayed start time creates a
7033 // render surface.
7034 TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
7035 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7036 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7037 scoped_refptr<Layer> grandchild = Layer::Create(layer_settings());
7038 root->AddChild(child);
7039 child->AddChild(grandchild);
7041 gfx::Transform identity_transform;
7042 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7043 gfx::PointF(), gfx::Size(50, 50), true, false);
7044 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
7045 gfx::PointF(), gfx::Size(50, 50), true, false);
7046 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
7047 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7048 true, false);
7049 host()->SetRootLayer(root);
7051 scoped_ptr<KeyframedFilterAnimationCurve> curve(
7052 KeyframedFilterAnimationCurve::Create());
7053 FilterOperations start_filters;
7054 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
7055 FilterOperations end_filters;
7056 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
7057 curve->AddKeyframe(
7058 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
7059 curve->AddKeyframe(FilterKeyframe::Create(
7060 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
7061 scoped_ptr<Animation> animation =
7062 Animation::Create(curve.Pass(), 0, 1, Animation::FILTER);
7063 animation->set_fill_mode(Animation::FILL_MODE_NONE);
7064 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7065 child->layer_animation_controller()->AddAnimation(animation.Pass());
7067 ExecuteCalculateDrawProperties(root.get());
7069 EXPECT_TRUE(root->has_render_surface());
7070 EXPECT_TRUE(child->has_render_surface());
7071 EXPECT_FALSE(grandchild->has_render_surface());
7073 EXPECT_TRUE(root->filters().IsEmpty());
7074 EXPECT_TRUE(child->filters().IsEmpty());
7075 EXPECT_TRUE(grandchild->filters().IsEmpty());
7077 EXPECT_FALSE(root->FilterIsAnimating());
7078 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
7079 EXPECT_FALSE(child->FilterIsAnimating());
7080 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
7081 EXPECT_FALSE(grandchild->FilterIsAnimating());
7082 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
7085 // Ensures that the property tree code accounts for offsets between fixed
7086 // position layers and their respective containers.
7087 TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
7088 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7089 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7090 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
7091 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7093 root->AddChild(child);
7094 child->AddChild(grandchild);
7096 gfx::Transform identity_transform;
7097 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7098 gfx::PointF(), gfx::Size(50, 50), true, false);
7099 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
7100 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7101 false);
7102 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
7103 gfx::Point3F(), gfx::PointF(-1000, -1000),
7104 gfx::Size(50, 50), true, false);
7106 root->SetMasksToBounds(true);
7107 root->SetIsContainerForFixedPositionLayers(true);
7108 LayerPositionConstraint constraint;
7109 constraint.set_is_fixed_position(true);
7110 grandchild->SetPositionConstraint(constraint);
7112 root->SetIsContainerForFixedPositionLayers(true);
7114 host()->SetRootLayer(root);
7116 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7118 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7119 grandchild->visible_rect_from_property_trees());
7122 // Ensures that the property tree code accounts for offsets between fixed
7123 // position containers and their transform tree parents, when a fixed position
7124 // layer's container is its layer tree parent, but this parent doesn't have its
7125 // own transform tree node.
7126 TEST_F(LayerTreeHostCommonTest,
7127 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
7128 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7129 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7130 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
7131 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7133 root->AddChild(child);
7134 child->AddChild(grandchild);
7136 gfx::Transform identity_transform;
7137 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7138 gfx::PointF(), gfx::Size(50, 50), true, false);
7139 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
7140 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7141 false);
7142 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
7143 gfx::Point3F(), gfx::PointF(-1000, -1000),
7144 gfx::Size(50, 50), true, false);
7146 root->SetMasksToBounds(true);
7147 child->SetIsContainerForFixedPositionLayers(true);
7148 LayerPositionConstraint constraint;
7149 constraint.set_is_fixed_position(true);
7150 grandchild->SetPositionConstraint(constraint);
7152 root->SetIsContainerForFixedPositionLayers(true);
7154 host()->SetRootLayer(root);
7156 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7158 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7159 grandchild->visible_rect_from_property_trees());
7162 TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) {
7163 // In the following layer tree, the layer |box|'s render target is |surface|.
7164 // |surface| also creates a transform node. We want to combine clips for |box|
7165 // in the space of its target (i.e., |surface|), not its target's target. This
7166 // test ensures that happens.
7168 gfx::Transform rotate;
7169 rotate.Rotate(5);
7170 gfx::Transform identity;
7172 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7173 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7174 gfx::PointF(), gfx::Size(2500, 1500), true,
7175 false);
7177 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
7178 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
7179 gfx::PointF(), gfx::Size(2500, 1500), true,
7180 false);
7181 frame_clip->SetMasksToBounds(true);
7183 scoped_refptr<Layer> rotated = Layer::Create(layer_settings());
7184 SetLayerPropertiesForTesting(rotated.get(), rotate,
7185 gfx::Point3F(1250, 250, 0), gfx::PointF(),
7186 gfx::Size(2500, 500), true, false);
7188 scoped_refptr<Layer> surface = Layer::Create(layer_settings());
7189 SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(),
7190 gfx::PointF(), gfx::Size(2500, 500), true,
7191 false);
7192 surface->SetOpacity(0.5);
7194 scoped_refptr<LayerWithForcedDrawsContent> container =
7195 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7196 SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(),
7197 gfx::PointF(), gfx::Size(300, 300), true, false);
7199 scoped_refptr<LayerWithForcedDrawsContent> box =
7200 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7201 SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(),
7202 gfx::PointF(), gfx::Size(100, 100), true, false);
7204 root->AddChild(frame_clip);
7205 frame_clip->AddChild(rotated);
7206 rotated->AddChild(surface);
7207 surface->AddChild(container);
7208 surface->AddChild(box);
7210 host()->SetRootLayer(root);
7212 ExecuteCalculateDrawProperties(root.get());
7215 TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
7216 gfx::Transform identity;
7217 gfx::Transform translate_z;
7218 translate_z.Translate3d(0, 0, 10);
7220 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7221 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7222 gfx::PointF(), gfx::Size(800, 800), true, false);
7223 root->SetIsContainerForFixedPositionLayers(true);
7225 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
7226 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
7227 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7228 false);
7229 frame_clip->SetMasksToBounds(true);
7231 scoped_refptr<LayerWithForcedDrawsContent> fixed =
7232 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7233 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
7234 gfx::PointF(), gfx::Size(1000, 1000), true,
7235 false);
7237 LayerPositionConstraint constraint;
7238 constraint.set_is_fixed_position(true);
7239 fixed->SetPositionConstraint(constraint);
7241 root->AddChild(frame_clip);
7242 frame_clip->AddChild(fixed);
7244 host()->SetRootLayer(root);
7246 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7248 gfx::Rect expected(0, 0, 100, 100);
7249 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
7252 TEST_F(LayerTreeHostCommonTest,
7253 PropertyTreesAccountForScrollCompensationAdjustment) {
7254 gfx::Transform identity;
7255 gfx::Transform translate_z;
7256 translate_z.Translate3d(0, 0, 10);
7258 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7259 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7260 gfx::PointF(), gfx::Size(800, 800), true, false);
7261 root->SetIsContainerForFixedPositionLayers(true);
7263 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
7264 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
7265 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7266 false);
7267 frame_clip->SetMasksToBounds(true);
7269 scoped_refptr<LayerWithForcedDrawsContent> scroller =
7270 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7271 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
7272 gfx::PointF(), gfx::Size(1000, 1000), true,
7273 false);
7275 scroller->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f, 0.7f));
7276 scroller->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7));
7277 scroller->SetScrollClipLayerId(frame_clip->id());
7279 scoped_refptr<LayerWithForcedDrawsContent> fixed =
7280 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7281 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
7282 gfx::PointF(), gfx::Size(50, 50), true, false);
7284 LayerPositionConstraint constraint;
7285 constraint.set_is_fixed_position(true);
7286 fixed->SetPositionConstraint(constraint);
7288 scoped_refptr<LayerWithForcedDrawsContent> fixed_child =
7289 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7290 SetLayerPropertiesForTesting(fixed_child.get(), identity, gfx::Point3F(),
7291 gfx::PointF(), gfx::Size(10, 10), true, false);
7293 fixed_child->SetPositionConstraint(constraint);
7295 root->AddChild(frame_clip);
7296 frame_clip->AddChild(scroller);
7297 scroller->AddChild(fixed);
7298 fixed->AddChild(fixed_child);
7300 host()->SetRootLayer(root);
7302 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7304 gfx::Rect expected(0, 0, 50, 50);
7305 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
7307 expected = gfx::Rect(0, 0, 10, 10);
7308 EXPECT_EQ(expected, fixed_child->visible_rect_from_property_trees());
7311 TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
7312 gfx::Transform identity;
7314 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7315 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7316 gfx::PointF(), gfx::Size(800, 800), true, false);
7317 root->SetIsContainerForFixedPositionLayers(true);
7319 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
7320 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
7321 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7322 false);
7323 frame_clip->SetMasksToBounds(true);
7325 scoped_refptr<LayerWithForcedDrawsContent> scroller =
7326 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7327 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
7328 gfx::PointF(), gfx::Size(1000, 1000), true,
7329 false);
7331 scroller->SetScrollOffset(gfx::ScrollOffset(100, 100));
7332 scroller->SetScrollClipLayerId(frame_clip->id());
7334 scoped_refptr<LayerWithForcedDrawsContent> fixed =
7335 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7336 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
7337 gfx::PointF(100, 100), gfx::Size(50, 50), true,
7338 false);
7340 LayerPositionConstraint constraint;
7341 constraint.set_is_fixed_position(true);
7342 fixed->SetPositionConstraint(constraint);
7343 fixed->SetForceRenderSurface(true);
7344 fixed->SetMasksToBounds(true);
7346 root->AddChild(frame_clip);
7347 frame_clip->AddChild(scroller);
7348 scroller->AddChild(fixed);
7350 host()->SetRootLayer(root);
7352 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7354 gfx::Rect expected(0, 0, 50, 50);
7355 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
7358 TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
7359 gfx::Transform identity;
7360 gfx::Transform translate;
7361 gfx::Transform rotate;
7363 translate.Translate(10, 10);
7364 rotate.Rotate(45);
7366 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7367 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7368 gfx::PointF(), gfx::Size(800, 800), true, false);
7369 root->SetIsContainerForFixedPositionLayers(true);
7371 host()->SetRootLayer(root);
7373 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7374 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
7376 root->SetTransform(translate);
7377 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
7379 root->SetTransform(rotate);
7380 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
7383 TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
7384 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7385 scoped_refptr<LayerWithForcedDrawsContent> child =
7386 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7387 root->AddChild(child);
7389 host()->SetRootLayer(root);
7391 gfx::Transform identity_matrix;
7392 gfx::Transform scale_matrix;
7393 scale_matrix.Scale(2.f, 2.f);
7394 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
7395 gfx::PointF(), gfx::Size(100, 100), true, false);
7396 SetLayerPropertiesForTesting(child.get(), scale_matrix, gfx::Point3F(),
7397 gfx::PointF(), gfx::Size(10, 10), true, false);
7399 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7400 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
7402 child->SetTransformOrigin(gfx::Point3F(10.f, 10.f, 10.f));
7404 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7405 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_rect_from_property_trees());
7408 TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
7409 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7410 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7411 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7412 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7413 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7415 root->AddChild(scroll_child);
7416 root->AddChild(scroll_parent);
7417 scroll_child->SetScrollParent(scroll_parent.get());
7418 scroll_parent->SetScrollClipLayerId(root->id());
7420 host()->SetRootLayer(root);
7422 gfx::Transform identity_transform;
7423 gfx::Transform scale;
7424 scale.Scale(2.f, 2.f);
7425 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7426 gfx::PointF(), gfx::Size(50, 50), true, false);
7427 SetLayerPropertiesForTesting(scroll_child.get(), scale, gfx::Point3F(),
7428 gfx::PointF(), gfx::Size(40, 40), true, false);
7429 SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform,
7430 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7431 true, false);
7433 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7434 EXPECT_EQ(gfx::Rect(25, 25),
7435 scroll_child->visible_rect_from_property_trees());
7437 scroll_child->SetPosition(gfx::PointF(0, -10.f));
7438 scroll_parent->SetScrollOffset(gfx::ScrollOffset(0.f, 10.f));
7439 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7440 EXPECT_EQ(gfx::Rect(0, 5, 25, 25),
7441 scroll_child->visible_rect_from_property_trees());
7444 static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {
7447 TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
7448 gfx::Transform identity;
7449 FakeContentLayerClient client;
7450 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7451 scoped_refptr<LayerWithForcedDrawsContent> child =
7452 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7453 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
7454 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7455 scoped_refptr<FakePictureLayer> greatgrandchild(
7456 FakePictureLayer::Create(layer_settings(), &client));
7457 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7458 gfx::PointF(), gfx::Size(100, 100), true, false);
7459 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
7460 gfx::PointF(), gfx::Size(10, 10), true, false);
7461 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
7462 gfx::PointF(), gfx::Size(10, 10), true, false);
7463 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
7464 gfx::PointF(), gfx::Size(10, 10), true, false);
7466 root->AddChild(child);
7467 child->AddChild(grandchild);
7468 grandchild->AddChild(greatgrandchild);
7470 host()->SetRootLayer(root);
7472 // Check the non-skipped case.
7473 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7474 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
7476 // Now we will reset the visible rect from property trees for the grandchild,
7477 // and we will configure |child| in several ways that should force the subtree
7478 // to be skipped. The visible content rect for |grandchild| should, therefore,
7479 // remain empty.
7480 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
7481 gfx::Transform singular;
7482 singular.matrix().set(0, 0, 0);
7484 child->SetTransform(singular);
7485 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7486 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
7487 child->SetTransform(identity);
7489 child->SetHideLayerAndSubtree(true);
7490 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7491 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
7492 child->SetHideLayerAndSubtree(false);
7494 gfx::Transform zero_z_scale;
7495 zero_z_scale.Scale3d(1, 1, 0);
7496 child->SetTransform(zero_z_scale);
7498 // Add a transform animation with a start delay. Now, even though |child| has
7499 // a singular transform, the subtree should still get processed.
7500 int animation_id = 0;
7501 scoped_ptr<Animation> animation = Animation::Create(
7502 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(),
7503 animation_id, 1, Animation::TRANSFORM);
7504 animation->set_fill_mode(Animation::FILL_MODE_NONE);
7505 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7506 child->AddAnimation(animation.Pass());
7507 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7508 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
7509 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
7511 child->RemoveAnimation(animation_id);
7512 child->SetTransform(identity);
7513 child->SetOpacity(0.f);
7514 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7515 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
7517 // Now, even though child has zero opacity, we will configure |grandchild| and
7518 // |greatgrandchild| in several ways that should force the subtree to be
7519 // processed anyhow.
7520 greatgrandchild->RequestCopyOfOutput(
7521 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
7522 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7523 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
7524 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
7526 // Add an opacity animation with a start delay.
7527 animation_id = 1;
7528 animation = Animation::Create(
7529 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
7530 animation_id, 1, Animation::OPACITY);
7531 animation->set_fill_mode(Animation::FILL_MODE_NONE);
7532 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7533 child->AddAnimation(animation.Pass());
7534 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7535 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
7538 TEST_F(LayerTreeHostCommonTest, SkippingSubtreeImpl) {
7539 FakeImplProxy proxy;
7540 TestSharedBitmapManager shared_bitmap_manager;
7541 TestTaskGraphRunner task_graph_runner;
7542 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
7543 &task_graph_runner);
7545 gfx::Transform identity;
7546 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7547 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2);
7548 scoped_ptr<LayerImpl> grandchild =
7549 LayerImpl::Create(host_impl.active_tree(), 3);
7551 scoped_ptr<FakePictureLayerImpl> greatgrandchild(
7552 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
7554 child->SetDrawsContent(true);
7555 grandchild->SetDrawsContent(true);
7556 greatgrandchild->SetDrawsContent(true);
7558 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7559 gfx::PointF(), gfx::Size(100, 100), true, false,
7560 true);
7561 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
7562 gfx::PointF(), gfx::Size(10, 10), true, false,
7563 false);
7564 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
7565 gfx::PointF(), gfx::Size(10, 10), true, false,
7566 false);
7567 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
7568 gfx::PointF(), gfx::Size(10, 10), true, false,
7569 true);
7571 LayerImpl* child_ptr = child.get();
7572 LayerImpl* grandchild_ptr = grandchild.get();
7573 LayerImpl* greatgrandchild_ptr = greatgrandchild.get();
7575 grandchild->AddChild(greatgrandchild.Pass());
7576 child->AddChild(grandchild.Pass());
7577 root->AddChild(child.Pass());
7579 // Check the non-skipped case.
7580 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7581 EXPECT_EQ(gfx::Rect(10, 10),
7582 grandchild_ptr->visible_rect_from_property_trees());
7584 // Now we will reset the visible rect from property trees for the grandchild,
7585 // and we will configure |child| in several ways that should force the subtree
7586 // to be skipped. The visible content rect for |grandchild| should, therefore,
7587 // remain empty.
7588 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect());
7589 gfx::Transform singular;
7590 singular.matrix().set(0, 0, 0);
7592 child_ptr->SetTransform(singular);
7593 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7594 EXPECT_EQ(gfx::Rect(0, 0),
7595 grandchild_ptr->visible_rect_from_property_trees());
7596 child_ptr->SetTransform(identity);
7598 child_ptr->SetHideLayerAndSubtree(true);
7599 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7600 EXPECT_EQ(gfx::Rect(0, 0),
7601 grandchild_ptr->visible_rect_from_property_trees());
7602 child_ptr->SetHideLayerAndSubtree(false);
7604 child_ptr->SetOpacity(0.f);
7605 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7606 EXPECT_EQ(gfx::Rect(0, 0),
7607 grandchild_ptr->visible_rect_from_property_trees());
7609 // Now, even though child has zero opacity, we will configure |grandchild| and
7610 // |greatgrandchild| in several ways that should force the subtree to be
7611 // processed anyhow.
7612 ScopedPtrVector<CopyOutputRequest> requests;
7613 requests.push_back(CopyOutputRequest::CreateEmptyRequest());
7615 greatgrandchild_ptr->PassCopyRequests(&requests);
7616 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7617 EXPECT_EQ(gfx::Rect(10, 10),
7618 grandchild_ptr->visible_rect_from_property_trees());
7621 TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
7622 gfx::Transform identity;
7623 FakeContentLayerClient client;
7624 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7625 scoped_refptr<LayerWithForcedDrawsContent> child =
7626 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7627 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7628 gfx::PointF(), gfx::Size(100, 100), true, false);
7629 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
7630 gfx::PointF(), gfx::Size(10, 10), true, false);
7631 root->AddChild(child);
7633 host()->SetRootLayer(root);
7635 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7636 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
7637 child->set_visible_rect_from_property_trees(gfx::Rect());
7639 child->SetHideLayerAndSubtree(true);
7640 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7641 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
7642 child->SetHideLayerAndSubtree(false);
7644 child->SetBounds(gfx::Size());
7645 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7646 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
7647 child->SetBounds(gfx::Size(10, 10));
7649 gfx::Transform rotate;
7650 child->SetDoubleSided(false);
7651 rotate.RotateAboutXAxis(180.f);
7652 child->SetTransform(rotate);
7653 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7654 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
7655 child->SetDoubleSided(true);
7656 child->SetTransform(identity);
7658 child->SetOpacity(0.f);
7659 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7660 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
7663 TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
7664 // Ensure that the treewalk in LayerTreeHostCommom::
7665 // PreCalculateMetaInformation happens when its required.
7666 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7667 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
7668 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7670 root->AddChild(parent);
7671 parent->AddChild(child);
7673 child->SetClipParent(root.get());
7675 gfx::Transform identity;
7677 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7678 gfx::PointF(), gfx::Size(100, 100), true, false);
7679 SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(),
7680 gfx::PointF(), gfx::Size(100, 100), true, false);
7681 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
7682 gfx::PointF(), gfx::Size(100, 100), true, false);
7684 host()->SetRootLayer(root);
7686 ExecuteCalculateDrawProperties(root.get());
7687 EXPECT_EQ(parent->num_unclipped_descendants(), 1u);
7689 child->RequestCopyOfOutput(
7690 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
7691 EXPECT_GT(root->num_layer_or_descendants_with_copy_request(), 0);
7692 ExecuteCalculateDrawProperties(root.get());
7693 EXPECT_GT(root->num_layer_or_descendants_with_copy_request(), 0);
7696 TEST_F(LayerTreeHostCommonTest, InputHandlersRecursiveUpdateTest) {
7697 // Ensure that the treewalk in LayertreeHostCommon::
7698 // PreCalculateMetaInformation updates input handlers correctly.
7699 LayerImpl* root = root_layer();
7700 LayerImpl* child = AddChild<LayerImpl>(root);
7702 gfx::Transform identity;
7704 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
7705 gfx::Size(100, 100), true, false, true);
7706 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
7707 gfx::Size(100, 100), true, false, false);
7709 EXPECT_EQ(root->draw_properties().layer_or_descendant_has_input_handler,
7710 false);
7712 child->SetHaveWheelEventHandlers(true);
7713 ExecuteCalculateDrawProperties(root);
7714 EXPECT_EQ(root->draw_properties().layer_or_descendant_has_input_handler,
7715 true);
7717 child->SetHaveWheelEventHandlers(false);
7718 ExecuteCalculateDrawProperties(root);
7719 EXPECT_EQ(root->draw_properties().layer_or_descendant_has_input_handler,
7720 false);
7723 TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
7724 gfx::Transform identity;
7725 gfx::Transform translate_z;
7726 translate_z.Translate3d(0, 0, 10);
7728 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7729 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7730 gfx::PointF(), gfx::Size(800, 800), true, false);
7732 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7733 SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(),
7734 gfx::PointF(), gfx::Size(100, 100), true, false);
7736 root->AddChild(child);
7738 host()->SetRootLayer(root);
7740 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7741 EXPECT_NE(-1, child->transform_tree_index());
7743 child->RemoveFromParent();
7745 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7746 EXPECT_EQ(-1, child->transform_tree_index());
7749 TEST_F(LayerTreeHostCommonTest, ResetLayerDrawPropertiestest) {
7750 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7751 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7753 root->AddChild(child);
7754 gfx::Transform identity;
7756 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7757 gfx::PointF(), gfx::Size(100, 100), true, false);
7758 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
7759 gfx::PointF(), gfx::Size(100, 100), true, false);
7761 host()->SetRootLayer(root);
7763 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
7764 EXPECT_FALSE(root->visited());
7765 EXPECT_FALSE(root->sorted_for_recursion());
7766 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
7767 EXPECT_FALSE(child->visited());
7768 EXPECT_FALSE(child->sorted_for_recursion());
7770 root->set_layer_or_descendant_is_drawn(true);
7771 root->set_visited(true);
7772 root->set_sorted_for_recursion(true);
7773 child->set_layer_or_descendant_is_drawn(true);
7774 child->set_visited(true);
7775 child->set_sorted_for_recursion(true);
7777 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root.get());
7779 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
7780 EXPECT_FALSE(root->visited());
7781 EXPECT_FALSE(root->sorted_for_recursion());
7782 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
7783 EXPECT_FALSE(child->visited());
7784 EXPECT_FALSE(child->sorted_for_recursion());
7787 TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
7788 // Ensure that a Clip Node is added when a render surface applies clip.
7789 LayerImpl* root = root_layer();
7790 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
7791 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
7792 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
7793 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
7795 const gfx::Transform identity_matrix;
7796 // This transform should be a significant one so that a transform node is
7797 // formed for it.
7798 gfx::Transform transform1;
7799 transform1.RotateAboutYAxis(45);
7800 transform1.RotateAboutXAxis(30);
7801 // This transform should be a 3d transform as we want the render surface
7802 // to flatten the transform
7803 gfx::Transform transform2;
7804 transform2.Translate3d(10, 10, 10);
7806 layer_clips_subtree->SetMasksToBounds(true);
7807 test_layer->SetDrawsContent(true);
7809 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
7810 gfx::PointF(), gfx::Size(30, 30), true, false,
7811 true);
7812 SetLayerPropertiesForTesting(significant_transform, transform1,
7813 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7814 true, false, false);
7815 SetLayerPropertiesForTesting(layer_clips_subtree, identity_matrix,
7816 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7817 true, false, false);
7818 SetLayerPropertiesForTesting(render_surface, transform2, gfx::Point3F(),
7819 gfx::PointF(), gfx::Size(30, 30), true, false,
7820 true);
7821 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
7822 gfx::PointF(), gfx::Size(30, 30), true, false,
7823 false);
7825 ExecuteCalculateDrawProperties(root);
7827 TransformTree transform_tree =
7828 root->layer_tree_impl()->property_trees()->transform_tree;
7829 TransformNode* transform_node =
7830 transform_tree.Node(significant_transform->transform_tree_index());
7831 EXPECT_EQ(transform_node->owner_id, significant_transform->id());
7833 ClipTree clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
7834 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index());
7835 EXPECT_TRUE(clip_node->data.inherit_parent_target_space_clip);
7836 EXPECT_EQ(gfx::Rect(30, 21), test_layer->visible_rect_from_property_trees());
7839 TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
7840 // Ensure that when parent clip node's transform is an ancestor of current
7841 // clip node's target, clip is 'projected' from parent space to current
7842 // target space and visible rects are calculated correctly.
7843 LayerImpl* root = root_layer();
7844 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
7845 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
7846 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
7848 const gfx::Transform identity_matrix;
7849 gfx::Transform transform;
7850 transform.RotateAboutYAxis(45);
7851 clip_layer->SetMasksToBounds(true);
7852 target_layer->SetMasksToBounds(true);
7853 test_layer->SetDrawsContent(true);
7855 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
7856 gfx::PointF(), gfx::Size(30, 30), true, false,
7857 true);
7858 SetLayerPropertiesForTesting(clip_layer, transform, gfx::Point3F(),
7859 gfx::PointF(), gfx::Size(30, 30), true, false,
7860 false);
7861 SetLayerPropertiesForTesting(target_layer, transform, gfx::Point3F(),
7862 gfx::PointF(), gfx::Size(30, 30), true, false,
7863 true);
7864 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
7865 gfx::PointF(), gfx::Size(30, 30), true, false,
7866 false);
7867 ExecuteCalculateDrawProperties(root);
7869 ClipTree clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
7870 ClipNode* clip_node = clip_tree.Node(target_layer->clip_tree_index());
7871 EXPECT_EQ(gfx::RectF(30, 30), clip_node->data.combined_clip);
7872 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_rect_from_property_trees());
7875 TEST_F(LayerTreeHostCommonTest,
7876 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
7877 // Ensure clip rect is calculated correctly when render surface has unclipped
7878 // descendants.
7879 LayerImpl* root = root_layer();
7880 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
7881 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
7882 LayerImpl* render_surface =
7883 AddChild<LayerImpl>(between_clip_parent_and_child);
7884 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
7886 const gfx::Transform identity_matrix;
7887 gfx::Transform transform;
7888 transform.Translate(2.0, 2.0);
7890 test_layer->SetDrawsContent(true);
7891 render_surface->SetClipParent(clip_parent);
7892 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
7893 gfx::PointF(), gfx::Size(30, 30), true, false,
7894 true);
7895 SetLayerPropertiesForTesting(clip_parent, transform, gfx::Point3F(),
7896 gfx::PointF(), gfx::Size(30, 30), true, false,
7897 false);
7898 SetLayerPropertiesForTesting(between_clip_parent_and_child, transform,
7899 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7900 true, false, false);
7901 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
7902 gfx::PointF(), gfx::Size(30, 30), true, false,
7903 true);
7904 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
7905 gfx::PointF(), gfx::Size(30, 30), true, false,
7906 false);
7908 ExecuteCalculateDrawProperties(root);
7910 EXPECT_EQ(gfx::Rect(-4, -4, 30, 30), test_layer->clip_rect());
7913 } // namespace
7914 } // namespace cc