| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "cc/trees/layer_tree_host_common.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 #include <set> | |
| 9 | |
| 10 #include "cc/animation/layer_animation_controller.h" | |
| 11 #include "cc/animation/transform_operations.h" | |
| 12 #include "cc/base/math_util.h" | |
| 13 #include "cc/layers/content_layer.h" | |
| 14 #include "cc/layers/content_layer_client.h" | |
| 15 #include "cc/layers/layer.h" | |
| 16 #include "cc/layers/layer_client.h" | |
| 17 #include "cc/layers/layer_impl.h" | |
| 18 #include "cc/layers/layer_iterator.h" | |
| 19 #include "cc/layers/render_surface.h" | |
| 20 #include "cc/layers/render_surface_impl.h" | |
| 21 #include "cc/output/copy_output_request.h" | |
| 22 #include "cc/output/copy_output_result.h" | |
| 23 #include "cc/test/animation_test_common.h" | |
| 24 #include "cc/test/fake_impl_proxy.h" | |
| 25 #include "cc/test/fake_layer_tree_host.h" | |
| 26 #include "cc/test/fake_layer_tree_host_impl.h" | |
| 27 #include "cc/test/fake_picture_layer.h" | |
| 28 #include "cc/test/fake_picture_layer_impl.h" | |
| 29 #include "cc/test/geometry_test_utils.h" | |
| 30 #include "cc/test/layer_tree_host_common_test.h" | |
| 31 #include "cc/test/test_task_graph_runner.h" | |
| 32 #include "cc/trees/layer_tree_impl.h" | |
| 33 #include "cc/trees/proxy.h" | |
| 34 #include "cc/trees/single_thread_proxy.h" | |
| 35 #include "testing/gmock/include/gmock/gmock.h" | |
| 36 #include "testing/gtest/include/gtest/gtest.h" | |
| 37 #include "ui/gfx/geometry/quad_f.h" | |
| 38 #include "ui/gfx/geometry/vector2d_conversions.h" | |
| 39 #include "ui/gfx/transform.h" | |
| 40 | |
| 41 namespace cc { | |
| 42 namespace { | |
| 43 | |
| 44 class LayerWithForcedDrawsContent : public Layer { | |
| 45 public: | |
| 46 LayerWithForcedDrawsContent() {} | |
| 47 | |
| 48 bool DrawsContent() const override; | |
| 49 | |
| 50 private: | |
| 51 ~LayerWithForcedDrawsContent() override {} | |
| 52 }; | |
| 53 | |
| 54 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } | |
| 55 | |
| 56 class MockContentLayerClient : public ContentLayerClient { | |
| 57 public: | |
| 58 MockContentLayerClient() {} | |
| 59 ~MockContentLayerClient() override {} | |
| 60 void PaintContents(SkCanvas* canvas, | |
| 61 const gfx::Rect& clip, | |
| 62 PaintingControlSetting picture_control) override {} | |
| 63 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | |
| 64 const gfx::Rect& clip, | |
| 65 PaintingControlSetting picture_control) override { | |
| 66 NOTIMPLEMENTED(); | |
| 67 return DisplayItemList::Create(); | |
| 68 } | |
| 69 bool FillsBoundsCompletely() const override { return false; } | |
| 70 }; | |
| 71 | |
| 72 scoped_refptr<FakePictureLayer> CreateDrawablePictureLayer( | |
| 73 ContentLayerClient* delegate) { | |
| 74 scoped_refptr<FakePictureLayer> to_return = | |
| 75 FakePictureLayer::Create(delegate); | |
| 76 to_return->SetIsDrawable(true); | |
| 77 return to_return; | |
| 78 } | |
| 79 | |
| 80 scoped_refptr<ContentLayer> CreateDrawableContentLayer( | |
| 81 ContentLayerClient* delegate) { | |
| 82 scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate); | |
| 83 to_return->SetIsDrawable(true); | |
| 84 return to_return; | |
| 85 } | |
| 86 | |
| 87 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ | |
| 88 do { \ | |
| 89 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ | |
| 90 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ | |
| 91 } while (false) | |
| 92 | |
| 93 #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \ | |
| 94 do { \ | |
| 95 EXPECT_FLOAT_EQ(expected, layer->draw_properties().ideal_contents_scale); \ | |
| 96 } while (false) | |
| 97 | |
| 98 TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { | |
| 99 // Sanity check: For layers positioned at zero, with zero size, | |
| 100 // and with identity transforms, then the draw transform, | |
| 101 // screen space transform, and the hierarchy passed on to children | |
| 102 // layers should also be identity transforms. | |
| 103 | |
| 104 scoped_refptr<Layer> parent = Layer::Create(); | |
| 105 scoped_refptr<Layer> child = Layer::Create(); | |
| 106 scoped_refptr<Layer> grand_child = Layer::Create(); | |
| 107 parent->AddChild(child); | |
| 108 child->AddChild(grand_child); | |
| 109 | |
| 110 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 111 host->SetRootLayer(parent); | |
| 112 | |
| 113 gfx::Transform identity_matrix; | |
| 114 SetLayerPropertiesForTesting(parent.get(), | |
| 115 identity_matrix, | |
| 116 gfx::Point3F(), | |
| 117 gfx::PointF(), | |
| 118 gfx::Size(100, 100), | |
| 119 true, | |
| 120 false); | |
| 121 SetLayerPropertiesForTesting(child.get(), | |
| 122 identity_matrix, | |
| 123 gfx::Point3F(), | |
| 124 gfx::PointF(), | |
| 125 gfx::Size(), | |
| 126 true, | |
| 127 false); | |
| 128 SetLayerPropertiesForTesting(grand_child.get(), | |
| 129 identity_matrix, | |
| 130 gfx::Point3F(), | |
| 131 gfx::PointF(), | |
| 132 gfx::Size(), | |
| 133 true, | |
| 134 false); | |
| 135 | |
| 136 ExecuteCalculateDrawProperties(parent.get()); | |
| 137 | |
| 138 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); | |
| 139 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, | |
| 140 child->screen_space_transform()); | |
| 141 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, | |
| 142 grand_child->draw_transform()); | |
| 143 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, | |
| 144 grand_child->screen_space_transform()); | |
| 145 } | |
| 146 | |
| 147 TEST_F(LayerTreeHostCommonTest, DoNotSkipLayersWithHandlers) { | |
| 148 scoped_refptr<Layer> parent = Layer::Create(); | |
| 149 scoped_refptr<Layer> child = Layer::Create(); | |
| 150 scoped_refptr<Layer> grand_child = Layer::Create(); | |
| 151 parent->AddChild(child); | |
| 152 child->AddChild(grand_child); | |
| 153 | |
| 154 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 155 host->SetRootLayer(parent); | |
| 156 | |
| 157 gfx::Transform identity_matrix; | |
| 158 SetLayerPropertiesForTesting(parent.get(), | |
| 159 identity_matrix, | |
| 160 gfx::Point3F(), | |
| 161 gfx::PointF(), | |
| 162 gfx::Size(100, 100), | |
| 163 true, | |
| 164 false); | |
| 165 SetLayerPropertiesForTesting(child.get(), | |
| 166 identity_matrix, | |
| 167 gfx::Point3F(), | |
| 168 gfx::PointF(10, 10), | |
| 169 gfx::Size(100, 100), | |
| 170 true, | |
| 171 false); | |
| 172 // This would have previously caused us to skip our subtree, but this would be | |
| 173 // wrong; we need up-to-date draw properties to do hit testing on the layers | |
| 174 // with handlers. | |
| 175 child->SetOpacity(0.f); | |
| 176 SetLayerPropertiesForTesting(grand_child.get(), | |
| 177 identity_matrix, | |
| 178 gfx::Point3F(), | |
| 179 gfx::PointF(10, 10), | |
| 180 gfx::Size(100, 100), | |
| 181 true, | |
| 182 false); | |
| 183 grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); | |
| 184 | |
| 185 ExecuteCalculateDrawProperties(parent.get()); | |
| 186 | |
| 187 // Check that we've computed draw properties for the subtree rooted at | |
| 188 // |child|. | |
| 189 EXPECT_FALSE(child->draw_transform().IsIdentity()); | |
| 190 EXPECT_FALSE(grand_child->draw_transform().IsIdentity()); | |
| 191 } | |
| 192 | |
| 193 TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { | |
| 194 gfx::Transform identity_matrix; | |
| 195 scoped_refptr<Layer> layer = Layer::Create(); | |
| 196 | |
| 197 scoped_refptr<Layer> root = Layer::Create(); | |
| 198 SetLayerPropertiesForTesting(root.get(), | |
| 199 identity_matrix, | |
| 200 gfx::Point3F(), | |
| 201 gfx::PointF(), | |
| 202 gfx::Size(1, 2), | |
| 203 true, | |
| 204 false); | |
| 205 root->AddChild(layer); | |
| 206 | |
| 207 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 208 host->SetRootLayer(root); | |
| 209 | |
| 210 // Case 2: Setting the bounds of the layer should not affect either the draw | |
| 211 // transform or the screenspace transform. | |
| 212 gfx::Transform translation_to_center; | |
| 213 translation_to_center.Translate(5.0, 6.0); | |
| 214 SetLayerPropertiesForTesting(layer.get(), | |
| 215 identity_matrix, | |
| 216 gfx::Point3F(), | |
| 217 gfx::PointF(), | |
| 218 gfx::Size(10, 12), | |
| 219 true, | |
| 220 false); | |
| 221 ExecuteCalculateDrawProperties(root.get()); | |
| 222 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); | |
| 223 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, | |
| 224 layer->screen_space_transform()); | |
| 225 | |
| 226 // Case 3: The anchor point by itself (without a layer transform) should have | |
| 227 // no effect on the transforms. | |
| 228 SetLayerPropertiesForTesting(layer.get(), | |
| 229 identity_matrix, | |
| 230 gfx::Point3F(2.5f, 3.0f, 0.f), | |
| 231 gfx::PointF(), | |
| 232 gfx::Size(10, 12), | |
| 233 true, | |
| 234 false); | |
| 235 ExecuteCalculateDrawProperties(root.get()); | |
| 236 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); | |
| 237 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, | |
| 238 layer->screen_space_transform()); | |
| 239 | |
| 240 // Case 4: A change in actual position affects both the draw transform and | |
| 241 // screen space transform. | |
| 242 gfx::Transform position_transform; | |
| 243 position_transform.Translate(0.f, 1.2f); | |
| 244 SetLayerPropertiesForTesting(layer.get(), | |
| 245 identity_matrix, | |
| 246 gfx::Point3F(2.5f, 3.0f, 0.f), | |
| 247 gfx::PointF(0.f, 1.2f), | |
| 248 gfx::Size(10, 12), | |
| 249 true, | |
| 250 false); | |
| 251 ExecuteCalculateDrawProperties(root.get()); | |
| 252 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform()); | |
| 253 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, | |
| 254 layer->screen_space_transform()); | |
| 255 | |
| 256 // Case 5: In the correct sequence of transforms, the layer transform should | |
| 257 // pre-multiply the translation_to_center. This is easily tested by using a | |
| 258 // scale transform, because scale and translation are not commutative. | |
| 259 gfx::Transform layer_transform; | |
| 260 layer_transform.Scale3d(2.0, 2.0, 1.0); | |
| 261 SetLayerPropertiesForTesting(layer.get(), | |
| 262 layer_transform, | |
| 263 gfx::Point3F(), | |
| 264 gfx::PointF(), | |
| 265 gfx::Size(10, 12), | |
| 266 true, | |
| 267 false); | |
| 268 ExecuteCalculateDrawProperties(root.get()); | |
| 269 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform()); | |
| 270 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, | |
| 271 layer->screen_space_transform()); | |
| 272 | |
| 273 // Case 6: The layer transform should occur with respect to the anchor point. | |
| 274 gfx::Transform translation_to_anchor; | |
| 275 translation_to_anchor.Translate(5.0, 0.0); | |
| 276 gfx::Transform expected_result = | |
| 277 translation_to_anchor * layer_transform * Inverse(translation_to_anchor); | |
| 278 SetLayerPropertiesForTesting(layer.get(), | |
| 279 layer_transform, | |
| 280 gfx::Point3F(5.0f, 0.f, 0.f), | |
| 281 gfx::PointF(), | |
| 282 gfx::Size(10, 12), | |
| 283 true, | |
| 284 false); | |
| 285 ExecuteCalculateDrawProperties(root.get()); | |
| 286 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); | |
| 287 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, | |
| 288 layer->screen_space_transform()); | |
| 289 | |
| 290 // Case 7: Verify that position pre-multiplies the layer transform. The | |
| 291 // current implementation of CalculateDrawProperties does this implicitly, but | |
| 292 // it is still worth testing to detect accidental regressions. | |
| 293 expected_result = position_transform * translation_to_anchor * | |
| 294 layer_transform * Inverse(translation_to_anchor); | |
| 295 SetLayerPropertiesForTesting(layer.get(), | |
| 296 layer_transform, | |
| 297 gfx::Point3F(5.0f, 0.f, 0.f), | |
| 298 gfx::PointF(0.f, 1.2f), | |
| 299 gfx::Size(10, 12), | |
| 300 true, | |
| 301 false); | |
| 302 ExecuteCalculateDrawProperties(root.get()); | |
| 303 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); | |
| 304 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, | |
| 305 layer->screen_space_transform()); | |
| 306 } | |
| 307 | |
| 308 TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { | |
| 309 const gfx::ScrollOffset kScrollOffset(50, 100); | |
| 310 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); | |
| 311 const gfx::Vector2d kMaxScrollOffset(200, 200); | |
| 312 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), | |
| 313 -kScrollOffset.y()); | |
| 314 const float kPageScale = 0.888f; | |
| 315 const float kDeviceScale = 1.666f; | |
| 316 | |
| 317 FakeImplProxy proxy; | |
| 318 TestSharedBitmapManager shared_bitmap_manager; | |
| 319 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 320 | |
| 321 gfx::Transform identity_matrix; | |
| 322 scoped_ptr<LayerImpl> sublayer_scoped_ptr( | |
| 323 LayerImpl::Create(host_impl.active_tree(), 1)); | |
| 324 LayerImpl* sublayer = sublayer_scoped_ptr.get(); | |
| 325 sublayer->SetContentsScale(kPageScale * kDeviceScale, | |
| 326 kPageScale * kDeviceScale); | |
| 327 SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(), | |
| 328 gfx::PointF(), gfx::Size(500, 500), true, false, | |
| 329 false); | |
| 330 | |
| 331 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr( | |
| 332 LayerImpl::Create(host_impl.active_tree(), 2)); | |
| 333 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); | |
| 334 SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(), | |
| 335 gfx::PointF(), gfx::Size(10, 20), true, false, | |
| 336 false); | |
| 337 scoped_ptr<LayerImpl> clip_layer_scoped_ptr( | |
| 338 LayerImpl::Create(host_impl.active_tree(), 4)); | |
| 339 LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); | |
| 340 | |
| 341 scroll_layer->SetScrollClipLayer(clip_layer->id()); | |
| 342 clip_layer->SetBounds( | |
| 343 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), | |
| 344 scroll_layer->bounds().height() + kMaxScrollOffset.y())); | |
| 345 scroll_layer->SetScrollClipLayer(clip_layer->id()); | |
| 346 scroll_layer->SetScrollDelta(kScrollDelta); | |
| 347 gfx::Transform impl_transform; | |
| 348 scroll_layer->AddChild(sublayer_scoped_ptr.Pass()); | |
| 349 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); | |
| 350 clip_layer->AddChild(scroll_layer_scoped_ptr.Pass()); | |
| 351 scroll_layer_raw_ptr->PushScrollOffsetFromMainThread(kScrollOffset); | |
| 352 | |
| 353 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3)); | |
| 354 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), | |
| 355 gfx::PointF(), gfx::Size(3, 4), true, false, | |
| 356 false); | |
| 357 root->AddChild(clip_layer_scoped_ptr.Pass()); | |
| 358 root->SetHasRenderSurface(true); | |
| 359 | |
| 360 ExecuteCalculateDrawProperties( | |
| 361 root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); | |
| 362 gfx::Transform expected_transform = identity_matrix; | |
| 363 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; | |
| 364 sub_layer_screen_position.Scale(kPageScale * kDeviceScale); | |
| 365 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()), | |
| 366 MathUtil::Round(sub_layer_screen_position.y())); | |
| 367 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, | |
| 368 sublayer->draw_transform()); | |
| 369 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, | |
| 370 sublayer->screen_space_transform()); | |
| 371 | |
| 372 gfx::Transform arbitrary_translate; | |
| 373 const float kTranslateX = 10.6f; | |
| 374 const float kTranslateY = 20.6f; | |
| 375 arbitrary_translate.Translate(kTranslateX, kTranslateY); | |
| 376 SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate, | |
| 377 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20), | |
| 378 true, false, false); | |
| 379 ExecuteCalculateDrawProperties( | |
| 380 root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); | |
| 381 expected_transform.MakeIdentity(); | |
| 382 expected_transform.Translate( | |
| 383 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale + | |
| 384 sub_layer_screen_position.x()), | |
| 385 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale + | |
| 386 sub_layer_screen_position.y())); | |
| 387 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, | |
| 388 sublayer->draw_transform()); | |
| 389 } | |
| 390 | |
| 391 TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { | |
| 392 gfx::Transform identity_matrix; | |
| 393 scoped_refptr<Layer> root = Layer::Create(); | |
| 394 scoped_refptr<Layer> parent = Layer::Create(); | |
| 395 scoped_refptr<Layer> child = Layer::Create(); | |
| 396 scoped_refptr<Layer> grand_child = Layer::Create(); | |
| 397 root->AddChild(parent); | |
| 398 parent->AddChild(child); | |
| 399 child->AddChild(grand_child); | |
| 400 | |
| 401 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 402 host->SetRootLayer(root); | |
| 403 | |
| 404 // One-time setup of root layer | |
| 405 SetLayerPropertiesForTesting(root.get(), | |
| 406 identity_matrix, | |
| 407 gfx::Point3F(), | |
| 408 gfx::PointF(), | |
| 409 gfx::Size(1, 2), | |
| 410 true, | |
| 411 false); | |
| 412 | |
| 413 // Case 1: parent's anchor point should not affect child or grand_child. | |
| 414 SetLayerPropertiesForTesting(parent.get(), | |
| 415 identity_matrix, | |
| 416 gfx::Point3F(2.5f, 3.0f, 0.f), | |
| 417 gfx::PointF(), | |
| 418 gfx::Size(10, 12), | |
| 419 true, | |
| 420 false); | |
| 421 SetLayerPropertiesForTesting(child.get(), | |
| 422 identity_matrix, | |
| 423 gfx::Point3F(), | |
| 424 gfx::PointF(), | |
| 425 gfx::Size(16, 18), | |
| 426 true, | |
| 427 false); | |
| 428 SetLayerPropertiesForTesting(grand_child.get(), | |
| 429 identity_matrix, | |
| 430 gfx::Point3F(), | |
| 431 gfx::PointF(), | |
| 432 gfx::Size(76, 78), | |
| 433 true, | |
| 434 false); | |
| 435 ExecuteCalculateDrawProperties(root.get()); | |
| 436 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); | |
| 437 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, | |
| 438 child->screen_space_transform()); | |
| 439 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, | |
| 440 grand_child->draw_transform()); | |
| 441 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, | |
| 442 grand_child->screen_space_transform()); | |
| 443 | |
| 444 // Case 2: parent's position affects child and grand_child. | |
| 445 gfx::Transform parent_position_transform; | |
| 446 parent_position_transform.Translate(0.f, 1.2f); | |
| 447 SetLayerPropertiesForTesting(parent.get(), | |
| 448 identity_matrix, | |
| 449 gfx::Point3F(2.5f, 3.0f, 0.f), | |
| 450 gfx::PointF(0.f, 1.2f), | |
| 451 gfx::Size(10, 12), | |
| 452 true, | |
| 453 false); | |
| 454 SetLayerPropertiesForTesting(child.get(), | |
| 455 identity_matrix, | |
| 456 gfx::Point3F(), | |
| 457 gfx::PointF(), | |
| 458 gfx::Size(16, 18), | |
| 459 true, | |
| 460 false); | |
| 461 SetLayerPropertiesForTesting(grand_child.get(), | |
| 462 identity_matrix, | |
| 463 gfx::Point3F(), | |
| 464 gfx::PointF(), | |
| 465 gfx::Size(76, 78), | |
| 466 true, | |
| 467 false); | |
| 468 ExecuteCalculateDrawProperties(root.get()); | |
| 469 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, | |
| 470 child->draw_transform()); | |
| 471 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, | |
| 472 child->screen_space_transform()); | |
| 473 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, | |
| 474 grand_child->draw_transform()); | |
| 475 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, | |
| 476 grand_child->screen_space_transform()); | |
| 477 | |
| 478 // Case 3: parent's local transform affects child and grandchild | |
| 479 gfx::Transform parent_layer_transform; | |
| 480 parent_layer_transform.Scale3d(2.0, 2.0, 1.0); | |
| 481 gfx::Transform parent_translation_to_anchor; | |
| 482 parent_translation_to_anchor.Translate(2.5, 3.0); | |
| 483 gfx::Transform parent_composite_transform = | |
| 484 parent_translation_to_anchor * parent_layer_transform * | |
| 485 Inverse(parent_translation_to_anchor); | |
| 486 SetLayerPropertiesForTesting(parent.get(), | |
| 487 parent_layer_transform, | |
| 488 gfx::Point3F(2.5f, 3.0f, 0.f), | |
| 489 gfx::PointF(), | |
| 490 gfx::Size(10, 12), | |
| 491 true, | |
| 492 false); | |
| 493 SetLayerPropertiesForTesting(child.get(), | |
| 494 identity_matrix, | |
| 495 gfx::Point3F(), | |
| 496 gfx::PointF(), | |
| 497 gfx::Size(16, 18), | |
| 498 true, | |
| 499 false); | |
| 500 SetLayerPropertiesForTesting(grand_child.get(), | |
| 501 identity_matrix, | |
| 502 gfx::Point3F(), | |
| 503 gfx::PointF(), | |
| 504 gfx::Size(76, 78), | |
| 505 true, | |
| 506 false); | |
| 507 ExecuteCalculateDrawProperties(root.get()); | |
| 508 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, | |
| 509 child->draw_transform()); | |
| 510 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, | |
| 511 child->screen_space_transform()); | |
| 512 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, | |
| 513 grand_child->draw_transform()); | |
| 514 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, | |
| 515 grand_child->screen_space_transform()); | |
| 516 } | |
| 517 | |
| 518 TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { | |
| 519 scoped_refptr<Layer> root = Layer::Create(); | |
| 520 scoped_refptr<Layer> parent = Layer::Create(); | |
| 521 scoped_refptr<Layer> child = Layer::Create(); | |
| 522 scoped_refptr<LayerWithForcedDrawsContent> grand_child = | |
| 523 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 524 root->AddChild(parent); | |
| 525 parent->AddChild(child); | |
| 526 child->AddChild(grand_child); | |
| 527 | |
| 528 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 529 host->SetRootLayer(root); | |
| 530 | |
| 531 // One-time setup of root layer | |
| 532 gfx::Transform identity_matrix; | |
| 533 SetLayerPropertiesForTesting(root.get(), | |
| 534 identity_matrix, | |
| 535 gfx::Point3F(), | |
| 536 gfx::PointF(), | |
| 537 gfx::Size(1, 2), | |
| 538 true, | |
| 539 false); | |
| 540 | |
| 541 // Child is set up so that a new render surface should be created. | |
| 542 child->SetOpacity(0.5f); | |
| 543 child->SetForceRenderSurface(true); | |
| 544 | |
| 545 gfx::Transform parent_layer_transform; | |
| 546 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); | |
| 547 gfx::Transform parent_translation_to_anchor; | |
| 548 parent_translation_to_anchor.Translate(25.0, 30.0); | |
| 549 | |
| 550 gfx::Transform parent_composite_transform = | |
| 551 parent_translation_to_anchor * parent_layer_transform * | |
| 552 Inverse(parent_translation_to_anchor); | |
| 553 gfx::Vector2dF parent_composite_scale = | |
| 554 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, | |
| 555 1.f); | |
| 556 gfx::Transform surface_sublayer_transform; | |
| 557 surface_sublayer_transform.Scale(parent_composite_scale.x(), | |
| 558 parent_composite_scale.y()); | |
| 559 gfx::Transform surface_sublayer_composite_transform = | |
| 560 parent_composite_transform * Inverse(surface_sublayer_transform); | |
| 561 | |
| 562 // Child's render surface should not exist yet. | |
| 563 ASSERT_FALSE(child->render_surface()); | |
| 564 | |
| 565 SetLayerPropertiesForTesting(parent.get(), | |
| 566 parent_layer_transform, | |
| 567 gfx::Point3F(25.0f, 30.0f, 0.f), | |
| 568 gfx::PointF(), | |
| 569 gfx::Size(100, 120), | |
| 570 true, | |
| 571 false); | |
| 572 SetLayerPropertiesForTesting(child.get(), | |
| 573 identity_matrix, | |
| 574 gfx::Point3F(), | |
| 575 gfx::PointF(), | |
| 576 gfx::Size(16, 18), | |
| 577 true, | |
| 578 false); | |
| 579 SetLayerPropertiesForTesting(grand_child.get(), | |
| 580 identity_matrix, | |
| 581 gfx::Point3F(), | |
| 582 gfx::PointF(), | |
| 583 gfx::Size(8, 10), | |
| 584 true, | |
| 585 false); | |
| 586 ExecuteCalculateDrawProperties(root.get()); | |
| 587 | |
| 588 // Render surface should have been created now. | |
| 589 ASSERT_TRUE(child->render_surface()); | |
| 590 ASSERT_EQ(child.get(), child->render_target()); | |
| 591 | |
| 592 // The child layer's draw transform should refer to its new render surface. | |
| 593 // The screen-space transform, however, should still refer to the root. | |
| 594 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, | |
| 595 child->draw_transform()); | |
| 596 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, | |
| 597 child->screen_space_transform()); | |
| 598 | |
| 599 // Because the grand_child is the only drawable content, the child's render | |
| 600 // surface will tighten its bounds to the grand_child. The scale at which the | |
| 601 // surface's subtree is drawn must be removed from the composite transform. | |
| 602 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 603 surface_sublayer_composite_transform, | |
| 604 child->render_target()->render_surface()->draw_transform()); | |
| 605 | |
| 606 // The screen space is the same as the target since the child surface draws | |
| 607 // into the root. | |
| 608 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 609 surface_sublayer_composite_transform, | |
| 610 child->render_target()->render_surface()->screen_space_transform()); | |
| 611 } | |
| 612 | |
| 613 TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { | |
| 614 scoped_refptr<Layer> root = Layer::Create(); | |
| 615 scoped_refptr<Layer> parent = Layer::Create(); | |
| 616 scoped_refptr<Layer> child = Layer::Create(); | |
| 617 scoped_refptr<Layer> child_replica = Layer::Create(); | |
| 618 scoped_refptr<LayerWithForcedDrawsContent> grand_child = | |
| 619 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 620 root->AddChild(parent); | |
| 621 parent->AddChild(child); | |
| 622 child->AddChild(grand_child); | |
| 623 child->SetReplicaLayer(child_replica.get()); | |
| 624 | |
| 625 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 626 host->SetRootLayer(root); | |
| 627 | |
| 628 // One-time setup of root layer | |
| 629 gfx::Transform identity_matrix; | |
| 630 SetLayerPropertiesForTesting(root.get(), | |
| 631 identity_matrix, | |
| 632 gfx::Point3F(), | |
| 633 gfx::PointF(), | |
| 634 gfx::Size(1, 2), | |
| 635 true, | |
| 636 false); | |
| 637 | |
| 638 // Child is set up so that a new render surface should be created. | |
| 639 child->SetOpacity(0.5f); | |
| 640 | |
| 641 gfx::Transform parent_layer_transform; | |
| 642 parent_layer_transform.Scale3d(2.0, 2.0, 1.0); | |
| 643 gfx::Transform parent_translation_to_anchor; | |
| 644 parent_translation_to_anchor.Translate(2.5, 3.0); | |
| 645 gfx::Transform parent_composite_transform = | |
| 646 parent_translation_to_anchor * parent_layer_transform * | |
| 647 Inverse(parent_translation_to_anchor); | |
| 648 gfx::Transform replica_layer_transform; | |
| 649 replica_layer_transform.Scale3d(3.0, 3.0, 1.0); | |
| 650 gfx::Vector2dF parent_composite_scale = | |
| 651 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, | |
| 652 1.f); | |
| 653 gfx::Transform surface_sublayer_transform; | |
| 654 surface_sublayer_transform.Scale(parent_composite_scale.x(), | |
| 655 parent_composite_scale.y()); | |
| 656 gfx::Transform replica_composite_transform = | |
| 657 parent_composite_transform * replica_layer_transform * | |
| 658 Inverse(surface_sublayer_transform); | |
| 659 child_replica->SetIsDrawable(true); | |
| 660 // Child's render surface should not exist yet. | |
| 661 ASSERT_FALSE(child->render_surface()); | |
| 662 | |
| 663 SetLayerPropertiesForTesting(parent.get(), | |
| 664 parent_layer_transform, | |
| 665 gfx::Point3F(2.5f, 3.0f, 0.f), | |
| 666 gfx::PointF(), | |
| 667 gfx::Size(10, 12), | |
| 668 true, | |
| 669 false); | |
| 670 SetLayerPropertiesForTesting(child.get(), | |
| 671 identity_matrix, | |
| 672 gfx::Point3F(), | |
| 673 gfx::PointF(), | |
| 674 gfx::Size(16, 18), | |
| 675 true, | |
| 676 false); | |
| 677 SetLayerPropertiesForTesting(grand_child.get(), | |
| 678 identity_matrix, | |
| 679 gfx::Point3F(), | |
| 680 gfx::PointF(-0.5f, -0.5f), | |
| 681 gfx::Size(1, 1), | |
| 682 true, | |
| 683 false); | |
| 684 SetLayerPropertiesForTesting(child_replica.get(), | |
| 685 replica_layer_transform, | |
| 686 gfx::Point3F(), | |
| 687 gfx::PointF(), | |
| 688 gfx::Size(), | |
| 689 true, | |
| 690 false); | |
| 691 ExecuteCalculateDrawProperties(root.get()); | |
| 692 | |
| 693 // Render surface should have been created now. | |
| 694 ASSERT_TRUE(child->render_surface()); | |
| 695 ASSERT_EQ(child.get(), child->render_target()); | |
| 696 | |
| 697 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 698 replica_composite_transform, | |
| 699 child->render_target()->render_surface()->replica_draw_transform()); | |
| 700 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, | |
| 701 child->render_target() | |
| 702 ->render_surface() | |
| 703 ->replica_screen_space_transform()); | |
| 704 } | |
| 705 | |
| 706 TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { | |
| 707 // This test creates a more complex tree and verifies it all at once. This | |
| 708 // covers the following cases: | |
| 709 // - layers that are described w.r.t. a render surface: should have draw | |
| 710 // transforms described w.r.t. that surface | |
| 711 // - A render surface described w.r.t. an ancestor render surface: should | |
| 712 // have a draw transform described w.r.t. that ancestor surface | |
| 713 // - Replicas of a render surface are described w.r.t. the replica's | |
| 714 // transform around its anchor, along with the surface itself. | |
| 715 // - Sanity check on recursion: verify transforms of layers described w.r.t. | |
| 716 // a render surface that is described w.r.t. an ancestor render surface. | |
| 717 // - verifying that each layer has a reference to the correct render surface | |
| 718 // and render target values. | |
| 719 | |
| 720 scoped_refptr<Layer> root = Layer::Create(); | |
| 721 scoped_refptr<Layer> parent = Layer::Create(); | |
| 722 scoped_refptr<Layer> render_surface1 = Layer::Create(); | |
| 723 scoped_refptr<Layer> render_surface2 = Layer::Create(); | |
| 724 scoped_refptr<Layer> child_of_root = Layer::Create(); | |
| 725 scoped_refptr<Layer> child_of_rs1 = Layer::Create(); | |
| 726 scoped_refptr<Layer> child_of_rs2 = Layer::Create(); | |
| 727 scoped_refptr<Layer> replica_of_rs1 = Layer::Create(); | |
| 728 scoped_refptr<Layer> replica_of_rs2 = Layer::Create(); | |
| 729 scoped_refptr<Layer> grand_child_of_root = Layer::Create(); | |
| 730 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = | |
| 731 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 732 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = | |
| 733 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 734 root->AddChild(parent); | |
| 735 parent->AddChild(render_surface1); | |
| 736 parent->AddChild(child_of_root); | |
| 737 render_surface1->AddChild(child_of_rs1); | |
| 738 render_surface1->AddChild(render_surface2); | |
| 739 render_surface2->AddChild(child_of_rs2); | |
| 740 child_of_root->AddChild(grand_child_of_root); | |
| 741 child_of_rs1->AddChild(grand_child_of_rs1); | |
| 742 child_of_rs2->AddChild(grand_child_of_rs2); | |
| 743 render_surface1->SetReplicaLayer(replica_of_rs1.get()); | |
| 744 render_surface2->SetReplicaLayer(replica_of_rs2.get()); | |
| 745 | |
| 746 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 747 host->SetRootLayer(root); | |
| 748 | |
| 749 // In combination with descendant draws content, opacity != 1 forces the layer | |
| 750 // to have a new render surface. | |
| 751 render_surface1->SetOpacity(0.5f); | |
| 752 render_surface2->SetOpacity(0.33f); | |
| 753 | |
| 754 // One-time setup of root layer | |
| 755 gfx::Transform identity_matrix; | |
| 756 SetLayerPropertiesForTesting(root.get(), | |
| 757 identity_matrix, | |
| 758 gfx::Point3F(), | |
| 759 gfx::PointF(), | |
| 760 gfx::Size(1, 2), | |
| 761 true, | |
| 762 false); | |
| 763 | |
| 764 // All layers in the tree are initialized with an anchor at .25 and a size of | |
| 765 // (10,10). matrix "A" is the composite layer transform used in all layers, | |
| 766 // Matrix "R" is the composite replica transform used in all replica layers. | |
| 767 gfx::Transform translation_to_anchor; | |
| 768 translation_to_anchor.Translate(2.5, 0.0); | |
| 769 gfx::Transform layer_transform; | |
| 770 layer_transform.Translate(1.0, 1.0); | |
| 771 gfx::Transform replica_layer_transform; | |
| 772 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); | |
| 773 | |
| 774 gfx::Transform A = | |
| 775 translation_to_anchor * layer_transform * Inverse(translation_to_anchor); | |
| 776 gfx::Transform R = A * translation_to_anchor * replica_layer_transform * | |
| 777 Inverse(translation_to_anchor); | |
| 778 | |
| 779 gfx::Vector2dF surface1_parent_transform_scale = | |
| 780 MathUtil::ComputeTransform2dScaleComponents(A, 1.f); | |
| 781 gfx::Transform surface1_sublayer_transform; | |
| 782 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), | |
| 783 surface1_parent_transform_scale.y()); | |
| 784 | |
| 785 // SS1 = transform given to the subtree of render_surface1 | |
| 786 gfx::Transform SS1 = surface1_sublayer_transform; | |
| 787 // S1 = transform to move from render_surface1 pixels to the layer space of | |
| 788 // the owning layer | |
| 789 gfx::Transform S1 = Inverse(surface1_sublayer_transform); | |
| 790 | |
| 791 gfx::Vector2dF surface2_parent_transform_scale = | |
| 792 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); | |
| 793 gfx::Transform surface2_sublayer_transform; | |
| 794 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), | |
| 795 surface2_parent_transform_scale.y()); | |
| 796 | |
| 797 // SS2 = transform given to the subtree of render_surface2 | |
| 798 gfx::Transform SS2 = surface2_sublayer_transform; | |
| 799 // S2 = transform to move from render_surface2 pixels to the layer space of | |
| 800 // the owning layer | |
| 801 gfx::Transform S2 = Inverse(surface2_sublayer_transform); | |
| 802 | |
| 803 SetLayerPropertiesForTesting(parent.get(), | |
| 804 layer_transform, | |
| 805 gfx::Point3F(2.5f, 0.f, 0.f), | |
| 806 gfx::PointF(), | |
| 807 gfx::Size(10, 10), | |
| 808 true, | |
| 809 false); | |
| 810 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 811 layer_transform, | |
| 812 gfx::Point3F(2.5f, 0.f, 0.f), | |
| 813 gfx::PointF(), | |
| 814 gfx::Size(10, 10), | |
| 815 true, | |
| 816 false); | |
| 817 SetLayerPropertiesForTesting(render_surface2.get(), | |
| 818 layer_transform, | |
| 819 gfx::Point3F(2.5f, 0.f, 0.f), | |
| 820 gfx::PointF(), | |
| 821 gfx::Size(10, 10), | |
| 822 true, | |
| 823 false); | |
| 824 SetLayerPropertiesForTesting(child_of_root.get(), | |
| 825 layer_transform, | |
| 826 gfx::Point3F(2.5f, 0.f, 0.f), | |
| 827 gfx::PointF(), | |
| 828 gfx::Size(10, 10), | |
| 829 true, | |
| 830 false); | |
| 831 SetLayerPropertiesForTesting(child_of_rs1.get(), | |
| 832 layer_transform, | |
| 833 gfx::Point3F(2.5f, 0.f, 0.f), | |
| 834 gfx::PointF(), | |
| 835 gfx::Size(10, 10), | |
| 836 true, | |
| 837 false); | |
| 838 SetLayerPropertiesForTesting(child_of_rs2.get(), | |
| 839 layer_transform, | |
| 840 gfx::Point3F(2.5f, 0.f, 0.f), | |
| 841 gfx::PointF(), | |
| 842 gfx::Size(10, 10), | |
| 843 true, | |
| 844 false); | |
| 845 SetLayerPropertiesForTesting(grand_child_of_root.get(), | |
| 846 layer_transform, | |
| 847 gfx::Point3F(2.5f, 0.f, 0.f), | |
| 848 gfx::PointF(), | |
| 849 gfx::Size(10, 10), | |
| 850 true, | |
| 851 false); | |
| 852 SetLayerPropertiesForTesting(grand_child_of_rs1.get(), | |
| 853 layer_transform, | |
| 854 gfx::Point3F(2.5f, 0.f, 0.f), | |
| 855 gfx::PointF(), | |
| 856 gfx::Size(10, 10), | |
| 857 true, | |
| 858 false); | |
| 859 SetLayerPropertiesForTesting(grand_child_of_rs2.get(), | |
| 860 layer_transform, | |
| 861 gfx::Point3F(2.5f, 0.f, 0.f), | |
| 862 gfx::PointF(), | |
| 863 gfx::Size(10, 10), | |
| 864 true, | |
| 865 false); | |
| 866 SetLayerPropertiesForTesting(replica_of_rs1.get(), | |
| 867 replica_layer_transform, | |
| 868 gfx::Point3F(2.5f, 0.f, 0.f), | |
| 869 gfx::PointF(), | |
| 870 gfx::Size(), | |
| 871 true, | |
| 872 false); | |
| 873 SetLayerPropertiesForTesting(replica_of_rs2.get(), | |
| 874 replica_layer_transform, | |
| 875 gfx::Point3F(2.5f, 0.f, 0.f), | |
| 876 gfx::PointF(), | |
| 877 gfx::Size(), | |
| 878 true, | |
| 879 false); | |
| 880 | |
| 881 ExecuteCalculateDrawProperties(root.get()); | |
| 882 | |
| 883 // Only layers that are associated with render surfaces should have an actual | |
| 884 // RenderSurface() value. | |
| 885 ASSERT_TRUE(root->render_surface()); | |
| 886 ASSERT_FALSE(child_of_root->render_surface()); | |
| 887 ASSERT_FALSE(grand_child_of_root->render_surface()); | |
| 888 | |
| 889 ASSERT_TRUE(render_surface1->render_surface()); | |
| 890 ASSERT_FALSE(child_of_rs1->render_surface()); | |
| 891 ASSERT_FALSE(grand_child_of_rs1->render_surface()); | |
| 892 | |
| 893 ASSERT_TRUE(render_surface2->render_surface()); | |
| 894 ASSERT_FALSE(child_of_rs2->render_surface()); | |
| 895 ASSERT_FALSE(grand_child_of_rs2->render_surface()); | |
| 896 | |
| 897 // Verify all render target accessors | |
| 898 EXPECT_EQ(root.get(), parent->render_target()); | |
| 899 EXPECT_EQ(root.get(), child_of_root->render_target()); | |
| 900 EXPECT_EQ(root.get(), grand_child_of_root->render_target()); | |
| 901 | |
| 902 EXPECT_EQ(render_surface1.get(), render_surface1->render_target()); | |
| 903 EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target()); | |
| 904 EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target()); | |
| 905 | |
| 906 EXPECT_EQ(render_surface2.get(), render_surface2->render_target()); | |
| 907 EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target()); | |
| 908 EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target()); | |
| 909 | |
| 910 // Verify layer draw transforms note that draw transforms are described with | |
| 911 // respect to the nearest ancestor render surface but screen space transforms | |
| 912 // are described with respect to the root. | |
| 913 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform()); | |
| 914 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform()); | |
| 915 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, | |
| 916 grand_child_of_root->draw_transform()); | |
| 917 | |
| 918 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform()); | |
| 919 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform()); | |
| 920 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, | |
| 921 grand_child_of_rs1->draw_transform()); | |
| 922 | |
| 923 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform()); | |
| 924 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform()); | |
| 925 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, | |
| 926 grand_child_of_rs2->draw_transform()); | |
| 927 | |
| 928 // Verify layer screen-space transforms | |
| 929 // | |
| 930 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform()); | |
| 931 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, | |
| 932 child_of_root->screen_space_transform()); | |
| 933 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 934 A * A * A, grand_child_of_root->screen_space_transform()); | |
| 935 | |
| 936 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, | |
| 937 render_surface1->screen_space_transform()); | |
| 938 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, | |
| 939 child_of_rs1->screen_space_transform()); | |
| 940 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, | |
| 941 grand_child_of_rs1->screen_space_transform()); | |
| 942 | |
| 943 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, | |
| 944 render_surface2->screen_space_transform()); | |
| 945 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, | |
| 946 child_of_rs2->screen_space_transform()); | |
| 947 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, | |
| 948 grand_child_of_rs2->screen_space_transform()); | |
| 949 | |
| 950 // Verify render surface transforms. | |
| 951 // | |
| 952 // Draw transform of render surface 1 is described with respect to root. | |
| 953 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 954 A * A * S1, render_surface1->render_surface()->draw_transform()); | |
| 955 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 956 A * R * S1, render_surface1->render_surface()->replica_draw_transform()); | |
| 957 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 958 A * A * S1, render_surface1->render_surface()->screen_space_transform()); | |
| 959 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 960 A * R * S1, | |
| 961 render_surface1->render_surface()->replica_screen_space_transform()); | |
| 962 // Draw transform of render surface 2 is described with respect to render | |
| 963 // surface 1. | |
| 964 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 965 SS1 * A * S2, render_surface2->render_surface()->draw_transform()); | |
| 966 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 967 SS1 * R * S2, | |
| 968 render_surface2->render_surface()->replica_draw_transform()); | |
| 969 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 970 A * A * A * S2, | |
| 971 render_surface2->render_surface()->screen_space_transform()); | |
| 972 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 973 A * A * R * S2, | |
| 974 render_surface2->render_surface()->replica_screen_space_transform()); | |
| 975 | |
| 976 // Sanity check. If these fail there is probably a bug in the test itself. It | |
| 977 // is expected that we correctly set up transforms so that the y-component of | |
| 978 // the screen-space transform encodes the "depth" of the layer in the tree. | |
| 979 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); | |
| 980 EXPECT_FLOAT_EQ(2.0, | |
| 981 child_of_root->screen_space_transform().matrix().get(1, 3)); | |
| 982 EXPECT_FLOAT_EQ( | |
| 983 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); | |
| 984 | |
| 985 EXPECT_FLOAT_EQ(2.0, | |
| 986 render_surface1->screen_space_transform().matrix().get(1, 3)); | |
| 987 EXPECT_FLOAT_EQ(3.0, | |
| 988 child_of_rs1->screen_space_transform().matrix().get(1, 3)); | |
| 989 EXPECT_FLOAT_EQ( | |
| 990 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); | |
| 991 | |
| 992 EXPECT_FLOAT_EQ(3.0, | |
| 993 render_surface2->screen_space_transform().matrix().get(1, 3)); | |
| 994 EXPECT_FLOAT_EQ(4.0, | |
| 995 child_of_rs2->screen_space_transform().matrix().get(1, 3)); | |
| 996 EXPECT_FLOAT_EQ( | |
| 997 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); | |
| 998 } | |
| 999 | |
| 1000 TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { | |
| 1001 // For layers that flatten their subtree, there should be an orthographic | |
| 1002 // projection (for x and y values) in the middle of the transform sequence. | |
| 1003 // Note that the way the code is currently implemented, it is not expected to | |
| 1004 // use a canonical orthographic projection. | |
| 1005 | |
| 1006 scoped_refptr<Layer> root = Layer::Create(); | |
| 1007 scoped_refptr<Layer> child = Layer::Create(); | |
| 1008 scoped_refptr<LayerWithForcedDrawsContent> grand_child = | |
| 1009 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 1010 scoped_refptr<LayerWithForcedDrawsContent> great_grand_child = | |
| 1011 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 1012 | |
| 1013 gfx::Transform rotation_about_y_axis; | |
| 1014 rotation_about_y_axis.RotateAboutYAxis(30.0); | |
| 1015 | |
| 1016 const gfx::Transform identity_matrix; | |
| 1017 SetLayerPropertiesForTesting(root.get(), | |
| 1018 identity_matrix, | |
| 1019 gfx::Point3F(), | |
| 1020 gfx::PointF(), | |
| 1021 gfx::Size(100, 100), | |
| 1022 true, | |
| 1023 false); | |
| 1024 SetLayerPropertiesForTesting(child.get(), | |
| 1025 rotation_about_y_axis, | |
| 1026 gfx::Point3F(), | |
| 1027 gfx::PointF(), | |
| 1028 gfx::Size(10, 10), | |
| 1029 true, | |
| 1030 false); | |
| 1031 SetLayerPropertiesForTesting(grand_child.get(), | |
| 1032 rotation_about_y_axis, | |
| 1033 gfx::Point3F(), | |
| 1034 gfx::PointF(), | |
| 1035 gfx::Size(10, 10), | |
| 1036 true, | |
| 1037 false); | |
| 1038 SetLayerPropertiesForTesting(great_grand_child.get(), identity_matrix, | |
| 1039 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), | |
| 1040 true, false); | |
| 1041 | |
| 1042 root->AddChild(child); | |
| 1043 child->AddChild(grand_child); | |
| 1044 grand_child->AddChild(great_grand_child); | |
| 1045 child->SetForceRenderSurface(true); | |
| 1046 | |
| 1047 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 1048 host->SetRootLayer(root); | |
| 1049 | |
| 1050 // No layers in this test should preserve 3d. | |
| 1051 ASSERT_TRUE(root->should_flatten_transform()); | |
| 1052 ASSERT_TRUE(child->should_flatten_transform()); | |
| 1053 ASSERT_TRUE(grand_child->should_flatten_transform()); | |
| 1054 ASSERT_TRUE(great_grand_child->should_flatten_transform()); | |
| 1055 | |
| 1056 gfx::Transform expected_child_draw_transform = rotation_about_y_axis; | |
| 1057 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; | |
| 1058 gfx::Transform expected_grand_child_draw_transform = | |
| 1059 rotation_about_y_axis; // draws onto child's render surface | |
| 1060 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; | |
| 1061 flattened_rotation_about_y.FlattenTo2d(); | |
| 1062 gfx::Transform expected_grand_child_screen_space_transform = | |
| 1063 flattened_rotation_about_y * rotation_about_y_axis; | |
| 1064 gfx::Transform expected_great_grand_child_draw_transform = | |
| 1065 flattened_rotation_about_y; | |
| 1066 gfx::Transform expected_great_grand_child_screen_space_transform = | |
| 1067 flattened_rotation_about_y * flattened_rotation_about_y; | |
| 1068 | |
| 1069 ExecuteCalculateDrawProperties(root.get()); | |
| 1070 | |
| 1071 // The child's draw transform should have been taken by its surface. | |
| 1072 ASSERT_TRUE(child->render_surface()); | |
| 1073 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, | |
| 1074 child->render_surface()->draw_transform()); | |
| 1075 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 1076 expected_child_screen_space_transform, | |
| 1077 child->render_surface()->screen_space_transform()); | |
| 1078 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); | |
| 1079 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, | |
| 1080 child->screen_space_transform()); | |
| 1081 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, | |
| 1082 grand_child->draw_transform()); | |
| 1083 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, | |
| 1084 grand_child->screen_space_transform()); | |
| 1085 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, | |
| 1086 great_grand_child->draw_transform()); | |
| 1087 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 1088 expected_great_grand_child_screen_space_transform, | |
| 1089 great_grand_child->screen_space_transform()); | |
| 1090 } | |
| 1091 | |
| 1092 TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { | |
| 1093 // A layer that is empty in one axis, but not the other, was accidentally | |
| 1094 // skipping a necessary translation. Without that translation, the coordinate | |
| 1095 // space of the layer's draw transform is incorrect. | |
| 1096 // | |
| 1097 // Normally this isn't a problem, because the layer wouldn't be drawn anyway, | |
| 1098 // but if that layer becomes a render surface, then its draw transform is | |
| 1099 // implicitly inherited by the rest of the subtree, which then is positioned | |
| 1100 // incorrectly as a result. | |
| 1101 | |
| 1102 scoped_refptr<Layer> root = Layer::Create(); | |
| 1103 scoped_refptr<Layer> child = Layer::Create(); | |
| 1104 scoped_refptr<LayerWithForcedDrawsContent> grand_child = | |
| 1105 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 1106 | |
| 1107 // The child height is zero, but has non-zero width that should be accounted | |
| 1108 // for while computing draw transforms. | |
| 1109 const gfx::Transform identity_matrix; | |
| 1110 SetLayerPropertiesForTesting(root.get(), | |
| 1111 identity_matrix, | |
| 1112 gfx::Point3F(), | |
| 1113 gfx::PointF(), | |
| 1114 gfx::Size(100, 100), | |
| 1115 true, | |
| 1116 false); | |
| 1117 SetLayerPropertiesForTesting(child.get(), | |
| 1118 identity_matrix, | |
| 1119 gfx::Point3F(), | |
| 1120 gfx::PointF(), | |
| 1121 gfx::Size(10, 0), | |
| 1122 true, | |
| 1123 false); | |
| 1124 SetLayerPropertiesForTesting(grand_child.get(), | |
| 1125 identity_matrix, | |
| 1126 gfx::Point3F(), | |
| 1127 gfx::PointF(), | |
| 1128 gfx::Size(10, 10), | |
| 1129 true, | |
| 1130 false); | |
| 1131 | |
| 1132 root->AddChild(child); | |
| 1133 child->AddChild(grand_child); | |
| 1134 child->SetForceRenderSurface(true); | |
| 1135 | |
| 1136 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 1137 host->SetRootLayer(root); | |
| 1138 | |
| 1139 ExecuteCalculateDrawProperties(root.get()); | |
| 1140 | |
| 1141 ASSERT_TRUE(child->render_surface()); | |
| 1142 // This is the real test, the rest are sanity checks. | |
| 1143 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, | |
| 1144 child->render_surface()->draw_transform()); | |
| 1145 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); | |
| 1146 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, | |
| 1147 grand_child->draw_transform()); | |
| 1148 } | |
| 1149 | |
| 1150 TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { | |
| 1151 // Transformations applied at the root of the tree should be forwarded | |
| 1152 // to child layers instead of applied to the root RenderSurface. | |
| 1153 const gfx::Transform identity_matrix; | |
| 1154 scoped_refptr<LayerWithForcedDrawsContent> root = | |
| 1155 new LayerWithForcedDrawsContent; | |
| 1156 scoped_refptr<LayerWithForcedDrawsContent> child = | |
| 1157 new LayerWithForcedDrawsContent; | |
| 1158 child->SetScrollClipLayerId(root->id()); | |
| 1159 root->AddChild(child); | |
| 1160 | |
| 1161 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 1162 host->SetRootLayer(root); | |
| 1163 | |
| 1164 SetLayerPropertiesForTesting(root.get(), | |
| 1165 identity_matrix, | |
| 1166 gfx::Point3F(), | |
| 1167 gfx::PointF(), | |
| 1168 gfx::Size(20, 20), | |
| 1169 true, | |
| 1170 false); | |
| 1171 SetLayerPropertiesForTesting(child.get(), | |
| 1172 identity_matrix, | |
| 1173 gfx::Point3F(), | |
| 1174 gfx::PointF(), | |
| 1175 gfx::Size(20, 20), | |
| 1176 true, | |
| 1177 false); | |
| 1178 | |
| 1179 gfx::Transform translate; | |
| 1180 translate.Translate(50, 50); | |
| 1181 { | |
| 1182 RenderSurfaceLayerList render_surface_layer_list; | |
| 1183 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1184 root.get(), root->bounds(), translate, &render_surface_layer_list); | |
| 1185 inputs.can_adjust_raster_scales = true; | |
| 1186 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1187 EXPECT_EQ(translate, root->draw_properties().target_space_transform); | |
| 1188 EXPECT_EQ(translate, child->draw_properties().target_space_transform); | |
| 1189 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); | |
| 1190 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); | |
| 1191 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); | |
| 1192 } | |
| 1193 | |
| 1194 gfx::Transform scale; | |
| 1195 scale.Scale(2, 2); | |
| 1196 { | |
| 1197 RenderSurfaceLayerList render_surface_layer_list; | |
| 1198 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1199 root.get(), root->bounds(), scale, &render_surface_layer_list); | |
| 1200 inputs.can_adjust_raster_scales = true; | |
| 1201 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1202 EXPECT_EQ(scale, root->draw_properties().target_space_transform); | |
| 1203 EXPECT_EQ(scale, child->draw_properties().target_space_transform); | |
| 1204 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); | |
| 1205 EXPECT_EQ(2.f, root->draw_properties().device_scale_factor); | |
| 1206 EXPECT_EQ(2.f, child->draw_properties().device_scale_factor); | |
| 1207 } | |
| 1208 | |
| 1209 gfx::Transform rotate; | |
| 1210 rotate.Rotate(2); | |
| 1211 { | |
| 1212 RenderSurfaceLayerList render_surface_layer_list; | |
| 1213 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1214 root.get(), root->bounds(), rotate, &render_surface_layer_list); | |
| 1215 inputs.can_adjust_raster_scales = true; | |
| 1216 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1217 EXPECT_EQ(rotate, root->draw_properties().target_space_transform); | |
| 1218 EXPECT_EQ(rotate, child->draw_properties().target_space_transform); | |
| 1219 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); | |
| 1220 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); | |
| 1221 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); | |
| 1222 } | |
| 1223 | |
| 1224 gfx::Transform composite; | |
| 1225 composite.ConcatTransform(translate); | |
| 1226 composite.ConcatTransform(scale); | |
| 1227 composite.ConcatTransform(rotate); | |
| 1228 { | |
| 1229 RenderSurfaceLayerList render_surface_layer_list; | |
| 1230 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1231 root.get(), root->bounds(), composite, &render_surface_layer_list); | |
| 1232 inputs.can_adjust_raster_scales = true; | |
| 1233 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1234 EXPECT_EQ(composite, root->draw_properties().target_space_transform); | |
| 1235 EXPECT_EQ(composite, child->draw_properties().target_space_transform); | |
| 1236 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); | |
| 1237 } | |
| 1238 | |
| 1239 // Verify it composes correctly with device scale. | |
| 1240 float device_scale_factor = 1.5f; | |
| 1241 | |
| 1242 { | |
| 1243 RenderSurfaceLayerList render_surface_layer_list; | |
| 1244 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1245 root.get(), root->bounds(), translate, &render_surface_layer_list); | |
| 1246 inputs.device_scale_factor = device_scale_factor; | |
| 1247 inputs.can_adjust_raster_scales = true; | |
| 1248 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1249 gfx::Transform device_scaled_translate = translate; | |
| 1250 device_scaled_translate.Scale(device_scale_factor, device_scale_factor); | |
| 1251 EXPECT_EQ(device_scaled_translate, | |
| 1252 root->draw_properties().target_space_transform); | |
| 1253 EXPECT_EQ(device_scaled_translate, | |
| 1254 child->draw_properties().target_space_transform); | |
| 1255 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); | |
| 1256 EXPECT_EQ(device_scale_factor, root->draw_properties().device_scale_factor); | |
| 1257 EXPECT_EQ(device_scale_factor, | |
| 1258 child->draw_properties().device_scale_factor); | |
| 1259 } | |
| 1260 | |
| 1261 // Verify it composes correctly with page scale. | |
| 1262 float page_scale_factor = 2.f; | |
| 1263 | |
| 1264 { | |
| 1265 RenderSurfaceLayerList render_surface_layer_list; | |
| 1266 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1267 root.get(), root->bounds(), translate, &render_surface_layer_list); | |
| 1268 inputs.page_scale_factor = page_scale_factor; | |
| 1269 inputs.page_scale_application_layer = root.get(); | |
| 1270 inputs.can_adjust_raster_scales = true; | |
| 1271 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1272 gfx::Transform page_scaled_translate = translate; | |
| 1273 page_scaled_translate.Scale(page_scale_factor, page_scale_factor); | |
| 1274 EXPECT_EQ(translate, root->draw_properties().target_space_transform); | |
| 1275 EXPECT_EQ(page_scaled_translate, | |
| 1276 child->draw_properties().target_space_transform); | |
| 1277 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); | |
| 1278 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); | |
| 1279 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); | |
| 1280 } | |
| 1281 | |
| 1282 // Verify that it composes correctly with transforms directly on root layer. | |
| 1283 root->SetTransform(composite); | |
| 1284 | |
| 1285 { | |
| 1286 RenderSurfaceLayerList render_surface_layer_list; | |
| 1287 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1288 root.get(), root->bounds(), composite, &render_surface_layer_list); | |
| 1289 inputs.can_adjust_raster_scales = true; | |
| 1290 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1291 gfx::Transform compositeSquared = composite; | |
| 1292 compositeSquared.ConcatTransform(composite); | |
| 1293 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 1294 compositeSquared, root->draw_properties().target_space_transform); | |
| 1295 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 1296 compositeSquared, child->draw_properties().target_space_transform); | |
| 1297 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); | |
| 1298 } | |
| 1299 } | |
| 1300 | |
| 1301 TEST_F(LayerTreeHostCommonTest, | |
| 1302 RenderSurfaceListForRenderSurfaceWithClippedLayer) { | |
| 1303 scoped_refptr<Layer> parent = Layer::Create(); | |
| 1304 scoped_refptr<Layer> render_surface1 = Layer::Create(); | |
| 1305 scoped_refptr<LayerWithForcedDrawsContent> child = | |
| 1306 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 1307 | |
| 1308 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 1309 host->SetRootLayer(parent); | |
| 1310 | |
| 1311 const gfx::Transform identity_matrix; | |
| 1312 SetLayerPropertiesForTesting(parent.get(), | |
| 1313 identity_matrix, | |
| 1314 gfx::Point3F(), | |
| 1315 gfx::PointF(), | |
| 1316 gfx::Size(10, 10), | |
| 1317 true, | |
| 1318 false); | |
| 1319 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 1320 identity_matrix, | |
| 1321 gfx::Point3F(), | |
| 1322 gfx::PointF(), | |
| 1323 gfx::Size(10, 10), | |
| 1324 true, | |
| 1325 false); | |
| 1326 SetLayerPropertiesForTesting(child.get(), | |
| 1327 identity_matrix, | |
| 1328 gfx::Point3F(), | |
| 1329 gfx::PointF(30.f, 30.f), | |
| 1330 gfx::Size(10, 10), | |
| 1331 true, | |
| 1332 false); | |
| 1333 | |
| 1334 parent->AddChild(render_surface1); | |
| 1335 parent->SetMasksToBounds(true); | |
| 1336 render_surface1->AddChild(child); | |
| 1337 render_surface1->SetForceRenderSurface(true); | |
| 1338 | |
| 1339 RenderSurfaceLayerList render_surface_layer_list; | |
| 1340 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1341 parent.get(), | |
| 1342 parent->bounds(), | |
| 1343 gfx::Transform(), | |
| 1344 &render_surface_layer_list); | |
| 1345 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1346 | |
| 1347 // The child layer's content is entirely outside the parent's clip rect, so | |
| 1348 // the intermediate render surface should not be listed here, even if it was | |
| 1349 // forced to be created. Render surfaces without children or visible content | |
| 1350 // are unexpected at draw time (e.g. we might try to create a content texture | |
| 1351 // of size 0). | |
| 1352 ASSERT_TRUE(parent->render_surface()); | |
| 1353 EXPECT_EQ(1U, render_surface_layer_list.size()); | |
| 1354 } | |
| 1355 | |
| 1356 TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { | |
| 1357 scoped_refptr<Layer> parent = Layer::Create(); | |
| 1358 scoped_refptr<Layer> render_surface1 = Layer::Create(); | |
| 1359 scoped_refptr<LayerWithForcedDrawsContent> child = | |
| 1360 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 1361 | |
| 1362 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 1363 host->SetRootLayer(parent); | |
| 1364 | |
| 1365 const gfx::Transform identity_matrix; | |
| 1366 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 1367 identity_matrix, | |
| 1368 gfx::Point3F(), | |
| 1369 gfx::PointF(), | |
| 1370 gfx::Size(10, 10), | |
| 1371 true, | |
| 1372 false); | |
| 1373 SetLayerPropertiesForTesting(child.get(), | |
| 1374 identity_matrix, | |
| 1375 gfx::Point3F(), | |
| 1376 gfx::PointF(), | |
| 1377 gfx::Size(10, 10), | |
| 1378 true, | |
| 1379 false); | |
| 1380 | |
| 1381 parent->AddChild(render_surface1); | |
| 1382 render_surface1->AddChild(child); | |
| 1383 render_surface1->SetForceRenderSurface(true); | |
| 1384 render_surface1->SetOpacity(0.f); | |
| 1385 | |
| 1386 RenderSurfaceLayerList render_surface_layer_list; | |
| 1387 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1388 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 1389 inputs.can_adjust_raster_scales = true; | |
| 1390 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1391 | |
| 1392 // Since the layer is transparent, render_surface1->render_surface() should | |
| 1393 // not have gotten added anywhere. Also, the drawable content rect should not | |
| 1394 // have been extended by the children. | |
| 1395 ASSERT_TRUE(parent->render_surface()); | |
| 1396 EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); | |
| 1397 EXPECT_EQ(1U, render_surface_layer_list.size()); | |
| 1398 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); | |
| 1399 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); | |
| 1400 } | |
| 1401 | |
| 1402 TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { | |
| 1403 scoped_refptr<Layer> parent = Layer::Create(); | |
| 1404 scoped_refptr<LayerWithForcedDrawsContent> child = | |
| 1405 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 1406 | |
| 1407 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 1408 host->SetRootLayer(parent); | |
| 1409 | |
| 1410 const gfx::Transform identity_matrix; | |
| 1411 const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode; | |
| 1412 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), | |
| 1413 gfx::PointF(), gfx::Size(10, 10), true, false); | |
| 1414 | |
| 1415 parent->AddChild(child); | |
| 1416 child->SetBlendMode(blend_mode); | |
| 1417 | |
| 1418 RenderSurfaceLayerList render_surface_layer_list; | |
| 1419 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1420 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 1421 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1422 | |
| 1423 // Since the child layer has a blend mode other than normal, it should get | |
| 1424 // its own render surface. Also, layer's draw_properties should contain the | |
| 1425 // default blend mode, since the render surface becomes responsible for | |
| 1426 // applying the blend mode. | |
| 1427 ASSERT_TRUE(child->render_surface()); | |
| 1428 EXPECT_EQ(1U, child->render_surface()->layer_list().size()); | |
| 1429 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_properties().blend_mode); | |
| 1430 } | |
| 1431 | |
| 1432 TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { | |
| 1433 scoped_refptr<Layer> parent = Layer::Create(); | |
| 1434 scoped_refptr<Layer> render_surface1 = Layer::Create(); | |
| 1435 scoped_refptr<LayerWithForcedDrawsContent> child = | |
| 1436 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 1437 render_surface1->SetForceRenderSurface(true); | |
| 1438 | |
| 1439 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 1440 host->SetRootLayer(parent); | |
| 1441 | |
| 1442 const gfx::Transform identity_matrix; | |
| 1443 SetLayerPropertiesForTesting(parent.get(), | |
| 1444 identity_matrix, | |
| 1445 gfx::Point3F(), | |
| 1446 gfx::PointF(), | |
| 1447 gfx::Size(10, 10), | |
| 1448 true, | |
| 1449 false); | |
| 1450 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 1451 identity_matrix, | |
| 1452 gfx::Point3F(), | |
| 1453 gfx::PointF(), | |
| 1454 gfx::Size(10, 10), | |
| 1455 true, | |
| 1456 false); | |
| 1457 SetLayerPropertiesForTesting(child.get(), | |
| 1458 identity_matrix, | |
| 1459 gfx::Point3F(), | |
| 1460 gfx::PointF(), | |
| 1461 gfx::Size(10, 10), | |
| 1462 true, | |
| 1463 false); | |
| 1464 | |
| 1465 parent->AddChild(render_surface1); | |
| 1466 render_surface1->AddChild(child); | |
| 1467 | |
| 1468 // Sanity check before the actual test | |
| 1469 EXPECT_FALSE(parent->render_surface()); | |
| 1470 EXPECT_FALSE(render_surface1->render_surface()); | |
| 1471 | |
| 1472 { | |
| 1473 RenderSurfaceLayerList render_surface_layer_list; | |
| 1474 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1475 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 1476 inputs.can_adjust_raster_scales = true; | |
| 1477 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1478 | |
| 1479 // The root layer always creates a render surface | |
| 1480 EXPECT_TRUE(parent->render_surface()); | |
| 1481 EXPECT_TRUE(render_surface1->render_surface()); | |
| 1482 EXPECT_EQ(2U, render_surface_layer_list.size()); | |
| 1483 } | |
| 1484 | |
| 1485 { | |
| 1486 RenderSurfaceLayerList render_surface_layer_list; | |
| 1487 render_surface1->SetForceRenderSurface(false); | |
| 1488 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1489 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 1490 inputs.can_adjust_raster_scales = true; | |
| 1491 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1492 EXPECT_TRUE(parent->render_surface()); | |
| 1493 EXPECT_FALSE(render_surface1->render_surface()); | |
| 1494 EXPECT_EQ(1U, render_surface_layer_list.size()); | |
| 1495 } | |
| 1496 } | |
| 1497 | |
| 1498 TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { | |
| 1499 // Render surfaces act as a flattening point for their subtree, so should | |
| 1500 // always flatten the target-to-screen space transform seen by descendants. | |
| 1501 | |
| 1502 scoped_refptr<Layer> root = Layer::Create(); | |
| 1503 scoped_refptr<Layer> parent = Layer::Create(); | |
| 1504 scoped_refptr<LayerWithForcedDrawsContent> child = | |
| 1505 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 1506 scoped_refptr<LayerWithForcedDrawsContent> grand_child = | |
| 1507 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 1508 | |
| 1509 gfx::Transform rotation_about_y_axis; | |
| 1510 rotation_about_y_axis.RotateAboutYAxis(30.0); | |
| 1511 // Make |parent| have a render surface. | |
| 1512 parent->SetOpacity(0.9f); | |
| 1513 | |
| 1514 const gfx::Transform identity_matrix; | |
| 1515 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), | |
| 1516 gfx::PointF(), gfx::Size(100, 100), true, false); | |
| 1517 SetLayerPropertiesForTesting(parent.get(), rotation_about_y_axis, | |
| 1518 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), | |
| 1519 true, false); | |
| 1520 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), | |
| 1521 gfx::PointF(), gfx::Size(10, 10), true, false); | |
| 1522 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, | |
| 1523 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), | |
| 1524 true, false); | |
| 1525 | |
| 1526 root->AddChild(parent); | |
| 1527 parent->AddChild(child); | |
| 1528 child->AddChild(grand_child); | |
| 1529 | |
| 1530 grand_child->SetShouldFlattenTransform(false); | |
| 1531 | |
| 1532 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 1533 host->SetRootLayer(root); | |
| 1534 | |
| 1535 // Only grand_child should preserve 3d. | |
| 1536 EXPECT_TRUE(root->should_flatten_transform()); | |
| 1537 EXPECT_TRUE(parent->should_flatten_transform()); | |
| 1538 EXPECT_TRUE(child->should_flatten_transform()); | |
| 1539 EXPECT_FALSE(grand_child->should_flatten_transform()); | |
| 1540 | |
| 1541 gfx::Transform expected_child_draw_transform = identity_matrix; | |
| 1542 gfx::Transform expected_grand_child_draw_transform = identity_matrix; | |
| 1543 | |
| 1544 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; | |
| 1545 flattened_rotation_about_y.FlattenTo2d(); | |
| 1546 | |
| 1547 ExecuteCalculateDrawProperties(root.get()); | |
| 1548 | |
| 1549 EXPECT_TRUE(parent->render_surface()); | |
| 1550 EXPECT_FALSE(child->render_surface()); | |
| 1551 EXPECT_FALSE(grand_child->render_surface()); | |
| 1552 | |
| 1553 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); | |
| 1554 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, | |
| 1555 grand_child->draw_transform()); | |
| 1556 | |
| 1557 // The screen-space transform inherited by |child| and |grand_child| should | |
| 1558 // have been flattened at their render target. In particular, the fact that | |
| 1559 // |grand_child| happens to preserve 3d shouldn't affect this flattening. | |
| 1560 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, | |
| 1561 child->screen_space_transform()); | |
| 1562 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, | |
| 1563 grand_child->screen_space_transform()); | |
| 1564 } | |
| 1565 | |
| 1566 TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { | |
| 1567 // The entire subtree of layers that are outside the clip rect should be | |
| 1568 // culled away, and should not affect the render_surface_layer_list. | |
| 1569 // | |
| 1570 // The test tree is set up as follows: | |
| 1571 // - all layers except the leaf_nodes are forced to be a new render surface | |
| 1572 // that have something to draw. | |
| 1573 // - parent is a large container layer. | |
| 1574 // - child has masksToBounds=true to cause clipping. | |
| 1575 // - grand_child is positioned outside of the child's bounds | |
| 1576 // - great_grand_child is also kept outside child's bounds. | |
| 1577 // | |
| 1578 // In this configuration, grand_child and great_grand_child are completely | |
| 1579 // outside the clip rect, and they should never get scheduled on the list of | |
| 1580 // render surfaces. | |
| 1581 // | |
| 1582 | |
| 1583 const gfx::Transform identity_matrix; | |
| 1584 scoped_refptr<Layer> parent = Layer::Create(); | |
| 1585 scoped_refptr<Layer> child = Layer::Create(); | |
| 1586 scoped_refptr<Layer> grand_child = Layer::Create(); | |
| 1587 scoped_refptr<Layer> great_grand_child = Layer::Create(); | |
| 1588 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = | |
| 1589 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 1590 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = | |
| 1591 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 1592 parent->AddChild(child); | |
| 1593 child->AddChild(grand_child); | |
| 1594 grand_child->AddChild(great_grand_child); | |
| 1595 | |
| 1596 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 1597 host->SetRootLayer(parent); | |
| 1598 | |
| 1599 // leaf_node1 ensures that parent and child are kept on the | |
| 1600 // render_surface_layer_list, even though grand_child and great_grand_child | |
| 1601 // should be clipped. | |
| 1602 child->AddChild(leaf_node1); | |
| 1603 great_grand_child->AddChild(leaf_node2); | |
| 1604 | |
| 1605 SetLayerPropertiesForTesting(parent.get(), | |
| 1606 identity_matrix, | |
| 1607 gfx::Point3F(), | |
| 1608 gfx::PointF(), | |
| 1609 gfx::Size(500, 500), | |
| 1610 true, | |
| 1611 false); | |
| 1612 SetLayerPropertiesForTesting(child.get(), | |
| 1613 identity_matrix, | |
| 1614 gfx::Point3F(), | |
| 1615 gfx::PointF(), | |
| 1616 gfx::Size(20, 20), | |
| 1617 true, | |
| 1618 false); | |
| 1619 SetLayerPropertiesForTesting(grand_child.get(), | |
| 1620 identity_matrix, | |
| 1621 gfx::Point3F(), | |
| 1622 gfx::PointF(45.f, 45.f), | |
| 1623 gfx::Size(10, 10), | |
| 1624 true, | |
| 1625 false); | |
| 1626 SetLayerPropertiesForTesting(great_grand_child.get(), | |
| 1627 identity_matrix, | |
| 1628 gfx::Point3F(), | |
| 1629 gfx::PointF(), | |
| 1630 gfx::Size(10, 10), | |
| 1631 true, | |
| 1632 false); | |
| 1633 SetLayerPropertiesForTesting(leaf_node1.get(), | |
| 1634 identity_matrix, | |
| 1635 gfx::Point3F(), | |
| 1636 gfx::PointF(), | |
| 1637 gfx::Size(500, 500), | |
| 1638 true, | |
| 1639 false); | |
| 1640 SetLayerPropertiesForTesting(leaf_node2.get(), | |
| 1641 identity_matrix, | |
| 1642 gfx::Point3F(), | |
| 1643 gfx::PointF(), | |
| 1644 gfx::Size(20, 20), | |
| 1645 true, | |
| 1646 false); | |
| 1647 | |
| 1648 child->SetMasksToBounds(true); | |
| 1649 child->SetOpacity(0.4f); | |
| 1650 child->SetForceRenderSurface(true); | |
| 1651 grand_child->SetOpacity(0.5f); | |
| 1652 great_grand_child->SetOpacity(0.4f); | |
| 1653 | |
| 1654 RenderSurfaceLayerList render_surface_layer_list; | |
| 1655 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1656 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 1657 inputs.can_adjust_raster_scales = true; | |
| 1658 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1659 | |
| 1660 ASSERT_EQ(2U, render_surface_layer_list.size()); | |
| 1661 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); | |
| 1662 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); | |
| 1663 } | |
| 1664 | |
| 1665 TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { | |
| 1666 // When a render surface has a clip rect, it is used to clip the content rect | |
| 1667 // of the surface. When the render surface is animating its transforms, then | |
| 1668 // the content rect's position in the clip rect is not defined on the main | |
| 1669 // thread, and its content rect should not be clipped. | |
| 1670 | |
| 1671 // The test tree is set up as follows: | |
| 1672 // - parent is a container layer that masksToBounds=true to cause clipping. | |
| 1673 // - child is a render surface, which has a clip rect set to the bounds of | |
| 1674 // the parent. | |
| 1675 // - grand_child is a render surface, and the only visible content in child. | |
| 1676 // It is positioned outside of the clip rect from parent. | |
| 1677 | |
| 1678 // In this configuration, grand_child should be outside the clipped | |
| 1679 // content rect of the child, making grand_child not appear in the | |
| 1680 // render_surface_layer_list. However, when we place an animation on the | |
| 1681 // child, this clipping should be avoided and we should keep the grand_child | |
| 1682 // in the render_surface_layer_list. | |
| 1683 | |
| 1684 const gfx::Transform identity_matrix; | |
| 1685 scoped_refptr<Layer> parent = Layer::Create(); | |
| 1686 scoped_refptr<Layer> child = Layer::Create(); | |
| 1687 scoped_refptr<Layer> grand_child = Layer::Create(); | |
| 1688 scoped_refptr<LayerWithForcedDrawsContent> leaf_node = | |
| 1689 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 1690 parent->AddChild(child); | |
| 1691 child->AddChild(grand_child); | |
| 1692 grand_child->AddChild(leaf_node); | |
| 1693 | |
| 1694 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 1695 host->SetRootLayer(parent); | |
| 1696 | |
| 1697 SetLayerPropertiesForTesting(parent.get(), | |
| 1698 identity_matrix, | |
| 1699 gfx::Point3F(), | |
| 1700 gfx::PointF(), | |
| 1701 gfx::Size(100, 100), | |
| 1702 true, | |
| 1703 false); | |
| 1704 SetLayerPropertiesForTesting(child.get(), | |
| 1705 identity_matrix, | |
| 1706 gfx::Point3F(), | |
| 1707 gfx::PointF(), | |
| 1708 gfx::Size(20, 20), | |
| 1709 true, | |
| 1710 false); | |
| 1711 SetLayerPropertiesForTesting(grand_child.get(), | |
| 1712 identity_matrix, | |
| 1713 gfx::Point3F(), | |
| 1714 gfx::PointF(200.f, 200.f), | |
| 1715 gfx::Size(10, 10), | |
| 1716 true, | |
| 1717 false); | |
| 1718 SetLayerPropertiesForTesting(leaf_node.get(), | |
| 1719 identity_matrix, | |
| 1720 gfx::Point3F(), | |
| 1721 gfx::PointF(), | |
| 1722 gfx::Size(10, 10), | |
| 1723 true, | |
| 1724 false); | |
| 1725 | |
| 1726 parent->SetMasksToBounds(true); | |
| 1727 child->SetOpacity(0.4f); | |
| 1728 child->SetForceRenderSurface(true); | |
| 1729 grand_child->SetOpacity(0.4f); | |
| 1730 grand_child->SetForceRenderSurface(true); | |
| 1731 | |
| 1732 { | |
| 1733 RenderSurfaceLayerList render_surface_layer_list; | |
| 1734 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1735 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 1736 inputs.can_adjust_raster_scales = true; | |
| 1737 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1738 | |
| 1739 // Without an animation, we should cull child and grand_child from the | |
| 1740 // render_surface_layer_list. | |
| 1741 ASSERT_EQ(1U, render_surface_layer_list.size()); | |
| 1742 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); | |
| 1743 } | |
| 1744 | |
| 1745 // Now put an animating transform on child. | |
| 1746 AddAnimatedTransformToController( | |
| 1747 child->layer_animation_controller(), 10.0, 30, 0); | |
| 1748 | |
| 1749 { | |
| 1750 RenderSurfaceLayerList render_surface_layer_list; | |
| 1751 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1752 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 1753 inputs.can_adjust_raster_scales = true; | |
| 1754 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1755 | |
| 1756 // With an animating transform, we should keep child and grand_child in the | |
| 1757 // render_surface_layer_list. | |
| 1758 ASSERT_EQ(3U, render_surface_layer_list.size()); | |
| 1759 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); | |
| 1760 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); | |
| 1761 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id()); | |
| 1762 } | |
| 1763 } | |
| 1764 | |
| 1765 TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) { | |
| 1766 // Layer's IsClipped() property is set to true when: | |
| 1767 // - the layer clips its subtree, e.g. masks to bounds, | |
| 1768 // - the layer is clipped by an ancestor that contributes to the same | |
| 1769 // render target, | |
| 1770 // - a surface is clipped by an ancestor that contributes to the same | |
| 1771 // render target. | |
| 1772 // | |
| 1773 // In particular, for a layer that owns a render surface: | |
| 1774 // - the render surface inherits any clip from ancestors, and does NOT | |
| 1775 // pass that clipped status to the layer itself. | |
| 1776 // - but if the layer itself masks to bounds, it is considered clipped | |
| 1777 // and propagates the clip to the subtree. | |
| 1778 | |
| 1779 const gfx::Transform identity_matrix; | |
| 1780 scoped_refptr<Layer> root = Layer::Create(); | |
| 1781 scoped_refptr<Layer> parent = Layer::Create(); | |
| 1782 scoped_refptr<Layer> child1 = Layer::Create(); | |
| 1783 scoped_refptr<Layer> child2 = Layer::Create(); | |
| 1784 scoped_refptr<Layer> grand_child = Layer::Create(); | |
| 1785 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = | |
| 1786 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 1787 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = | |
| 1788 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 1789 root->AddChild(parent); | |
| 1790 parent->AddChild(child1); | |
| 1791 parent->AddChild(child2); | |
| 1792 child1->AddChild(grand_child); | |
| 1793 child2->AddChild(leaf_node2); | |
| 1794 grand_child->AddChild(leaf_node1); | |
| 1795 | |
| 1796 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 1797 host->SetRootLayer(root); | |
| 1798 | |
| 1799 child2->SetForceRenderSurface(true); | |
| 1800 | |
| 1801 SetLayerPropertiesForTesting(root.get(), | |
| 1802 identity_matrix, | |
| 1803 gfx::Point3F(), | |
| 1804 gfx::PointF(), | |
| 1805 gfx::Size(100, 100), | |
| 1806 true, | |
| 1807 false); | |
| 1808 SetLayerPropertiesForTesting(parent.get(), | |
| 1809 identity_matrix, | |
| 1810 gfx::Point3F(), | |
| 1811 gfx::PointF(), | |
| 1812 gfx::Size(100, 100), | |
| 1813 true, | |
| 1814 false); | |
| 1815 SetLayerPropertiesForTesting(child1.get(), | |
| 1816 identity_matrix, | |
| 1817 gfx::Point3F(), | |
| 1818 gfx::PointF(), | |
| 1819 gfx::Size(100, 100), | |
| 1820 true, | |
| 1821 false); | |
| 1822 SetLayerPropertiesForTesting(child2.get(), | |
| 1823 identity_matrix, | |
| 1824 gfx::Point3F(), | |
| 1825 gfx::PointF(), | |
| 1826 gfx::Size(100, 100), | |
| 1827 true, | |
| 1828 false); | |
| 1829 SetLayerPropertiesForTesting(grand_child.get(), | |
| 1830 identity_matrix, | |
| 1831 gfx::Point3F(), | |
| 1832 gfx::PointF(), | |
| 1833 gfx::Size(100, 100), | |
| 1834 true, | |
| 1835 false); | |
| 1836 SetLayerPropertiesForTesting(leaf_node1.get(), | |
| 1837 identity_matrix, | |
| 1838 gfx::Point3F(), | |
| 1839 gfx::PointF(), | |
| 1840 gfx::Size(100, 100), | |
| 1841 true, | |
| 1842 false); | |
| 1843 SetLayerPropertiesForTesting(leaf_node2.get(), | |
| 1844 identity_matrix, | |
| 1845 gfx::Point3F(), | |
| 1846 gfx::PointF(), | |
| 1847 gfx::Size(100, 100), | |
| 1848 true, | |
| 1849 false); | |
| 1850 | |
| 1851 // Case 1: nothing is clipped except the root render surface. | |
| 1852 { | |
| 1853 RenderSurfaceLayerList render_surface_layer_list; | |
| 1854 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1855 root.get(), parent->bounds(), &render_surface_layer_list); | |
| 1856 inputs.can_adjust_raster_scales = true; | |
| 1857 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1858 | |
| 1859 ASSERT_TRUE(root->render_surface()); | |
| 1860 ASSERT_TRUE(child2->render_surface()); | |
| 1861 | |
| 1862 EXPECT_FALSE(root->is_clipped()); | |
| 1863 EXPECT_TRUE(root->render_surface()->is_clipped()); | |
| 1864 EXPECT_FALSE(parent->is_clipped()); | |
| 1865 EXPECT_FALSE(child1->is_clipped()); | |
| 1866 EXPECT_FALSE(child2->is_clipped()); | |
| 1867 EXPECT_FALSE(child2->render_surface()->is_clipped()); | |
| 1868 EXPECT_FALSE(grand_child->is_clipped()); | |
| 1869 EXPECT_FALSE(leaf_node1->is_clipped()); | |
| 1870 EXPECT_FALSE(leaf_node2->is_clipped()); | |
| 1871 } | |
| 1872 | |
| 1873 // Case 2: parent masksToBounds, so the parent, child1, and child2's | |
| 1874 // surface are clipped. But layers that contribute to child2's surface are | |
| 1875 // not clipped explicitly because child2's surface already accounts for | |
| 1876 // that clip. | |
| 1877 { | |
| 1878 RenderSurfaceLayerList render_surface_layer_list; | |
| 1879 parent->SetMasksToBounds(true); | |
| 1880 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1881 root.get(), parent->bounds(), &render_surface_layer_list); | |
| 1882 inputs.can_adjust_raster_scales = true; | |
| 1883 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1884 | |
| 1885 ASSERT_TRUE(root->render_surface()); | |
| 1886 ASSERT_TRUE(child2->render_surface()); | |
| 1887 | |
| 1888 EXPECT_FALSE(root->is_clipped()); | |
| 1889 EXPECT_TRUE(root->render_surface()->is_clipped()); | |
| 1890 EXPECT_TRUE(parent->is_clipped()); | |
| 1891 EXPECT_TRUE(child1->is_clipped()); | |
| 1892 EXPECT_FALSE(child2->is_clipped()); | |
| 1893 EXPECT_TRUE(child2->render_surface()->is_clipped()); | |
| 1894 EXPECT_TRUE(grand_child->is_clipped()); | |
| 1895 EXPECT_TRUE(leaf_node1->is_clipped()); | |
| 1896 EXPECT_FALSE(leaf_node2->is_clipped()); | |
| 1897 } | |
| 1898 | |
| 1899 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and | |
| 1900 // child2's render surface is not clipped. | |
| 1901 { | |
| 1902 RenderSurfaceLayerList render_surface_layer_list; | |
| 1903 parent->SetMasksToBounds(false); | |
| 1904 child2->SetMasksToBounds(true); | |
| 1905 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 1906 root.get(), parent->bounds(), &render_surface_layer_list); | |
| 1907 inputs.can_adjust_raster_scales = true; | |
| 1908 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 1909 | |
| 1910 ASSERT_TRUE(root->render_surface()); | |
| 1911 ASSERT_TRUE(child2->render_surface()); | |
| 1912 | |
| 1913 EXPECT_FALSE(root->is_clipped()); | |
| 1914 EXPECT_TRUE(root->render_surface()->is_clipped()); | |
| 1915 EXPECT_FALSE(parent->is_clipped()); | |
| 1916 EXPECT_FALSE(child1->is_clipped()); | |
| 1917 EXPECT_TRUE(child2->is_clipped()); | |
| 1918 EXPECT_FALSE(child2->render_surface()->is_clipped()); | |
| 1919 EXPECT_FALSE(grand_child->is_clipped()); | |
| 1920 EXPECT_FALSE(leaf_node1->is_clipped()); | |
| 1921 EXPECT_TRUE(leaf_node2->is_clipped()); | |
| 1922 } | |
| 1923 } | |
| 1924 | |
| 1925 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { | |
| 1926 // Verify that layers get the appropriate DrawableContentRect when their | |
| 1927 // parent masksToBounds is true. | |
| 1928 // | |
| 1929 // grand_child1 - completely inside the region; DrawableContentRect should | |
| 1930 // be the layer rect expressed in target space. | |
| 1931 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect | |
| 1932 // will be the intersection of layer bounds and the mask region. | |
| 1933 // grand_child3 - partially clipped and masksToBounds; the | |
| 1934 // DrawableContentRect will still be the intersection of layer bounds and | |
| 1935 // the mask region. | |
| 1936 // grand_child4 - outside parent's clip rect; the DrawableContentRect should | |
| 1937 // be empty. | |
| 1938 // | |
| 1939 | |
| 1940 const gfx::Transform identity_matrix; | |
| 1941 scoped_refptr<Layer> parent = Layer::Create(); | |
| 1942 scoped_refptr<Layer> child = Layer::Create(); | |
| 1943 scoped_refptr<Layer> grand_child1 = Layer::Create(); | |
| 1944 scoped_refptr<Layer> grand_child2 = Layer::Create(); | |
| 1945 scoped_refptr<Layer> grand_child3 = Layer::Create(); | |
| 1946 scoped_refptr<Layer> grand_child4 = Layer::Create(); | |
| 1947 | |
| 1948 parent->AddChild(child); | |
| 1949 child->AddChild(grand_child1); | |
| 1950 child->AddChild(grand_child2); | |
| 1951 child->AddChild(grand_child3); | |
| 1952 child->AddChild(grand_child4); | |
| 1953 | |
| 1954 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 1955 host->SetRootLayer(parent); | |
| 1956 | |
| 1957 SetLayerPropertiesForTesting(parent.get(), | |
| 1958 identity_matrix, | |
| 1959 gfx::Point3F(), | |
| 1960 gfx::PointF(), | |
| 1961 gfx::Size(500, 500), | |
| 1962 true, | |
| 1963 false); | |
| 1964 SetLayerPropertiesForTesting(child.get(), | |
| 1965 identity_matrix, | |
| 1966 gfx::Point3F(), | |
| 1967 gfx::PointF(), | |
| 1968 gfx::Size(20, 20), | |
| 1969 true, | |
| 1970 false); | |
| 1971 SetLayerPropertiesForTesting(grand_child1.get(), | |
| 1972 identity_matrix, | |
| 1973 gfx::Point3F(), | |
| 1974 gfx::PointF(5.f, 5.f), | |
| 1975 gfx::Size(10, 10), | |
| 1976 true, | |
| 1977 false); | |
| 1978 SetLayerPropertiesForTesting(grand_child2.get(), | |
| 1979 identity_matrix, | |
| 1980 gfx::Point3F(), | |
| 1981 gfx::PointF(15.f, 15.f), | |
| 1982 gfx::Size(10, 10), | |
| 1983 true, | |
| 1984 false); | |
| 1985 SetLayerPropertiesForTesting(grand_child3.get(), | |
| 1986 identity_matrix, | |
| 1987 gfx::Point3F(), | |
| 1988 gfx::PointF(15.f, 15.f), | |
| 1989 gfx::Size(10, 10), | |
| 1990 true, | |
| 1991 false); | |
| 1992 SetLayerPropertiesForTesting(grand_child4.get(), | |
| 1993 identity_matrix, | |
| 1994 gfx::Point3F(), | |
| 1995 gfx::PointF(45.f, 45.f), | |
| 1996 gfx::Size(10, 10), | |
| 1997 true, | |
| 1998 false); | |
| 1999 | |
| 2000 child->SetMasksToBounds(true); | |
| 2001 grand_child3->SetMasksToBounds(true); | |
| 2002 | |
| 2003 // Force everyone to be a render surface. | |
| 2004 child->SetOpacity(0.4f); | |
| 2005 grand_child1->SetOpacity(0.5f); | |
| 2006 grand_child2->SetOpacity(0.5f); | |
| 2007 grand_child3->SetOpacity(0.5f); | |
| 2008 grand_child4->SetOpacity(0.5f); | |
| 2009 | |
| 2010 RenderSurfaceLayerList render_surface_layer_list; | |
| 2011 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 2012 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 2013 inputs.can_adjust_raster_scales = true; | |
| 2014 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 2015 | |
| 2016 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); | |
| 2017 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); | |
| 2018 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); | |
| 2019 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); | |
| 2020 } | |
| 2021 | |
| 2022 TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { | |
| 2023 // Verify that render surfaces (and their layers) get the appropriate | |
| 2024 // clip rects when their parent masksToBounds is true. | |
| 2025 // | |
| 2026 // Layers that own render surfaces (at least for now) do not inherit any | |
| 2027 // clipping; instead the surface will enforce the clip for the entire subtree. | |
| 2028 // They may still have a clip rect of their own layer bounds, however, if | |
| 2029 // masksToBounds was true. | |
| 2030 const gfx::Transform identity_matrix; | |
| 2031 scoped_refptr<Layer> parent = Layer::Create(); | |
| 2032 scoped_refptr<Layer> child = Layer::Create(); | |
| 2033 scoped_refptr<Layer> grand_child1 = Layer::Create(); | |
| 2034 scoped_refptr<Layer> grand_child2 = Layer::Create(); | |
| 2035 scoped_refptr<Layer> grand_child3 = Layer::Create(); | |
| 2036 scoped_refptr<Layer> grand_child4 = Layer::Create(); | |
| 2037 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = | |
| 2038 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2039 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = | |
| 2040 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2041 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 = | |
| 2042 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2043 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 = | |
| 2044 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2045 | |
| 2046 parent->AddChild(child); | |
| 2047 child->AddChild(grand_child1); | |
| 2048 child->AddChild(grand_child2); | |
| 2049 child->AddChild(grand_child3); | |
| 2050 child->AddChild(grand_child4); | |
| 2051 | |
| 2052 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 2053 host->SetRootLayer(parent); | |
| 2054 | |
| 2055 // the leaf nodes ensure that these grand_children become render surfaces for | |
| 2056 // this test. | |
| 2057 grand_child1->AddChild(leaf_node1); | |
| 2058 grand_child2->AddChild(leaf_node2); | |
| 2059 grand_child3->AddChild(leaf_node3); | |
| 2060 grand_child4->AddChild(leaf_node4); | |
| 2061 | |
| 2062 SetLayerPropertiesForTesting(parent.get(), | |
| 2063 identity_matrix, | |
| 2064 gfx::Point3F(), | |
| 2065 gfx::PointF(), | |
| 2066 gfx::Size(500, 500), | |
| 2067 true, | |
| 2068 false); | |
| 2069 SetLayerPropertiesForTesting(child.get(), | |
| 2070 identity_matrix, | |
| 2071 gfx::Point3F(), | |
| 2072 gfx::PointF(), | |
| 2073 gfx::Size(20, 20), | |
| 2074 true, | |
| 2075 false); | |
| 2076 SetLayerPropertiesForTesting(grand_child1.get(), | |
| 2077 identity_matrix, | |
| 2078 gfx::Point3F(), | |
| 2079 gfx::PointF(5.f, 5.f), | |
| 2080 gfx::Size(10, 10), | |
| 2081 true, | |
| 2082 false); | |
| 2083 SetLayerPropertiesForTesting(grand_child2.get(), | |
| 2084 identity_matrix, | |
| 2085 gfx::Point3F(), | |
| 2086 gfx::PointF(15.f, 15.f), | |
| 2087 gfx::Size(10, 10), | |
| 2088 true, | |
| 2089 false); | |
| 2090 SetLayerPropertiesForTesting(grand_child3.get(), | |
| 2091 identity_matrix, | |
| 2092 gfx::Point3F(), | |
| 2093 gfx::PointF(15.f, 15.f), | |
| 2094 gfx::Size(10, 10), | |
| 2095 true, | |
| 2096 false); | |
| 2097 SetLayerPropertiesForTesting(grand_child4.get(), | |
| 2098 identity_matrix, | |
| 2099 gfx::Point3F(), | |
| 2100 gfx::PointF(45.f, 45.f), | |
| 2101 gfx::Size(10, 10), | |
| 2102 true, | |
| 2103 false); | |
| 2104 SetLayerPropertiesForTesting(leaf_node1.get(), | |
| 2105 identity_matrix, | |
| 2106 gfx::Point3F(), | |
| 2107 gfx::PointF(), | |
| 2108 gfx::Size(10, 10), | |
| 2109 true, | |
| 2110 false); | |
| 2111 SetLayerPropertiesForTesting(leaf_node2.get(), | |
| 2112 identity_matrix, | |
| 2113 gfx::Point3F(), | |
| 2114 gfx::PointF(), | |
| 2115 gfx::Size(10, 10), | |
| 2116 true, | |
| 2117 false); | |
| 2118 SetLayerPropertiesForTesting(leaf_node3.get(), | |
| 2119 identity_matrix, | |
| 2120 gfx::Point3F(), | |
| 2121 gfx::PointF(), | |
| 2122 gfx::Size(10, 10), | |
| 2123 true, | |
| 2124 false); | |
| 2125 SetLayerPropertiesForTesting(leaf_node4.get(), | |
| 2126 identity_matrix, | |
| 2127 gfx::Point3F(), | |
| 2128 gfx::PointF(), | |
| 2129 gfx::Size(10, 10), | |
| 2130 true, | |
| 2131 false); | |
| 2132 | |
| 2133 child->SetMasksToBounds(true); | |
| 2134 grand_child3->SetMasksToBounds(true); | |
| 2135 grand_child4->SetMasksToBounds(true); | |
| 2136 | |
| 2137 // Force everyone to be a render surface. | |
| 2138 child->SetOpacity(0.4f); | |
| 2139 child->SetForceRenderSurface(true); | |
| 2140 grand_child1->SetOpacity(0.5f); | |
| 2141 grand_child1->SetForceRenderSurface(true); | |
| 2142 grand_child2->SetOpacity(0.5f); | |
| 2143 grand_child2->SetForceRenderSurface(true); | |
| 2144 grand_child3->SetOpacity(0.5f); | |
| 2145 grand_child3->SetForceRenderSurface(true); | |
| 2146 grand_child4->SetOpacity(0.5f); | |
| 2147 grand_child4->SetForceRenderSurface(true); | |
| 2148 | |
| 2149 RenderSurfaceLayerList render_surface_layer_list; | |
| 2150 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 2151 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 2152 inputs.can_adjust_raster_scales = true; | |
| 2153 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 2154 ASSERT_TRUE(grand_child1->render_surface()); | |
| 2155 ASSERT_TRUE(grand_child2->render_surface()); | |
| 2156 ASSERT_TRUE(grand_child3->render_surface()); | |
| 2157 | |
| 2158 // Surfaces are clipped by their parent, but un-affected by the owning layer's | |
| 2159 // masksToBounds. | |
| 2160 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), | |
| 2161 grand_child1->render_surface()->clip_rect()); | |
| 2162 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), | |
| 2163 grand_child2->render_surface()->clip_rect()); | |
| 2164 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), | |
| 2165 grand_child3->render_surface()->clip_rect()); | |
| 2166 } | |
| 2167 | |
| 2168 TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { | |
| 2169 scoped_refptr<Layer> parent = Layer::Create(); | |
| 2170 scoped_refptr<Layer> render_surface1 = Layer::Create(); | |
| 2171 scoped_refptr<Layer> render_surface2 = Layer::Create(); | |
| 2172 scoped_refptr<Layer> child_of_root = Layer::Create(); | |
| 2173 scoped_refptr<Layer> child_of_rs1 = Layer::Create(); | |
| 2174 scoped_refptr<Layer> child_of_rs2 = Layer::Create(); | |
| 2175 scoped_refptr<Layer> grand_child_of_root = Layer::Create(); | |
| 2176 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = | |
| 2177 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2178 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = | |
| 2179 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2180 parent->AddChild(render_surface1); | |
| 2181 parent->AddChild(child_of_root); | |
| 2182 render_surface1->AddChild(child_of_rs1); | |
| 2183 render_surface1->AddChild(render_surface2); | |
| 2184 render_surface2->AddChild(child_of_rs2); | |
| 2185 child_of_root->AddChild(grand_child_of_root); | |
| 2186 child_of_rs1->AddChild(grand_child_of_rs1); | |
| 2187 child_of_rs2->AddChild(grand_child_of_rs2); | |
| 2188 | |
| 2189 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 2190 host->SetRootLayer(parent); | |
| 2191 | |
| 2192 // Make our render surfaces. | |
| 2193 render_surface1->SetForceRenderSurface(true); | |
| 2194 render_surface2->SetForceRenderSurface(true); | |
| 2195 | |
| 2196 gfx::Transform layer_transform; | |
| 2197 layer_transform.Translate(1.0, 1.0); | |
| 2198 | |
| 2199 SetLayerPropertiesForTesting(parent.get(), | |
| 2200 layer_transform, | |
| 2201 gfx::Point3F(0.25f, 0.f, 0.f), | |
| 2202 gfx::PointF(2.5f, 0.f), | |
| 2203 gfx::Size(10, 10), | |
| 2204 true, | |
| 2205 false); | |
| 2206 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 2207 layer_transform, | |
| 2208 gfx::Point3F(0.25f, 0.f, 0.f), | |
| 2209 gfx::PointF(2.5f, 0.f), | |
| 2210 gfx::Size(10, 10), | |
| 2211 true, | |
| 2212 false); | |
| 2213 SetLayerPropertiesForTesting(render_surface2.get(), | |
| 2214 layer_transform, | |
| 2215 gfx::Point3F(0.25f, 0.f, 0.f), | |
| 2216 gfx::PointF(2.5f, 0.f), | |
| 2217 gfx::Size(10, 10), | |
| 2218 true, | |
| 2219 false); | |
| 2220 SetLayerPropertiesForTesting(child_of_root.get(), | |
| 2221 layer_transform, | |
| 2222 gfx::Point3F(0.25f, 0.f, 0.f), | |
| 2223 gfx::PointF(2.5f, 0.f), | |
| 2224 gfx::Size(10, 10), | |
| 2225 true, | |
| 2226 false); | |
| 2227 SetLayerPropertiesForTesting(child_of_rs1.get(), | |
| 2228 layer_transform, | |
| 2229 gfx::Point3F(0.25f, 0.f, 0.f), | |
| 2230 gfx::PointF(2.5f, 0.f), | |
| 2231 gfx::Size(10, 10), | |
| 2232 true, | |
| 2233 false); | |
| 2234 SetLayerPropertiesForTesting(child_of_rs2.get(), | |
| 2235 layer_transform, | |
| 2236 gfx::Point3F(0.25f, 0.f, 0.f), | |
| 2237 gfx::PointF(2.5f, 0.f), | |
| 2238 gfx::Size(10, 10), | |
| 2239 true, | |
| 2240 false); | |
| 2241 SetLayerPropertiesForTesting(grand_child_of_root.get(), | |
| 2242 layer_transform, | |
| 2243 gfx::Point3F(0.25f, 0.f, 0.f), | |
| 2244 gfx::PointF(2.5f, 0.f), | |
| 2245 gfx::Size(10, 10), | |
| 2246 true, | |
| 2247 false); | |
| 2248 SetLayerPropertiesForTesting(grand_child_of_rs1.get(), | |
| 2249 layer_transform, | |
| 2250 gfx::Point3F(0.25f, 0.f, 0.f), | |
| 2251 gfx::PointF(2.5f, 0.f), | |
| 2252 gfx::Size(10, 10), | |
| 2253 true, | |
| 2254 false); | |
| 2255 SetLayerPropertiesForTesting(grand_child_of_rs2.get(), | |
| 2256 layer_transform, | |
| 2257 gfx::Point3F(0.25f, 0.f, 0.f), | |
| 2258 gfx::PointF(2.5f, 0.f), | |
| 2259 gfx::Size(10, 10), | |
| 2260 true, | |
| 2261 false); | |
| 2262 | |
| 2263 // Put an animated opacity on the render surface. | |
| 2264 AddOpacityTransitionToController( | |
| 2265 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false); | |
| 2266 | |
| 2267 // Also put an animated opacity on a layer without descendants. | |
| 2268 AddOpacityTransitionToController( | |
| 2269 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false); | |
| 2270 | |
| 2271 // Put a transform animation on the render surface. | |
| 2272 AddAnimatedTransformToController( | |
| 2273 render_surface2->layer_animation_controller(), 10.0, 30, 0); | |
| 2274 | |
| 2275 // Also put transform animations on grand_child_of_root, and | |
| 2276 // grand_child_of_rs2 | |
| 2277 AddAnimatedTransformToController( | |
| 2278 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0); | |
| 2279 AddAnimatedTransformToController( | |
| 2280 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0); | |
| 2281 | |
| 2282 ExecuteCalculateDrawProperties(parent.get()); | |
| 2283 | |
| 2284 // Only layers that are associated with render surfaces should have an actual | |
| 2285 // RenderSurface() value. | |
| 2286 ASSERT_TRUE(parent->render_surface()); | |
| 2287 ASSERT_FALSE(child_of_root->render_surface()); | |
| 2288 ASSERT_FALSE(grand_child_of_root->render_surface()); | |
| 2289 | |
| 2290 ASSERT_TRUE(render_surface1->render_surface()); | |
| 2291 ASSERT_FALSE(child_of_rs1->render_surface()); | |
| 2292 ASSERT_FALSE(grand_child_of_rs1->render_surface()); | |
| 2293 | |
| 2294 ASSERT_TRUE(render_surface2->render_surface()); | |
| 2295 ASSERT_FALSE(child_of_rs2->render_surface()); | |
| 2296 ASSERT_FALSE(grand_child_of_rs2->render_surface()); | |
| 2297 | |
| 2298 // Verify all render target accessors | |
| 2299 EXPECT_EQ(parent.get(), parent->render_target()); | |
| 2300 EXPECT_EQ(parent.get(), child_of_root->render_target()); | |
| 2301 EXPECT_EQ(parent.get(), grand_child_of_root->render_target()); | |
| 2302 | |
| 2303 EXPECT_EQ(render_surface1.get(), render_surface1->render_target()); | |
| 2304 EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target()); | |
| 2305 EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target()); | |
| 2306 | |
| 2307 EXPECT_EQ(render_surface2.get(), render_surface2->render_target()); | |
| 2308 EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target()); | |
| 2309 EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target()); | |
| 2310 | |
| 2311 // Verify draw_opacity_is_animating values | |
| 2312 EXPECT_FALSE(parent->draw_opacity_is_animating()); | |
| 2313 EXPECT_FALSE(child_of_root->draw_opacity_is_animating()); | |
| 2314 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating()); | |
| 2315 EXPECT_FALSE(render_surface1->draw_opacity_is_animating()); | |
| 2316 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating()); | |
| 2317 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating()); | |
| 2318 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating()); | |
| 2319 EXPECT_FALSE(render_surface2->draw_opacity_is_animating()); | |
| 2320 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating()); | |
| 2321 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating()); | |
| 2322 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating()); | |
| 2323 | |
| 2324 // Verify draw_transform_is_animating values | |
| 2325 EXPECT_FALSE(parent->draw_transform_is_animating()); | |
| 2326 EXPECT_FALSE(child_of_root->draw_transform_is_animating()); | |
| 2327 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating()); | |
| 2328 EXPECT_FALSE(render_surface1->draw_transform_is_animating()); | |
| 2329 EXPECT_FALSE(render_surface1->render_surface() | |
| 2330 ->target_surface_transforms_are_animating()); | |
| 2331 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating()); | |
| 2332 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating()); | |
| 2333 EXPECT_FALSE(render_surface2->draw_transform_is_animating()); | |
| 2334 EXPECT_TRUE(render_surface2->render_surface() | |
| 2335 ->target_surface_transforms_are_animating()); | |
| 2336 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating()); | |
| 2337 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating()); | |
| 2338 | |
| 2339 // Verify screen_space_transform_is_animating values | |
| 2340 EXPECT_FALSE(parent->screen_space_transform_is_animating()); | |
| 2341 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); | |
| 2342 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); | |
| 2343 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); | |
| 2344 EXPECT_FALSE(render_surface1->render_surface() | |
| 2345 ->screen_space_transforms_are_animating()); | |
| 2346 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); | |
| 2347 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); | |
| 2348 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); | |
| 2349 EXPECT_TRUE(render_surface2->render_surface() | |
| 2350 ->screen_space_transforms_are_animating()); | |
| 2351 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); | |
| 2352 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); | |
| 2353 | |
| 2354 // Sanity check. If these fail there is probably a bug in the test itself. | |
| 2355 // It is expected that we correctly set up transforms so that the y-component | |
| 2356 // of the screen-space transform encodes the "depth" of the layer in the tree. | |
| 2357 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); | |
| 2358 EXPECT_FLOAT_EQ(2.0, | |
| 2359 child_of_root->screen_space_transform().matrix().get(1, 3)); | |
| 2360 EXPECT_FLOAT_EQ( | |
| 2361 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); | |
| 2362 | |
| 2363 EXPECT_FLOAT_EQ(2.0, | |
| 2364 render_surface1->screen_space_transform().matrix().get(1, 3)); | |
| 2365 EXPECT_FLOAT_EQ(3.0, | |
| 2366 child_of_rs1->screen_space_transform().matrix().get(1, 3)); | |
| 2367 EXPECT_FLOAT_EQ( | |
| 2368 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); | |
| 2369 | |
| 2370 EXPECT_FLOAT_EQ(3.0, | |
| 2371 render_surface2->screen_space_transform().matrix().get(1, 3)); | |
| 2372 EXPECT_FLOAT_EQ(4.0, | |
| 2373 child_of_rs2->screen_space_transform().matrix().get(1, 3)); | |
| 2374 EXPECT_FLOAT_EQ( | |
| 2375 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); | |
| 2376 } | |
| 2377 | |
| 2378 TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { | |
| 2379 // Test the calculateVisibleRect() function works correctly for identity | |
| 2380 // transforms. | |
| 2381 | |
| 2382 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); | |
| 2383 gfx::Transform layer_to_surface_transform; | |
| 2384 | |
| 2385 // Case 1: Layer is contained within the surface. | |
| 2386 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); | |
| 2387 gfx::Rect expected = gfx::Rect(10, 10, 30, 30); | |
| 2388 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2389 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2390 EXPECT_EQ(expected, actual); | |
| 2391 | |
| 2392 // Case 2: Layer is outside the surface rect. | |
| 2393 layer_content_rect = gfx::Rect(120, 120, 30, 30); | |
| 2394 actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2395 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2396 EXPECT_TRUE(actual.IsEmpty()); | |
| 2397 | |
| 2398 // Case 3: Layer is partially overlapping the surface rect. | |
| 2399 layer_content_rect = gfx::Rect(80, 80, 30, 30); | |
| 2400 expected = gfx::Rect(80, 80, 20, 20); | |
| 2401 actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2402 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2403 EXPECT_EQ(expected, actual); | |
| 2404 } | |
| 2405 | |
| 2406 TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) { | |
| 2407 // Test the calculateVisibleRect() function works correctly for scaling | |
| 2408 // transforms. | |
| 2409 | |
| 2410 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); | |
| 2411 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); | |
| 2412 gfx::Transform layer_to_surface_transform; | |
| 2413 | |
| 2414 // Case 1: Layer is contained within the surface. | |
| 2415 layer_to_surface_transform.MakeIdentity(); | |
| 2416 layer_to_surface_transform.Translate(10.0, 10.0); | |
| 2417 gfx::Rect expected = gfx::Rect(0, 0, 30, 30); | |
| 2418 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2419 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2420 EXPECT_EQ(expected, actual); | |
| 2421 | |
| 2422 // Case 2: Layer is outside the surface rect. | |
| 2423 layer_to_surface_transform.MakeIdentity(); | |
| 2424 layer_to_surface_transform.Translate(120.0, 120.0); | |
| 2425 actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2426 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2427 EXPECT_TRUE(actual.IsEmpty()); | |
| 2428 | |
| 2429 // Case 3: Layer is partially overlapping the surface rect. | |
| 2430 layer_to_surface_transform.MakeIdentity(); | |
| 2431 layer_to_surface_transform.Translate(80.0, 80.0); | |
| 2432 expected = gfx::Rect(0, 0, 20, 20); | |
| 2433 actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2434 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2435 EXPECT_EQ(expected, actual); | |
| 2436 } | |
| 2437 | |
| 2438 TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) { | |
| 2439 // Test the calculateVisibleRect() function works correctly for rotations | |
| 2440 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect() | |
| 2441 // should return the g in the layer's space. | |
| 2442 | |
| 2443 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); | |
| 2444 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); | |
| 2445 gfx::Transform layer_to_surface_transform; | |
| 2446 | |
| 2447 // Case 1: Layer is contained within the surface. | |
| 2448 layer_to_surface_transform.MakeIdentity(); | |
| 2449 layer_to_surface_transform.Translate(50.0, 50.0); | |
| 2450 layer_to_surface_transform.Rotate(45.0); | |
| 2451 gfx::Rect expected = gfx::Rect(0, 0, 30, 30); | |
| 2452 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2453 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2454 EXPECT_EQ(expected, actual); | |
| 2455 | |
| 2456 // Case 2: Layer is outside the surface rect. | |
| 2457 layer_to_surface_transform.MakeIdentity(); | |
| 2458 layer_to_surface_transform.Translate(-50.0, 0.0); | |
| 2459 layer_to_surface_transform.Rotate(45.0); | |
| 2460 actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2461 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2462 EXPECT_TRUE(actual.IsEmpty()); | |
| 2463 | |
| 2464 // Case 3: The layer is rotated about its top-left corner. In surface space, | |
| 2465 // the layer is oriented diagonally, with the left half outside of the render | |
| 2466 // surface. In this case, the g should still be the entire layer | |
| 2467 // (remember the g is computed in layer space); both the top-left | |
| 2468 // and bottom-right corners of the layer are still visible. | |
| 2469 layer_to_surface_transform.MakeIdentity(); | |
| 2470 layer_to_surface_transform.Rotate(45.0); | |
| 2471 expected = gfx::Rect(0, 0, 30, 30); | |
| 2472 actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2473 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2474 EXPECT_EQ(expected, actual); | |
| 2475 | |
| 2476 // Case 4: The layer is rotated about its top-left corner, and translated | |
| 2477 // upwards. In surface space, the layer is oriented diagonally, with only the | |
| 2478 // top corner of the surface overlapping the layer. In layer space, the render | |
| 2479 // surface overlaps the right side of the layer. The g should be | |
| 2480 // the layer's right half. | |
| 2481 layer_to_surface_transform.MakeIdentity(); | |
| 2482 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); | |
| 2483 layer_to_surface_transform.Rotate(45.0); | |
| 2484 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds. | |
| 2485 actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2486 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2487 EXPECT_EQ(expected, actual); | |
| 2488 } | |
| 2489 | |
| 2490 TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) { | |
| 2491 // Test that the calculateVisibleRect() function works correctly for 3d | |
| 2492 // transforms. | |
| 2493 | |
| 2494 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); | |
| 2495 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); | |
| 2496 gfx::Transform layer_to_surface_transform; | |
| 2497 | |
| 2498 // Case 1: Orthographic projection of a layer rotated about y-axis by 45 | |
| 2499 // degrees, should be fully contained in the render surface. | |
| 2500 layer_to_surface_transform.MakeIdentity(); | |
| 2501 layer_to_surface_transform.RotateAboutYAxis(45.0); | |
| 2502 gfx::Rect expected = gfx::Rect(0, 0, 100, 100); | |
| 2503 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2504 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2505 EXPECT_EQ(expected, actual); | |
| 2506 | |
| 2507 // Case 2: Orthographic projection of a layer rotated about y-axis by 45 | |
| 2508 // degrees, but shifted to the side so only the right-half the layer would be | |
| 2509 // visible on the surface. | |
| 2510 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width. | |
| 2511 SkMScalar half_width_of_rotated_layer = | |
| 2512 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); | |
| 2513 layer_to_surface_transform.MakeIdentity(); | |
| 2514 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); | |
| 2515 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left | |
| 2516 // edge of the layer. | |
| 2517 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer. | |
| 2518 actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2519 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2520 EXPECT_EQ(expected, actual); | |
| 2521 } | |
| 2522 | |
| 2523 TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) { | |
| 2524 // Test the calculateVisibleRect() function works correctly when the layer has | |
| 2525 // a perspective projection onto the target surface. | |
| 2526 | |
| 2527 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); | |
| 2528 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); | |
| 2529 gfx::Transform layer_to_surface_transform; | |
| 2530 | |
| 2531 // Case 1: Even though the layer is twice as large as the surface, due to | |
| 2532 // perspective foreshortening, the layer will fit fully in the surface when | |
| 2533 // its translated more than the perspective amount. | |
| 2534 layer_to_surface_transform.MakeIdentity(); | |
| 2535 | |
| 2536 // The following sequence of transforms applies the perspective about the | |
| 2537 // center of the surface. | |
| 2538 layer_to_surface_transform.Translate(50.0, 50.0); | |
| 2539 layer_to_surface_transform.ApplyPerspectiveDepth(9.0); | |
| 2540 layer_to_surface_transform.Translate(-50.0, -50.0); | |
| 2541 | |
| 2542 // This translate places the layer in front of the surface's projection plane. | |
| 2543 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); | |
| 2544 | |
| 2545 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200); | |
| 2546 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2547 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2548 EXPECT_EQ(expected, actual); | |
| 2549 | |
| 2550 // Case 2: same projection as before, except that the layer is also translated | |
| 2551 // to the side, so that only the right half of the layer should be visible. | |
| 2552 // | |
| 2553 // Explanation of expected result: The perspective ratio is (z distance | |
| 2554 // between layer and camera origin) / (z distance between projection plane and | |
| 2555 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to | |
| 2556 // move a layer by translating -50 units in projected surface units (so that | |
| 2557 // only half of it is visible), then we would need to translate by (-36 / 9) * | |
| 2558 // -50 == -200 in the layer's units. | |
| 2559 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0); | |
| 2560 expected = gfx::Rect(gfx::Point(50, -50), | |
| 2561 gfx::Size(100, 200)); // The right half of the layer's | |
| 2562 // bounding rect. | |
| 2563 actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2564 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2565 EXPECT_EQ(expected, actual); | |
| 2566 } | |
| 2567 | |
| 2568 TEST_F(LayerTreeHostCommonTest, | |
| 2569 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) { | |
| 2570 // There is currently no explicit concept of an orthographic projection plane | |
| 2571 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that | |
| 2572 // are technically behind the surface in an orthographic world should not be | |
| 2573 // clipped when they are flattened to the surface. | |
| 2574 | |
| 2575 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); | |
| 2576 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); | |
| 2577 gfx::Transform layer_to_surface_transform; | |
| 2578 | |
| 2579 // This sequence of transforms effectively rotates the layer about the y-axis | |
| 2580 // at the center of the layer. | |
| 2581 layer_to_surface_transform.MakeIdentity(); | |
| 2582 layer_to_surface_transform.Translate(50.0, 0.0); | |
| 2583 layer_to_surface_transform.RotateAboutYAxis(45.0); | |
| 2584 layer_to_surface_transform.Translate(-50.0, 0.0); | |
| 2585 | |
| 2586 gfx::Rect expected = gfx::Rect(0, 0, 100, 100); | |
| 2587 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2588 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2589 EXPECT_EQ(expected, actual); | |
| 2590 } | |
| 2591 | |
| 2592 TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) { | |
| 2593 // Test the calculateVisibleRect() function works correctly when projecting a | |
| 2594 // surface onto a layer, but the layer is partially behind the camera (not | |
| 2595 // just behind the projection plane). In this case, the cartesian coordinates | |
| 2596 // may seem to be valid, but actually they are not. The visible rect needs to | |
| 2597 // be properly clipped by the w = 0 plane in homogeneous coordinates before | |
| 2598 // converting to cartesian coordinates. | |
| 2599 | |
| 2600 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); | |
| 2601 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2); | |
| 2602 gfx::Transform layer_to_surface_transform; | |
| 2603 | |
| 2604 // The layer is positioned so that the right half of the layer should be in | |
| 2605 // front of the camera, while the other half is behind the surface's | |
| 2606 // projection plane. The following sequence of transforms applies the | |
| 2607 // perspective and rotation about the center of the layer. | |
| 2608 layer_to_surface_transform.MakeIdentity(); | |
| 2609 layer_to_surface_transform.ApplyPerspectiveDepth(1.0); | |
| 2610 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0); | |
| 2611 layer_to_surface_transform.RotateAboutYAxis(45.0); | |
| 2612 | |
| 2613 // Sanity check that this transform does indeed cause w < 0 when applying the | |
| 2614 // transform, otherwise this code is not testing the intended scenario. | |
| 2615 bool clipped; | |
| 2616 MathUtil::MapQuad(layer_to_surface_transform, | |
| 2617 gfx::QuadF(gfx::RectF(layer_content_rect)), | |
| 2618 &clipped); | |
| 2619 ASSERT_TRUE(clipped); | |
| 2620 | |
| 2621 int expected_x_position = 0; | |
| 2622 int expected_width = 10; | |
| 2623 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2624 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2625 EXPECT_EQ(expected_x_position, actual.x()); | |
| 2626 EXPECT_EQ(expected_width, actual.width()); | |
| 2627 } | |
| 2628 | |
| 2629 TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) { | |
| 2630 // To determine visible rect in layer space, there needs to be an | |
| 2631 // un-projection from surface space to layer space. When the original | |
| 2632 // transform was a perspective projection that was clipped, it returns a rect | |
| 2633 // that encloses the clipped bounds. Un-projecting this new rect may require | |
| 2634 // clipping again. | |
| 2635 | |
| 2636 // This sequence of transforms causes one corner of the layer to protrude | |
| 2637 // across the w = 0 plane, and should be clipped. | |
| 2638 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); | |
| 2639 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20); | |
| 2640 gfx::Transform layer_to_surface_transform; | |
| 2641 layer_to_surface_transform.MakeIdentity(); | |
| 2642 layer_to_surface_transform.ApplyPerspectiveDepth(1.0); | |
| 2643 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); | |
| 2644 layer_to_surface_transform.RotateAboutYAxis(45.0); | |
| 2645 layer_to_surface_transform.RotateAboutXAxis(80.0); | |
| 2646 | |
| 2647 // Sanity check that un-projection does indeed cause w < 0, otherwise this | |
| 2648 // code is not testing the intended scenario. | |
| 2649 bool clipped; | |
| 2650 gfx::RectF clipped_rect = | |
| 2651 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect); | |
| 2652 MathUtil::ProjectQuad( | |
| 2653 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); | |
| 2654 ASSERT_TRUE(clipped); | |
| 2655 | |
| 2656 // Only the corner of the layer is not visible on the surface because of being | |
| 2657 // clipped. But, the net result of rounding visible region to an axis-aligned | |
| 2658 // rect is that the entire layer should still be considered visible. | |
| 2659 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); | |
| 2660 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( | |
| 2661 target_surface_rect, layer_content_rect, layer_to_surface_transform); | |
| 2662 EXPECT_EQ(expected, actual); | |
| 2663 } | |
| 2664 | |
| 2665 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { | |
| 2666 scoped_refptr<Layer> root = Layer::Create(); | |
| 2667 scoped_refptr<LayerWithForcedDrawsContent> child1 = | |
| 2668 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2669 scoped_refptr<LayerWithForcedDrawsContent> child2 = | |
| 2670 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2671 scoped_refptr<LayerWithForcedDrawsContent> child3 = | |
| 2672 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2673 root->AddChild(child1); | |
| 2674 root->AddChild(child2); | |
| 2675 root->AddChild(child3); | |
| 2676 | |
| 2677 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 2678 host->SetRootLayer(root); | |
| 2679 | |
| 2680 gfx::Transform identity_matrix; | |
| 2681 SetLayerPropertiesForTesting(root.get(), | |
| 2682 identity_matrix, | |
| 2683 gfx::Point3F(), | |
| 2684 gfx::PointF(), | |
| 2685 gfx::Size(100, 100), | |
| 2686 true, | |
| 2687 false); | |
| 2688 SetLayerPropertiesForTesting(child1.get(), | |
| 2689 identity_matrix, | |
| 2690 gfx::Point3F(), | |
| 2691 gfx::PointF(), | |
| 2692 gfx::Size(50, 50), | |
| 2693 true, | |
| 2694 false); | |
| 2695 SetLayerPropertiesForTesting(child2.get(), | |
| 2696 identity_matrix, | |
| 2697 gfx::Point3F(), | |
| 2698 gfx::PointF(75.f, 75.f), | |
| 2699 gfx::Size(50, 50), | |
| 2700 true, | |
| 2701 false); | |
| 2702 SetLayerPropertiesForTesting(child3.get(), | |
| 2703 identity_matrix, | |
| 2704 gfx::Point3F(), | |
| 2705 gfx::PointF(125.f, 125.f), | |
| 2706 gfx::Size(50, 50), | |
| 2707 true, | |
| 2708 false); | |
| 2709 | |
| 2710 ExecuteCalculateDrawProperties(root.get()); | |
| 2711 | |
| 2712 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | |
| 2713 root->render_surface()->DrawableContentRect()); | |
| 2714 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); | |
| 2715 | |
| 2716 // Layers that do not draw content should have empty visible_content_rects. | |
| 2717 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); | |
| 2718 | |
| 2719 // layer visible_content_rects are clipped by their target surface. | |
| 2720 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); | |
| 2721 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); | |
| 2722 EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); | |
| 2723 | |
| 2724 // layer drawable_content_rects are not clipped. | |
| 2725 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect()); | |
| 2726 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); | |
| 2727 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); | |
| 2728 } | |
| 2729 | |
| 2730 TEST_F(LayerTreeHostCommonTest, | |
| 2731 DrawableAndVisibleContentRectsForLayersClippedByLayer) { | |
| 2732 scoped_refptr<Layer> root = Layer::Create(); | |
| 2733 scoped_refptr<Layer> child = Layer::Create(); | |
| 2734 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 = | |
| 2735 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2736 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 = | |
| 2737 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2738 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 = | |
| 2739 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2740 root->AddChild(child); | |
| 2741 child->AddChild(grand_child1); | |
| 2742 child->AddChild(grand_child2); | |
| 2743 child->AddChild(grand_child3); | |
| 2744 | |
| 2745 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 2746 host->SetRootLayer(root); | |
| 2747 | |
| 2748 gfx::Transform identity_matrix; | |
| 2749 SetLayerPropertiesForTesting(root.get(), | |
| 2750 identity_matrix, | |
| 2751 gfx::Point3F(), | |
| 2752 gfx::PointF(), | |
| 2753 gfx::Size(100, 100), | |
| 2754 true, | |
| 2755 false); | |
| 2756 SetLayerPropertiesForTesting(child.get(), | |
| 2757 identity_matrix, | |
| 2758 gfx::Point3F(), | |
| 2759 gfx::PointF(), | |
| 2760 gfx::Size(100, 100), | |
| 2761 true, | |
| 2762 false); | |
| 2763 SetLayerPropertiesForTesting(grand_child1.get(), | |
| 2764 identity_matrix, | |
| 2765 gfx::Point3F(), | |
| 2766 gfx::PointF(5.f, 5.f), | |
| 2767 gfx::Size(50, 50), | |
| 2768 true, | |
| 2769 false); | |
| 2770 SetLayerPropertiesForTesting(grand_child2.get(), | |
| 2771 identity_matrix, | |
| 2772 gfx::Point3F(), | |
| 2773 gfx::PointF(75.f, 75.f), | |
| 2774 gfx::Size(50, 50), | |
| 2775 true, | |
| 2776 false); | |
| 2777 SetLayerPropertiesForTesting(grand_child3.get(), | |
| 2778 identity_matrix, | |
| 2779 gfx::Point3F(), | |
| 2780 gfx::PointF(125.f, 125.f), | |
| 2781 gfx::Size(50, 50), | |
| 2782 true, | |
| 2783 false); | |
| 2784 | |
| 2785 child->SetMasksToBounds(true); | |
| 2786 ExecuteCalculateDrawProperties(root.get()); | |
| 2787 | |
| 2788 ASSERT_FALSE(child->render_surface()); | |
| 2789 | |
| 2790 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | |
| 2791 root->render_surface()->DrawableContentRect()); | |
| 2792 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); | |
| 2793 | |
| 2794 // Layers that do not draw content should have empty visible content rects. | |
| 2795 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); | |
| 2796 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect()); | |
| 2797 | |
| 2798 // All grandchild visible content rects should be clipped by child. | |
| 2799 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect()); | |
| 2800 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect()); | |
| 2801 EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty()); | |
| 2802 | |
| 2803 // All grandchild DrawableContentRects should also be clipped by child. | |
| 2804 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); | |
| 2805 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); | |
| 2806 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); | |
| 2807 } | |
| 2808 | |
| 2809 TEST_F(LayerTreeHostCommonTest, | |
| 2810 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { | |
| 2811 scoped_refptr<Layer> root = Layer::Create(); | |
| 2812 scoped_refptr<Layer> render_surface1 = Layer::Create(); | |
| 2813 scoped_refptr<LayerWithForcedDrawsContent> child1 = | |
| 2814 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2815 scoped_refptr<LayerWithForcedDrawsContent> child2 = | |
| 2816 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2817 scoped_refptr<LayerWithForcedDrawsContent> child3 = | |
| 2818 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2819 root->AddChild(render_surface1); | |
| 2820 render_surface1->AddChild(child1); | |
| 2821 render_surface1->AddChild(child2); | |
| 2822 render_surface1->AddChild(child3); | |
| 2823 | |
| 2824 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 2825 host->SetRootLayer(root); | |
| 2826 | |
| 2827 gfx::Transform identity_matrix; | |
| 2828 SetLayerPropertiesForTesting(root.get(), | |
| 2829 identity_matrix, | |
| 2830 gfx::Point3F(), | |
| 2831 gfx::PointF(), | |
| 2832 gfx::Size(100, 100), | |
| 2833 true, | |
| 2834 false); | |
| 2835 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 2836 identity_matrix, | |
| 2837 gfx::Point3F(), | |
| 2838 gfx::PointF(), | |
| 2839 gfx::Size(3, 4), | |
| 2840 true, | |
| 2841 false); | |
| 2842 SetLayerPropertiesForTesting(child1.get(), | |
| 2843 identity_matrix, | |
| 2844 gfx::Point3F(), | |
| 2845 gfx::PointF(5.f, 5.f), | |
| 2846 gfx::Size(50, 50), | |
| 2847 true, | |
| 2848 false); | |
| 2849 SetLayerPropertiesForTesting(child2.get(), | |
| 2850 identity_matrix, | |
| 2851 gfx::Point3F(), | |
| 2852 gfx::PointF(75.f, 75.f), | |
| 2853 gfx::Size(50, 50), | |
| 2854 true, | |
| 2855 false); | |
| 2856 SetLayerPropertiesForTesting(child3.get(), | |
| 2857 identity_matrix, | |
| 2858 gfx::Point3F(), | |
| 2859 gfx::PointF(125.f, 125.f), | |
| 2860 gfx::Size(50, 50), | |
| 2861 true, | |
| 2862 false); | |
| 2863 | |
| 2864 render_surface1->SetForceRenderSurface(true); | |
| 2865 ExecuteCalculateDrawProperties(root.get()); | |
| 2866 | |
| 2867 ASSERT_TRUE(render_surface1->render_surface()); | |
| 2868 | |
| 2869 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | |
| 2870 root->render_surface()->DrawableContentRect()); | |
| 2871 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); | |
| 2872 | |
| 2873 // Layers that do not draw content should have empty visible content rects. | |
| 2874 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); | |
| 2875 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); | |
| 2876 | |
| 2877 // An unclipped surface grows its DrawableContentRect to include all drawable | |
| 2878 // regions of the subtree. | |
| 2879 EXPECT_EQ(gfx::Rect(5, 5, 170, 170), | |
| 2880 render_surface1->render_surface()->DrawableContentRect()); | |
| 2881 | |
| 2882 // All layers that draw content into the unclipped surface are also unclipped. | |
| 2883 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); | |
| 2884 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); | |
| 2885 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); | |
| 2886 | |
| 2887 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); | |
| 2888 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); | |
| 2889 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); | |
| 2890 } | |
| 2891 | |
| 2892 TEST_F(LayerTreeHostCommonTest, | |
| 2893 VisibleContentRectsForClippedSurfaceWithEmptyClip) { | |
| 2894 scoped_refptr<Layer> root = Layer::Create(); | |
| 2895 scoped_refptr<LayerWithForcedDrawsContent> child1 = | |
| 2896 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2897 scoped_refptr<LayerWithForcedDrawsContent> child2 = | |
| 2898 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2899 scoped_refptr<LayerWithForcedDrawsContent> child3 = | |
| 2900 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2901 root->AddChild(child1); | |
| 2902 root->AddChild(child2); | |
| 2903 root->AddChild(child3); | |
| 2904 | |
| 2905 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 2906 host->SetRootLayer(root); | |
| 2907 | |
| 2908 gfx::Transform identity_matrix; | |
| 2909 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), | |
| 2910 gfx::PointF(), gfx::Size(100, 100), true, false); | |
| 2911 SetLayerPropertiesForTesting(child1.get(), identity_matrix, gfx::Point3F(), | |
| 2912 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, | |
| 2913 false); | |
| 2914 SetLayerPropertiesForTesting(child2.get(), identity_matrix, gfx::Point3F(), | |
| 2915 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, | |
| 2916 false); | |
| 2917 SetLayerPropertiesForTesting(child3.get(), identity_matrix, gfx::Point3F(), | |
| 2918 gfx::PointF(125.f, 125.f), gfx::Size(50, 50), | |
| 2919 true, false); | |
| 2920 | |
| 2921 RenderSurfaceLayerList render_surface_layer_list; | |
| 2922 // Now set the root render surface an empty clip. | |
| 2923 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 2924 root.get(), gfx::Size(), &render_surface_layer_list); | |
| 2925 | |
| 2926 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 2927 ASSERT_TRUE(root->render_surface()); | |
| 2928 EXPECT_FALSE(root->is_clipped()); | |
| 2929 | |
| 2930 gfx::Rect empty; | |
| 2931 EXPECT_EQ(empty, root->render_surface()->clip_rect()); | |
| 2932 EXPECT_TRUE(root->render_surface()->is_clipped()); | |
| 2933 | |
| 2934 // Visible content rect calculation will check if the target surface is | |
| 2935 // clipped or not. An empty clip rect does not indicate the render surface | |
| 2936 // is unclipped. | |
| 2937 EXPECT_EQ(empty, child1->visible_content_rect()); | |
| 2938 EXPECT_EQ(empty, child2->visible_content_rect()); | |
| 2939 EXPECT_EQ(empty, child3->visible_content_rect()); | |
| 2940 } | |
| 2941 | |
| 2942 TEST_F(LayerTreeHostCommonTest, | |
| 2943 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { | |
| 2944 scoped_refptr<Layer> root = Layer::Create(); | |
| 2945 scoped_refptr<LayerWithForcedDrawsContent> child = | |
| 2946 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 2947 root->AddChild(child); | |
| 2948 | |
| 2949 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 2950 host->SetRootLayer(root); | |
| 2951 | |
| 2952 // Case 1: a truly degenerate matrix | |
| 2953 gfx::Transform identity_matrix; | |
| 2954 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); | |
| 2955 ASSERT_FALSE(uninvertible_matrix.IsInvertible()); | |
| 2956 | |
| 2957 SetLayerPropertiesForTesting(root.get(), | |
| 2958 identity_matrix, | |
| 2959 gfx::Point3F(), | |
| 2960 gfx::PointF(), | |
| 2961 gfx::Size(100, 100), | |
| 2962 true, | |
| 2963 false); | |
| 2964 SetLayerPropertiesForTesting(child.get(), | |
| 2965 uninvertible_matrix, | |
| 2966 gfx::Point3F(), | |
| 2967 gfx::PointF(5.f, 5.f), | |
| 2968 gfx::Size(50, 50), | |
| 2969 true, | |
| 2970 false); | |
| 2971 | |
| 2972 ExecuteCalculateDrawProperties(root.get()); | |
| 2973 | |
| 2974 EXPECT_TRUE(child->visible_content_rect().IsEmpty()); | |
| 2975 EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); | |
| 2976 | |
| 2977 // Case 2: a matrix with flattened z, uninvertible and not visible according | |
| 2978 // to the CSS spec. | |
| 2979 uninvertible_matrix.MakeIdentity(); | |
| 2980 uninvertible_matrix.matrix().set(2, 2, 0.0); | |
| 2981 ASSERT_FALSE(uninvertible_matrix.IsInvertible()); | |
| 2982 | |
| 2983 SetLayerPropertiesForTesting(child.get(), | |
| 2984 uninvertible_matrix, | |
| 2985 gfx::Point3F(), | |
| 2986 gfx::PointF(5.f, 5.f), | |
| 2987 gfx::Size(50, 50), | |
| 2988 true, | |
| 2989 false); | |
| 2990 | |
| 2991 ExecuteCalculateDrawProperties(root.get()); | |
| 2992 | |
| 2993 EXPECT_TRUE(child->visible_content_rect().IsEmpty()); | |
| 2994 EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); | |
| 2995 | |
| 2996 // Case 3: a matrix with flattened z, also uninvertible and not visible. | |
| 2997 uninvertible_matrix.MakeIdentity(); | |
| 2998 uninvertible_matrix.Translate(500.0, 0.0); | |
| 2999 uninvertible_matrix.matrix().set(2, 2, 0.0); | |
| 3000 ASSERT_FALSE(uninvertible_matrix.IsInvertible()); | |
| 3001 | |
| 3002 SetLayerPropertiesForTesting(child.get(), | |
| 3003 uninvertible_matrix, | |
| 3004 gfx::Point3F(), | |
| 3005 gfx::PointF(5.f, 5.f), | |
| 3006 gfx::Size(50, 50), | |
| 3007 true, | |
| 3008 false); | |
| 3009 | |
| 3010 ExecuteCalculateDrawProperties(root.get()); | |
| 3011 | |
| 3012 EXPECT_TRUE(child->visible_content_rect().IsEmpty()); | |
| 3013 EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); | |
| 3014 } | |
| 3015 | |
| 3016 TEST_F(LayerTreeHostCommonTest, | |
| 3017 SingularTransformDoesNotPreventClearingDrawProperties) { | |
| 3018 scoped_refptr<Layer> root = Layer::Create(); | |
| 3019 scoped_refptr<LayerWithForcedDrawsContent> child = | |
| 3020 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3021 root->AddChild(child); | |
| 3022 | |
| 3023 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 3024 host->SetRootLayer(root); | |
| 3025 | |
| 3026 gfx::Transform identity_matrix; | |
| 3027 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); | |
| 3028 ASSERT_FALSE(uninvertible_matrix.IsInvertible()); | |
| 3029 | |
| 3030 SetLayerPropertiesForTesting(root.get(), | |
| 3031 uninvertible_matrix, | |
| 3032 gfx::Point3F(), | |
| 3033 gfx::PointF(), | |
| 3034 gfx::Size(100, 100), | |
| 3035 true, | |
| 3036 false); | |
| 3037 SetLayerPropertiesForTesting(child.get(), | |
| 3038 identity_matrix, | |
| 3039 gfx::Point3F(), | |
| 3040 gfx::PointF(5.f, 5.f), | |
| 3041 gfx::Size(50, 50), | |
| 3042 true, | |
| 3043 false); | |
| 3044 | |
| 3045 child->draw_properties().sorted_for_recursion = true; | |
| 3046 | |
| 3047 TransformOperations start_transform_operations; | |
| 3048 start_transform_operations.AppendScale(1.f, 0.f, 0.f); | |
| 3049 | |
| 3050 TransformOperations end_transform_operations; | |
| 3051 end_transform_operations.AppendScale(1.f, 1.f, 0.f); | |
| 3052 | |
| 3053 AddAnimatedTransformToLayer( | |
| 3054 root.get(), 10.0, start_transform_operations, end_transform_operations); | |
| 3055 | |
| 3056 EXPECT_TRUE(root->TransformIsAnimating()); | |
| 3057 | |
| 3058 ExecuteCalculateDrawProperties(root.get()); | |
| 3059 | |
| 3060 EXPECT_FALSE(child->draw_properties().sorted_for_recursion); | |
| 3061 } | |
| 3062 | |
| 3063 TEST_F(LayerTreeHostCommonTest, | |
| 3064 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) { | |
| 3065 scoped_refptr<Layer> root = Layer::Create(); | |
| 3066 | |
| 3067 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 3068 host->SetRootLayer(root); | |
| 3069 | |
| 3070 gfx::Transform identity_matrix; | |
| 3071 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); | |
| 3072 ASSERT_FALSE(uninvertible_matrix.IsInvertible()); | |
| 3073 | |
| 3074 SetLayerPropertiesForTesting(root.get(), | |
| 3075 uninvertible_matrix, | |
| 3076 gfx::Point3F(), | |
| 3077 gfx::PointF(), | |
| 3078 gfx::Size(100, 100), | |
| 3079 true, | |
| 3080 false); | |
| 3081 | |
| 3082 root->draw_properties().sorted_for_recursion = true; | |
| 3083 | |
| 3084 EXPECT_FALSE(root->TransformIsAnimating()); | |
| 3085 | |
| 3086 ExecuteCalculateDrawProperties(root.get()); | |
| 3087 | |
| 3088 EXPECT_FALSE(root->draw_properties().sorted_for_recursion); | |
| 3089 } | |
| 3090 | |
| 3091 TEST_F(LayerTreeHostCommonTest, | |
| 3092 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { | |
| 3093 scoped_refptr<Layer> root = Layer::Create(); | |
| 3094 scoped_refptr<Layer> render_surface1 = Layer::Create(); | |
| 3095 scoped_refptr<LayerWithForcedDrawsContent> child1 = | |
| 3096 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3097 scoped_refptr<LayerWithForcedDrawsContent> child2 = | |
| 3098 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3099 scoped_refptr<LayerWithForcedDrawsContent> child3 = | |
| 3100 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3101 root->AddChild(render_surface1); | |
| 3102 render_surface1->AddChild(child1); | |
| 3103 render_surface1->AddChild(child2); | |
| 3104 render_surface1->AddChild(child3); | |
| 3105 | |
| 3106 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 3107 host->SetRootLayer(root); | |
| 3108 | |
| 3109 gfx::Transform identity_matrix; | |
| 3110 SetLayerPropertiesForTesting(root.get(), | |
| 3111 identity_matrix, | |
| 3112 gfx::Point3F(), | |
| 3113 gfx::PointF(), | |
| 3114 gfx::Size(100, 100), | |
| 3115 true, | |
| 3116 false); | |
| 3117 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 3118 identity_matrix, | |
| 3119 gfx::Point3F(), | |
| 3120 gfx::PointF(), | |
| 3121 gfx::Size(3, 4), | |
| 3122 true, | |
| 3123 false); | |
| 3124 SetLayerPropertiesForTesting(child1.get(), | |
| 3125 identity_matrix, | |
| 3126 gfx::Point3F(), | |
| 3127 gfx::PointF(5.f, 5.f), | |
| 3128 gfx::Size(50, 50), | |
| 3129 true, | |
| 3130 false); | |
| 3131 SetLayerPropertiesForTesting(child2.get(), | |
| 3132 identity_matrix, | |
| 3133 gfx::Point3F(), | |
| 3134 gfx::PointF(75.f, 75.f), | |
| 3135 gfx::Size(50, 50), | |
| 3136 true, | |
| 3137 false); | |
| 3138 SetLayerPropertiesForTesting(child3.get(), | |
| 3139 identity_matrix, | |
| 3140 gfx::Point3F(), | |
| 3141 gfx::PointF(125.f, 125.f), | |
| 3142 gfx::Size(50, 50), | |
| 3143 true, | |
| 3144 false); | |
| 3145 | |
| 3146 root->SetMasksToBounds(true); | |
| 3147 render_surface1->SetForceRenderSurface(true); | |
| 3148 ExecuteCalculateDrawProperties(root.get()); | |
| 3149 | |
| 3150 ASSERT_TRUE(render_surface1->render_surface()); | |
| 3151 | |
| 3152 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | |
| 3153 root->render_surface()->DrawableContentRect()); | |
| 3154 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); | |
| 3155 | |
| 3156 // Layers that do not draw content should have empty visible content rects. | |
| 3157 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); | |
| 3158 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); | |
| 3159 | |
| 3160 // A clipped surface grows its DrawableContentRect to include all drawable | |
| 3161 // regions of the subtree, but also gets clamped by the ancestor's clip. | |
| 3162 EXPECT_EQ(gfx::Rect(5, 5, 95, 95), | |
| 3163 render_surface1->render_surface()->DrawableContentRect()); | |
| 3164 | |
| 3165 // All layers that draw content into the surface have their visible content | |
| 3166 // rect clipped by the surface clip rect. | |
| 3167 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); | |
| 3168 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); | |
| 3169 EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); | |
| 3170 | |
| 3171 // But the DrawableContentRects are unclipped. | |
| 3172 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); | |
| 3173 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); | |
| 3174 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); | |
| 3175 } | |
| 3176 | |
| 3177 TEST_F(LayerTreeHostCommonTest, | |
| 3178 DrawableAndVisibleContentRectsForSurfaceHierarchy) { | |
| 3179 // Check that clipping does not propagate down surfaces. | |
| 3180 scoped_refptr<Layer> root = Layer::Create(); | |
| 3181 scoped_refptr<Layer> render_surface1 = Layer::Create(); | |
| 3182 scoped_refptr<Layer> render_surface2 = Layer::Create(); | |
| 3183 scoped_refptr<LayerWithForcedDrawsContent> child1 = | |
| 3184 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3185 scoped_refptr<LayerWithForcedDrawsContent> child2 = | |
| 3186 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3187 scoped_refptr<LayerWithForcedDrawsContent> child3 = | |
| 3188 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3189 root->AddChild(render_surface1); | |
| 3190 render_surface1->AddChild(render_surface2); | |
| 3191 render_surface2->AddChild(child1); | |
| 3192 render_surface2->AddChild(child2); | |
| 3193 render_surface2->AddChild(child3); | |
| 3194 | |
| 3195 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 3196 host->SetRootLayer(root); | |
| 3197 | |
| 3198 gfx::Transform identity_matrix; | |
| 3199 SetLayerPropertiesForTesting(root.get(), | |
| 3200 identity_matrix, | |
| 3201 gfx::Point3F(), | |
| 3202 gfx::PointF(), | |
| 3203 gfx::Size(100, 100), | |
| 3204 true, | |
| 3205 false); | |
| 3206 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 3207 identity_matrix, | |
| 3208 gfx::Point3F(), | |
| 3209 gfx::PointF(), | |
| 3210 gfx::Size(3, 4), | |
| 3211 true, | |
| 3212 false); | |
| 3213 SetLayerPropertiesForTesting(render_surface2.get(), | |
| 3214 identity_matrix, | |
| 3215 gfx::Point3F(), | |
| 3216 gfx::PointF(), | |
| 3217 gfx::Size(7, 13), | |
| 3218 true, | |
| 3219 false); | |
| 3220 SetLayerPropertiesForTesting(child1.get(), | |
| 3221 identity_matrix, | |
| 3222 gfx::Point3F(), | |
| 3223 gfx::PointF(5.f, 5.f), | |
| 3224 gfx::Size(50, 50), | |
| 3225 true, | |
| 3226 false); | |
| 3227 SetLayerPropertiesForTesting(child2.get(), | |
| 3228 identity_matrix, | |
| 3229 gfx::Point3F(), | |
| 3230 gfx::PointF(75.f, 75.f), | |
| 3231 gfx::Size(50, 50), | |
| 3232 true, | |
| 3233 false); | |
| 3234 SetLayerPropertiesForTesting(child3.get(), | |
| 3235 identity_matrix, | |
| 3236 gfx::Point3F(), | |
| 3237 gfx::PointF(125.f, 125.f), | |
| 3238 gfx::Size(50, 50), | |
| 3239 true, | |
| 3240 false); | |
| 3241 | |
| 3242 root->SetMasksToBounds(true); | |
| 3243 render_surface1->SetForceRenderSurface(true); | |
| 3244 render_surface2->SetForceRenderSurface(true); | |
| 3245 ExecuteCalculateDrawProperties(root.get()); | |
| 3246 | |
| 3247 ASSERT_TRUE(render_surface1->render_surface()); | |
| 3248 ASSERT_TRUE(render_surface2->render_surface()); | |
| 3249 | |
| 3250 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | |
| 3251 root->render_surface()->DrawableContentRect()); | |
| 3252 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); | |
| 3253 | |
| 3254 // Layers that do not draw content should have empty visible content rects. | |
| 3255 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); | |
| 3256 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); | |
| 3257 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_content_rect()); | |
| 3258 | |
| 3259 // A clipped surface grows its DrawableContentRect to include all drawable | |
| 3260 // regions of the subtree, but also gets clamped by the ancestor's clip. | |
| 3261 EXPECT_EQ(gfx::Rect(5, 5, 95, 95), | |
| 3262 render_surface1->render_surface()->DrawableContentRect()); | |
| 3263 | |
| 3264 // render_surface1 lives in the "unclipped universe" of render_surface1, and | |
| 3265 // is only implicitly clipped by render_surface1's content rect. So, | |
| 3266 // render_surface2 grows to enclose all drawable content of its subtree. | |
| 3267 EXPECT_EQ(gfx::Rect(5, 5, 170, 170), | |
| 3268 render_surface2->render_surface()->DrawableContentRect()); | |
| 3269 | |
| 3270 // All layers that draw content into render_surface2 think they are unclipped. | |
| 3271 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); | |
| 3272 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); | |
| 3273 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); | |
| 3274 | |
| 3275 // DrawableContentRects are also unclipped. | |
| 3276 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); | |
| 3277 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); | |
| 3278 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); | |
| 3279 } | |
| 3280 | |
| 3281 TEST_F(LayerTreeHostCommonTest, | |
| 3282 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { | |
| 3283 // Layers that have non-axis aligned bounds (due to transforms) have an | |
| 3284 // expanded, axis-aligned DrawableContentRect and visible content rect. | |
| 3285 | |
| 3286 scoped_refptr<Layer> root = Layer::Create(); | |
| 3287 scoped_refptr<Layer> render_surface1 = Layer::Create(); | |
| 3288 scoped_refptr<LayerWithForcedDrawsContent> child1 = | |
| 3289 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3290 root->AddChild(render_surface1); | |
| 3291 render_surface1->AddChild(child1); | |
| 3292 | |
| 3293 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 3294 host->SetRootLayer(root); | |
| 3295 | |
| 3296 gfx::Transform identity_matrix; | |
| 3297 gfx::Transform child_rotation; | |
| 3298 child_rotation.Rotate(45.0); | |
| 3299 SetLayerPropertiesForTesting(root.get(), | |
| 3300 identity_matrix, | |
| 3301 gfx::Point3F(), | |
| 3302 gfx::PointF(), | |
| 3303 gfx::Size(100, 100), | |
| 3304 true, | |
| 3305 false); | |
| 3306 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 3307 identity_matrix, | |
| 3308 gfx::Point3F(), | |
| 3309 gfx::PointF(), | |
| 3310 gfx::Size(3, 4), | |
| 3311 true, | |
| 3312 false); | |
| 3313 SetLayerPropertiesForTesting(child1.get(), | |
| 3314 child_rotation, | |
| 3315 gfx::Point3F(25, 25, 0.f), | |
| 3316 gfx::PointF(25.f, 25.f), | |
| 3317 gfx::Size(50, 50), | |
| 3318 true, | |
| 3319 false); | |
| 3320 | |
| 3321 render_surface1->SetForceRenderSurface(true); | |
| 3322 ExecuteCalculateDrawProperties(root.get()); | |
| 3323 | |
| 3324 ASSERT_TRUE(render_surface1->render_surface()); | |
| 3325 | |
| 3326 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | |
| 3327 root->render_surface()->DrawableContentRect()); | |
| 3328 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); | |
| 3329 | |
| 3330 // Layers that do not draw content should have empty visible content rects. | |
| 3331 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); | |
| 3332 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); | |
| 3333 | |
| 3334 // The unclipped surface grows its DrawableContentRect to include all drawable | |
| 3335 // regions of the subtree. | |
| 3336 int diagonal_radius = ceil(sqrt(2.0) * 25.0); | |
| 3337 gfx::Rect expected_surface_drawable_content = | |
| 3338 gfx::Rect(50 - diagonal_radius, | |
| 3339 50 - diagonal_radius, | |
| 3340 diagonal_radius * 2, | |
| 3341 diagonal_radius * 2); | |
| 3342 EXPECT_EQ(expected_surface_drawable_content, | |
| 3343 render_surface1->render_surface()->DrawableContentRect()); | |
| 3344 | |
| 3345 // All layers that draw content into the unclipped surface are also unclipped. | |
| 3346 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); | |
| 3347 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); | |
| 3348 } | |
| 3349 | |
| 3350 TEST_F(LayerTreeHostCommonTest, | |
| 3351 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { | |
| 3352 // Layers that have non-axis aligned bounds (due to transforms) have an | |
| 3353 // expanded, axis-aligned DrawableContentRect and visible content rect. | |
| 3354 | |
| 3355 scoped_refptr<Layer> root = Layer::Create(); | |
| 3356 scoped_refptr<Layer> render_surface1 = Layer::Create(); | |
| 3357 scoped_refptr<LayerWithForcedDrawsContent> child1 = | |
| 3358 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3359 root->AddChild(render_surface1); | |
| 3360 render_surface1->AddChild(child1); | |
| 3361 | |
| 3362 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 3363 host->SetRootLayer(root); | |
| 3364 | |
| 3365 gfx::Transform identity_matrix; | |
| 3366 gfx::Transform child_rotation; | |
| 3367 child_rotation.Rotate(45.0); | |
| 3368 SetLayerPropertiesForTesting(root.get(), | |
| 3369 identity_matrix, | |
| 3370 gfx::Point3F(), | |
| 3371 gfx::PointF(), | |
| 3372 gfx::Size(50, 50), | |
| 3373 true, | |
| 3374 false); | |
| 3375 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 3376 identity_matrix, | |
| 3377 gfx::Point3F(), | |
| 3378 gfx::PointF(), | |
| 3379 gfx::Size(3, 4), | |
| 3380 true, | |
| 3381 false); | |
| 3382 | |
| 3383 SetLayerPropertiesForTesting(child1.get(), | |
| 3384 child_rotation, | |
| 3385 gfx::Point3F(25, 25, 0.f), | |
| 3386 gfx::PointF(25.f, 25.f), | |
| 3387 gfx::Size(50, 50), | |
| 3388 true, | |
| 3389 false); | |
| 3390 | |
| 3391 root->SetMasksToBounds(true); | |
| 3392 render_surface1->SetForceRenderSurface(true); | |
| 3393 ExecuteCalculateDrawProperties(root.get()); | |
| 3394 | |
| 3395 ASSERT_TRUE(render_surface1->render_surface()); | |
| 3396 | |
| 3397 // The clipped surface clamps the DrawableContentRect that encloses the | |
| 3398 // rotated layer. | |
| 3399 int diagonal_radius = ceil(sqrt(2.0) * 25.0); | |
| 3400 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, | |
| 3401 50 - diagonal_radius, | |
| 3402 diagonal_radius * 2, | |
| 3403 diagonal_radius * 2); | |
| 3404 gfx::Rect expected_surface_drawable_content = | |
| 3405 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50)); | |
| 3406 EXPECT_EQ(expected_surface_drawable_content, | |
| 3407 render_surface1->render_surface()->DrawableContentRect()); | |
| 3408 | |
| 3409 // On the clipped surface, only a quarter of the child1 is visible, but when | |
| 3410 // rotating it back to child1's content space, the actual enclosing rect ends | |
| 3411 // up covering the full left half of child1. | |
| 3412 // | |
| 3413 // Given the floating point math, this number is a little bit fuzzy. | |
| 3414 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect()); | |
| 3415 | |
| 3416 // The child's DrawableContentRect is unclipped. | |
| 3417 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); | |
| 3418 } | |
| 3419 | |
| 3420 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { | |
| 3421 MockContentLayerClient client; | |
| 3422 | |
| 3423 scoped_refptr<Layer> root = Layer::Create(); | |
| 3424 scoped_refptr<FakePictureLayer> render_surface1 = | |
| 3425 CreateDrawablePictureLayer(&client); | |
| 3426 scoped_refptr<FakePictureLayer> render_surface2 = | |
| 3427 CreateDrawablePictureLayer(&client); | |
| 3428 scoped_refptr<FakePictureLayer> child1 = CreateDrawablePictureLayer(&client); | |
| 3429 scoped_refptr<FakePictureLayer> child2 = CreateDrawablePictureLayer(&client); | |
| 3430 scoped_refptr<FakePictureLayer> child3 = CreateDrawablePictureLayer(&client); | |
| 3431 root->AddChild(render_surface1); | |
| 3432 render_surface1->AddChild(render_surface2); | |
| 3433 render_surface2->AddChild(child1); | |
| 3434 render_surface2->AddChild(child2); | |
| 3435 render_surface2->AddChild(child3); | |
| 3436 | |
| 3437 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 3438 host->SetRootLayer(root); | |
| 3439 | |
| 3440 gfx::Transform identity_matrix; | |
| 3441 SetLayerPropertiesForTesting(root.get(), | |
| 3442 identity_matrix, | |
| 3443 gfx::Point3F(), | |
| 3444 gfx::PointF(), | |
| 3445 gfx::Size(100, 100), | |
| 3446 true, | |
| 3447 false); | |
| 3448 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 3449 identity_matrix, | |
| 3450 gfx::Point3F(), | |
| 3451 gfx::PointF(5.f, 5.f), | |
| 3452 gfx::Size(3, 4), | |
| 3453 true, | |
| 3454 false); | |
| 3455 SetLayerPropertiesForTesting(render_surface2.get(), | |
| 3456 identity_matrix, | |
| 3457 gfx::Point3F(), | |
| 3458 gfx::PointF(5.f, 5.f), | |
| 3459 gfx::Size(7, 13), | |
| 3460 true, | |
| 3461 false); | |
| 3462 SetLayerPropertiesForTesting(child1.get(), | |
| 3463 identity_matrix, | |
| 3464 gfx::Point3F(), | |
| 3465 gfx::PointF(5.f, 5.f), | |
| 3466 gfx::Size(50, 50), | |
| 3467 true, | |
| 3468 false); | |
| 3469 SetLayerPropertiesForTesting(child2.get(), | |
| 3470 identity_matrix, | |
| 3471 gfx::Point3F(), | |
| 3472 gfx::PointF(75.f, 75.f), | |
| 3473 gfx::Size(50, 50), | |
| 3474 true, | |
| 3475 false); | |
| 3476 SetLayerPropertiesForTesting(child3.get(), | |
| 3477 identity_matrix, | |
| 3478 gfx::Point3F(), | |
| 3479 gfx::PointF(125.f, 125.f), | |
| 3480 gfx::Size(50, 50), | |
| 3481 true, | |
| 3482 false); | |
| 3483 | |
| 3484 float device_scale_factor = 2.f; | |
| 3485 | |
| 3486 root->SetMasksToBounds(true); | |
| 3487 render_surface1->SetForceRenderSurface(true); | |
| 3488 render_surface2->SetForceRenderSurface(true); | |
| 3489 ExecuteCalculateDrawProperties(root.get(), device_scale_factor); | |
| 3490 | |
| 3491 ASSERT_TRUE(render_surface1->render_surface()); | |
| 3492 ASSERT_TRUE(render_surface2->render_surface()); | |
| 3493 | |
| 3494 // drawable_content_rects for all layers and surfaces are scaled by | |
| 3495 // device_scale_factor. | |
| 3496 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), | |
| 3497 root->render_surface()->DrawableContentRect()); | |
| 3498 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect()); | |
| 3499 EXPECT_EQ(gfx::Rect(10, 10, 190, 190), | |
| 3500 render_surface1->render_surface()->DrawableContentRect()); | |
| 3501 | |
| 3502 // render_surface2 lives in the "unclipped universe" of render_surface1, and | |
| 3503 // is only implicitly clipped by render_surface1. | |
| 3504 EXPECT_EQ(gfx::Rect(10, 10, 350, 350), | |
| 3505 render_surface2->render_surface()->DrawableContentRect()); | |
| 3506 | |
| 3507 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); | |
| 3508 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); | |
| 3509 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); | |
| 3510 | |
| 3511 // The root layer does not actually draw content of its own. | |
| 3512 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); | |
| 3513 | |
| 3514 // All layer visible content rects are not expressed in content space of each | |
| 3515 // layer, so they are not scaled by the device_scale_factor. | |
| 3516 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_content_rect()); | |
| 3517 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_content_rect()); | |
| 3518 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); | |
| 3519 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); | |
| 3520 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); | |
| 3521 } | |
| 3522 | |
| 3523 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { | |
| 3524 // Verify the behavior of back-face culling when there are no preserve-3d | |
| 3525 // layers. Note that 3d transforms still apply in this case, but they are | |
| 3526 // "flattened" to each parent layer according to current W3C spec. | |
| 3527 | |
| 3528 const gfx::Transform identity_matrix; | |
| 3529 scoped_refptr<Layer> parent = Layer::Create(); | |
| 3530 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = | |
| 3531 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3532 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = | |
| 3533 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3534 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = | |
| 3535 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3536 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = | |
| 3537 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3538 scoped_refptr<LayerWithForcedDrawsContent> | |
| 3539 front_facing_child_of_front_facing_surface = | |
| 3540 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3541 scoped_refptr<LayerWithForcedDrawsContent> | |
| 3542 back_facing_child_of_front_facing_surface = | |
| 3543 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3544 scoped_refptr<LayerWithForcedDrawsContent> | |
| 3545 front_facing_child_of_back_facing_surface = | |
| 3546 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3547 scoped_refptr<LayerWithForcedDrawsContent> | |
| 3548 back_facing_child_of_back_facing_surface = | |
| 3549 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3550 | |
| 3551 parent->AddChild(front_facing_child); | |
| 3552 parent->AddChild(back_facing_child); | |
| 3553 parent->AddChild(front_facing_surface); | |
| 3554 parent->AddChild(back_facing_surface); | |
| 3555 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); | |
| 3556 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); | |
| 3557 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); | |
| 3558 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); | |
| 3559 | |
| 3560 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 3561 host->SetRootLayer(parent); | |
| 3562 | |
| 3563 // Nothing is double-sided | |
| 3564 front_facing_child->SetDoubleSided(false); | |
| 3565 back_facing_child->SetDoubleSided(false); | |
| 3566 front_facing_surface->SetDoubleSided(false); | |
| 3567 back_facing_surface->SetDoubleSided(false); | |
| 3568 front_facing_child_of_front_facing_surface->SetDoubleSided(false); | |
| 3569 back_facing_child_of_front_facing_surface->SetDoubleSided(false); | |
| 3570 front_facing_child_of_back_facing_surface->SetDoubleSided(false); | |
| 3571 back_facing_child_of_back_facing_surface->SetDoubleSided(false); | |
| 3572 | |
| 3573 gfx::Transform backface_matrix; | |
| 3574 backface_matrix.Translate(50.0, 50.0); | |
| 3575 backface_matrix.RotateAboutYAxis(180.0); | |
| 3576 backface_matrix.Translate(-50.0, -50.0); | |
| 3577 | |
| 3578 // Having a descendant and opacity will force these to have render surfaces. | |
| 3579 front_facing_surface->SetOpacity(0.5f); | |
| 3580 back_facing_surface->SetOpacity(0.5f); | |
| 3581 | |
| 3582 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, | |
| 3583 // these layers should blindly use their own local transforms to determine | |
| 3584 // back-face culling. | |
| 3585 SetLayerPropertiesForTesting(parent.get(), | |
| 3586 identity_matrix, | |
| 3587 gfx::Point3F(), | |
| 3588 gfx::PointF(), | |
| 3589 gfx::Size(100, 100), | |
| 3590 true, | |
| 3591 false); | |
| 3592 SetLayerPropertiesForTesting(front_facing_child.get(), | |
| 3593 identity_matrix, | |
| 3594 gfx::Point3F(), | |
| 3595 gfx::PointF(), | |
| 3596 gfx::Size(100, 100), | |
| 3597 true, | |
| 3598 false); | |
| 3599 SetLayerPropertiesForTesting(back_facing_child.get(), | |
| 3600 backface_matrix, | |
| 3601 gfx::Point3F(), | |
| 3602 gfx::PointF(), | |
| 3603 gfx::Size(100, 100), | |
| 3604 true, | |
| 3605 false); | |
| 3606 SetLayerPropertiesForTesting(front_facing_surface.get(), | |
| 3607 identity_matrix, | |
| 3608 gfx::Point3F(), | |
| 3609 gfx::PointF(), | |
| 3610 gfx::Size(100, 100), | |
| 3611 true, | |
| 3612 false); | |
| 3613 SetLayerPropertiesForTesting(back_facing_surface.get(), | |
| 3614 backface_matrix, | |
| 3615 gfx::Point3F(), | |
| 3616 gfx::PointF(), | |
| 3617 gfx::Size(100, 100), | |
| 3618 true, | |
| 3619 false); | |
| 3620 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), | |
| 3621 identity_matrix, | |
| 3622 gfx::Point3F(), | |
| 3623 gfx::PointF(), | |
| 3624 gfx::Size(100, 100), | |
| 3625 true, | |
| 3626 false); | |
| 3627 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), | |
| 3628 backface_matrix, | |
| 3629 gfx::Point3F(), | |
| 3630 gfx::PointF(), | |
| 3631 gfx::Size(100, 100), | |
| 3632 true, | |
| 3633 false); | |
| 3634 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), | |
| 3635 identity_matrix, | |
| 3636 gfx::Point3F(), | |
| 3637 gfx::PointF(), | |
| 3638 gfx::Size(100, 100), | |
| 3639 true, | |
| 3640 false); | |
| 3641 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), | |
| 3642 backface_matrix, | |
| 3643 gfx::Point3F(), | |
| 3644 gfx::PointF(), | |
| 3645 gfx::Size(100, 100), | |
| 3646 true, | |
| 3647 false); | |
| 3648 | |
| 3649 RenderSurfaceLayerList render_surface_layer_list; | |
| 3650 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 3651 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 3652 inputs.can_adjust_raster_scales = true; | |
| 3653 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 3654 | |
| 3655 // Verify which render surfaces were created. | |
| 3656 EXPECT_FALSE(front_facing_child->render_surface()); | |
| 3657 EXPECT_FALSE(back_facing_child->render_surface()); | |
| 3658 EXPECT_TRUE(front_facing_surface->render_surface()); | |
| 3659 EXPECT_TRUE(back_facing_surface->render_surface()); | |
| 3660 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); | |
| 3661 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); | |
| 3662 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); | |
| 3663 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); | |
| 3664 | |
| 3665 // Verify the render_surface_layer_list. | |
| 3666 ASSERT_EQ(3u, render_surface_layer_list.size()); | |
| 3667 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); | |
| 3668 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); | |
| 3669 // Even though the back facing surface LAYER gets culled, the other | |
| 3670 // descendants should still be added, so the SURFACE should not be culled. | |
| 3671 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id()); | |
| 3672 | |
| 3673 // Verify root surface's layer list. | |
| 3674 ASSERT_EQ( | |
| 3675 3u, | |
| 3676 render_surface_layer_list.at(0)->render_surface()->layer_list().size()); | |
| 3677 EXPECT_EQ(front_facing_child->id(), | |
| 3678 render_surface_layer_list.at(0) | |
| 3679 ->render_surface() | |
| 3680 ->layer_list() | |
| 3681 .at(0) | |
| 3682 ->id()); | |
| 3683 EXPECT_EQ(front_facing_surface->id(), | |
| 3684 render_surface_layer_list.at(0) | |
| 3685 ->render_surface() | |
| 3686 ->layer_list() | |
| 3687 .at(1) | |
| 3688 ->id()); | |
| 3689 EXPECT_EQ(back_facing_surface->id(), | |
| 3690 render_surface_layer_list.at(0) | |
| 3691 ->render_surface() | |
| 3692 ->layer_list() | |
| 3693 .at(2) | |
| 3694 ->id()); | |
| 3695 | |
| 3696 // Verify front_facing_surface's layer list. | |
| 3697 ASSERT_EQ( | |
| 3698 2u, | |
| 3699 render_surface_layer_list.at(1)->render_surface()->layer_list().size()); | |
| 3700 EXPECT_EQ(front_facing_surface->id(), | |
| 3701 render_surface_layer_list.at(1) | |
| 3702 ->render_surface() | |
| 3703 ->layer_list() | |
| 3704 .at(0) | |
| 3705 ->id()); | |
| 3706 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), | |
| 3707 render_surface_layer_list.at(1) | |
| 3708 ->render_surface() | |
| 3709 ->layer_list() | |
| 3710 .at(1) | |
| 3711 ->id()); | |
| 3712 | |
| 3713 // Verify back_facing_surface's layer list; its own layer should be culled | |
| 3714 // from the surface list. | |
| 3715 ASSERT_EQ( | |
| 3716 1u, | |
| 3717 render_surface_layer_list.at(2)->render_surface()->layer_list().size()); | |
| 3718 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(), | |
| 3719 render_surface_layer_list.at(2) | |
| 3720 ->render_surface() | |
| 3721 ->layer_list() | |
| 3722 .at(0) | |
| 3723 ->id()); | |
| 3724 } | |
| 3725 | |
| 3726 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { | |
| 3727 // Verify the behavior of back-face culling when preserves-3d transform style | |
| 3728 // is used. | |
| 3729 | |
| 3730 const gfx::Transform identity_matrix; | |
| 3731 scoped_refptr<Layer> parent = Layer::Create(); | |
| 3732 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = | |
| 3733 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3734 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = | |
| 3735 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3736 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = | |
| 3737 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3738 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = | |
| 3739 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3740 scoped_refptr<LayerWithForcedDrawsContent> | |
| 3741 front_facing_child_of_front_facing_surface = | |
| 3742 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3743 scoped_refptr<LayerWithForcedDrawsContent> | |
| 3744 back_facing_child_of_front_facing_surface = | |
| 3745 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3746 scoped_refptr<LayerWithForcedDrawsContent> | |
| 3747 front_facing_child_of_back_facing_surface = | |
| 3748 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3749 scoped_refptr<LayerWithForcedDrawsContent> | |
| 3750 back_facing_child_of_back_facing_surface = | |
| 3751 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3752 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 = | |
| 3753 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3754 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 = | |
| 3755 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3756 | |
| 3757 parent->AddChild(front_facing_child); | |
| 3758 parent->AddChild(back_facing_child); | |
| 3759 parent->AddChild(front_facing_surface); | |
| 3760 parent->AddChild(back_facing_surface); | |
| 3761 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); | |
| 3762 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); | |
| 3763 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); | |
| 3764 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); | |
| 3765 | |
| 3766 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 3767 host->SetRootLayer(parent); | |
| 3768 | |
| 3769 // Nothing is double-sided | |
| 3770 front_facing_child->SetDoubleSided(false); | |
| 3771 back_facing_child->SetDoubleSided(false); | |
| 3772 front_facing_surface->SetDoubleSided(false); | |
| 3773 back_facing_surface->SetDoubleSided(false); | |
| 3774 front_facing_child_of_front_facing_surface->SetDoubleSided(false); | |
| 3775 back_facing_child_of_front_facing_surface->SetDoubleSided(false); | |
| 3776 front_facing_child_of_back_facing_surface->SetDoubleSided(false); | |
| 3777 back_facing_child_of_back_facing_surface->SetDoubleSided(false); | |
| 3778 | |
| 3779 gfx::Transform backface_matrix; | |
| 3780 backface_matrix.Translate(50.0, 50.0); | |
| 3781 backface_matrix.RotateAboutYAxis(180.0); | |
| 3782 backface_matrix.Translate(-50.0, -50.0); | |
| 3783 | |
| 3784 // Opacity will not force creation of render surfaces in this case because of | |
| 3785 // the preserve-3d transform style. Instead, an example of when a surface | |
| 3786 // would be created with preserve-3d is when there is a replica layer. | |
| 3787 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get()); | |
| 3788 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get()); | |
| 3789 | |
| 3790 // Each surface creates its own new 3d rendering context (as defined by W3C | |
| 3791 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d | |
| 3792 // rendering context should use the transform with respect to that context. | |
| 3793 // This 3d rendering context occurs when (a) parent's transform style is flat | |
| 3794 // and (b) the layer's transform style is preserve-3d. | |
| 3795 SetLayerPropertiesForTesting(parent.get(), | |
| 3796 identity_matrix, | |
| 3797 gfx::Point3F(), | |
| 3798 gfx::PointF(), | |
| 3799 gfx::Size(100, 100), | |
| 3800 true, | |
| 3801 false); // parent transform style is flat. | |
| 3802 SetLayerPropertiesForTesting(front_facing_child.get(), | |
| 3803 identity_matrix, | |
| 3804 gfx::Point3F(), | |
| 3805 gfx::PointF(), | |
| 3806 gfx::Size(100, 100), | |
| 3807 true, | |
| 3808 false); | |
| 3809 SetLayerPropertiesForTesting(back_facing_child.get(), | |
| 3810 backface_matrix, | |
| 3811 gfx::Point3F(), | |
| 3812 gfx::PointF(), | |
| 3813 gfx::Size(100, 100), | |
| 3814 true, | |
| 3815 false); | |
| 3816 // surface transform style is preserve-3d. | |
| 3817 SetLayerPropertiesForTesting(front_facing_surface.get(), | |
| 3818 identity_matrix, | |
| 3819 gfx::Point3F(), | |
| 3820 gfx::PointF(), | |
| 3821 gfx::Size(100, 100), | |
| 3822 false, | |
| 3823 true); | |
| 3824 // surface transform style is preserve-3d. | |
| 3825 SetLayerPropertiesForTesting(back_facing_surface.get(), | |
| 3826 backface_matrix, | |
| 3827 gfx::Point3F(), | |
| 3828 gfx::PointF(), | |
| 3829 gfx::Size(100, 100), | |
| 3830 false, | |
| 3831 true); | |
| 3832 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), | |
| 3833 identity_matrix, | |
| 3834 gfx::Point3F(), | |
| 3835 gfx::PointF(), | |
| 3836 gfx::Size(100, 100), | |
| 3837 true, | |
| 3838 true); | |
| 3839 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), | |
| 3840 backface_matrix, | |
| 3841 gfx::Point3F(), | |
| 3842 gfx::PointF(), | |
| 3843 gfx::Size(100, 100), | |
| 3844 true, | |
| 3845 true); | |
| 3846 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), | |
| 3847 identity_matrix, | |
| 3848 gfx::Point3F(), | |
| 3849 gfx::PointF(), | |
| 3850 gfx::Size(100, 100), | |
| 3851 true, | |
| 3852 true); | |
| 3853 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), | |
| 3854 backface_matrix, | |
| 3855 gfx::Point3F(), | |
| 3856 gfx::PointF(), | |
| 3857 gfx::Size(100, 100), | |
| 3858 true, | |
| 3859 true); | |
| 3860 | |
| 3861 RenderSurfaceLayerList render_surface_layer_list; | |
| 3862 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 3863 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 3864 inputs.can_adjust_raster_scales = true; | |
| 3865 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 3866 | |
| 3867 // Verify which render surfaces were created and used. | |
| 3868 EXPECT_FALSE(front_facing_child->render_surface()); | |
| 3869 EXPECT_FALSE(back_facing_child->render_surface()); | |
| 3870 EXPECT_TRUE(front_facing_surface->render_surface()); | |
| 3871 EXPECT_NE(back_facing_surface->render_target(), back_facing_surface); | |
| 3872 // We expect that a render_surface was created but not used. | |
| 3873 EXPECT_TRUE(back_facing_surface->render_surface()); | |
| 3874 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); | |
| 3875 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); | |
| 3876 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); | |
| 3877 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); | |
| 3878 | |
| 3879 // Verify the render_surface_layer_list. The back-facing surface should be | |
| 3880 // culled. | |
| 3881 ASSERT_EQ(2u, render_surface_layer_list.size()); | |
| 3882 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); | |
| 3883 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); | |
| 3884 | |
| 3885 // Verify root surface's layer list. | |
| 3886 ASSERT_EQ( | |
| 3887 2u, | |
| 3888 render_surface_layer_list.at(0)->render_surface()->layer_list().size()); | |
| 3889 EXPECT_EQ(front_facing_child->id(), | |
| 3890 render_surface_layer_list.at(0) | |
| 3891 ->render_surface()->layer_list().at(0)->id()); | |
| 3892 EXPECT_EQ(front_facing_surface->id(), | |
| 3893 render_surface_layer_list.at(0) | |
| 3894 ->render_surface()->layer_list().at(1)->id()); | |
| 3895 | |
| 3896 // Verify front_facing_surface's layer list. | |
| 3897 ASSERT_EQ( | |
| 3898 2u, | |
| 3899 render_surface_layer_list.at(1)->render_surface()->layer_list().size()); | |
| 3900 EXPECT_EQ(front_facing_surface->id(), | |
| 3901 render_surface_layer_list.at(1) | |
| 3902 ->render_surface()->layer_list().at(0)->id()); | |
| 3903 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), | |
| 3904 render_surface_layer_list.at(1) | |
| 3905 ->render_surface()->layer_list().at(1)->id()); | |
| 3906 } | |
| 3907 | |
| 3908 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { | |
| 3909 // Verify that layers are appropriately culled when their back face is showing | |
| 3910 // and they are not double sided, while animations are going on. | |
| 3911 // | |
| 3912 // Layers that are animating do not get culled on the main thread, as their | |
| 3913 // transforms should be treated as "unknown" so we can not be sure that their | |
| 3914 // back face is really showing. | |
| 3915 const gfx::Transform identity_matrix; | |
| 3916 scoped_refptr<Layer> parent = Layer::Create(); | |
| 3917 scoped_refptr<LayerWithForcedDrawsContent> child = | |
| 3918 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3919 scoped_refptr<LayerWithForcedDrawsContent> animating_surface = | |
| 3920 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3921 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface = | |
| 3922 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3923 scoped_refptr<LayerWithForcedDrawsContent> animating_child = | |
| 3924 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3925 scoped_refptr<LayerWithForcedDrawsContent> child2 = | |
| 3926 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 3927 | |
| 3928 parent->AddChild(child); | |
| 3929 parent->AddChild(animating_surface); | |
| 3930 animating_surface->AddChild(child_of_animating_surface); | |
| 3931 parent->AddChild(animating_child); | |
| 3932 parent->AddChild(child2); | |
| 3933 | |
| 3934 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 3935 host->SetRootLayer(parent); | |
| 3936 | |
| 3937 // Nothing is double-sided | |
| 3938 child->SetDoubleSided(false); | |
| 3939 child2->SetDoubleSided(false); | |
| 3940 animating_surface->SetDoubleSided(false); | |
| 3941 child_of_animating_surface->SetDoubleSided(false); | |
| 3942 animating_child->SetDoubleSided(false); | |
| 3943 | |
| 3944 gfx::Transform backface_matrix; | |
| 3945 backface_matrix.Translate(50.0, 50.0); | |
| 3946 backface_matrix.RotateAboutYAxis(180.0); | |
| 3947 backface_matrix.Translate(-50.0, -50.0); | |
| 3948 | |
| 3949 // Make our render surface. | |
| 3950 animating_surface->SetForceRenderSurface(true); | |
| 3951 | |
| 3952 // Animate the transform on the render surface. | |
| 3953 AddAnimatedTransformToController( | |
| 3954 animating_surface->layer_animation_controller(), 10.0, 30, 0); | |
| 3955 // This is just an animating layer, not a surface. | |
| 3956 AddAnimatedTransformToController( | |
| 3957 animating_child->layer_animation_controller(), 10.0, 30, 0); | |
| 3958 | |
| 3959 SetLayerPropertiesForTesting(parent.get(), | |
| 3960 identity_matrix, | |
| 3961 gfx::Point3F(), | |
| 3962 gfx::PointF(), | |
| 3963 gfx::Size(100, 100), | |
| 3964 true, | |
| 3965 false); | |
| 3966 SetLayerPropertiesForTesting(child.get(), | |
| 3967 backface_matrix, | |
| 3968 gfx::Point3F(), | |
| 3969 gfx::PointF(), | |
| 3970 gfx::Size(100, 100), | |
| 3971 true, | |
| 3972 false); | |
| 3973 SetLayerPropertiesForTesting(animating_surface.get(), | |
| 3974 backface_matrix, | |
| 3975 gfx::Point3F(), | |
| 3976 gfx::PointF(), | |
| 3977 gfx::Size(100, 100), | |
| 3978 true, | |
| 3979 false); | |
| 3980 SetLayerPropertiesForTesting(child_of_animating_surface.get(), | |
| 3981 backface_matrix, | |
| 3982 gfx::Point3F(), | |
| 3983 gfx::PointF(), | |
| 3984 gfx::Size(100, 100), | |
| 3985 true, | |
| 3986 false); | |
| 3987 SetLayerPropertiesForTesting(animating_child.get(), | |
| 3988 backface_matrix, | |
| 3989 gfx::Point3F(), | |
| 3990 gfx::PointF(), | |
| 3991 gfx::Size(100, 100), | |
| 3992 true, | |
| 3993 false); | |
| 3994 SetLayerPropertiesForTesting(child2.get(), | |
| 3995 identity_matrix, | |
| 3996 gfx::Point3F(), | |
| 3997 gfx::PointF(), | |
| 3998 gfx::Size(100, 100), | |
| 3999 true, | |
| 4000 false); | |
| 4001 | |
| 4002 RenderSurfaceLayerList render_surface_layer_list; | |
| 4003 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 4004 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 4005 inputs.can_adjust_raster_scales = true; | |
| 4006 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 4007 | |
| 4008 EXPECT_FALSE(child->render_surface()); | |
| 4009 EXPECT_TRUE(animating_surface->render_surface()); | |
| 4010 EXPECT_FALSE(child_of_animating_surface->render_surface()); | |
| 4011 EXPECT_FALSE(animating_child->render_surface()); | |
| 4012 EXPECT_FALSE(child2->render_surface()); | |
| 4013 | |
| 4014 // Verify that the animating_child and child_of_animating_surface were not | |
| 4015 // culled, but that child was. | |
| 4016 ASSERT_EQ(2u, render_surface_layer_list.size()); | |
| 4017 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); | |
| 4018 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id()); | |
| 4019 | |
| 4020 // The non-animating child be culled from the layer list for the parent render | |
| 4021 // surface. | |
| 4022 ASSERT_EQ( | |
| 4023 3u, | |
| 4024 render_surface_layer_list.at(0)->render_surface()->layer_list().size()); | |
| 4025 EXPECT_EQ(animating_surface->id(), | |
| 4026 render_surface_layer_list.at(0) | |
| 4027 ->render_surface()->layer_list().at(0)->id()); | |
| 4028 EXPECT_EQ(animating_child->id(), | |
| 4029 render_surface_layer_list.at(0) | |
| 4030 ->render_surface()->layer_list().at(1)->id()); | |
| 4031 EXPECT_EQ(child2->id(), | |
| 4032 render_surface_layer_list.at(0) | |
| 4033 ->render_surface()->layer_list().at(2)->id()); | |
| 4034 | |
| 4035 ASSERT_EQ( | |
| 4036 2u, | |
| 4037 render_surface_layer_list.at(1)->render_surface()->layer_list().size()); | |
| 4038 EXPECT_EQ(animating_surface->id(), | |
| 4039 render_surface_layer_list.at(1) | |
| 4040 ->render_surface()->layer_list().at(0)->id()); | |
| 4041 EXPECT_EQ(child_of_animating_surface->id(), | |
| 4042 render_surface_layer_list.at(1) | |
| 4043 ->render_surface()->layer_list().at(1)->id()); | |
| 4044 | |
| 4045 EXPECT_FALSE(child2->visible_content_rect().IsEmpty()); | |
| 4046 | |
| 4047 // The animating layers should have a visible content rect that represents the | |
| 4048 // area of the front face that is within the viewport. | |
| 4049 EXPECT_EQ(animating_child->visible_content_rect(), | |
| 4050 gfx::Rect(animating_child->content_bounds())); | |
| 4051 EXPECT_EQ(animating_surface->visible_content_rect(), | |
| 4052 gfx::Rect(animating_surface->content_bounds())); | |
| 4053 // And layers in the subtree of the animating layer should have valid visible | |
| 4054 // content rects also. | |
| 4055 EXPECT_EQ(child_of_animating_surface->visible_content_rect(), | |
| 4056 gfx::Rect(child_of_animating_surface->content_bounds())); | |
| 4057 } | |
| 4058 | |
| 4059 TEST_F(LayerTreeHostCommonTest, | |
| 4060 BackFaceCullingWithPreserves3dForFlatteningSurface) { | |
| 4061 // Verify the behavior of back-face culling for a render surface that is | |
| 4062 // created when it flattens its subtree, and its parent has preserves-3d. | |
| 4063 | |
| 4064 const gfx::Transform identity_matrix; | |
| 4065 scoped_refptr<Layer> parent = Layer::Create(); | |
| 4066 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = | |
| 4067 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 4068 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = | |
| 4069 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 4070 scoped_refptr<LayerWithForcedDrawsContent> child1 = | |
| 4071 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 4072 scoped_refptr<LayerWithForcedDrawsContent> child2 = | |
| 4073 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 4074 | |
| 4075 parent->AddChild(front_facing_surface); | |
| 4076 parent->AddChild(back_facing_surface); | |
| 4077 front_facing_surface->AddChild(child1); | |
| 4078 back_facing_surface->AddChild(child2); | |
| 4079 | |
| 4080 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 4081 host->SetRootLayer(parent); | |
| 4082 | |
| 4083 // RenderSurfaces are not double-sided | |
| 4084 front_facing_surface->SetDoubleSided(false); | |
| 4085 back_facing_surface->SetDoubleSided(false); | |
| 4086 | |
| 4087 gfx::Transform backface_matrix; | |
| 4088 backface_matrix.Translate(50.0, 50.0); | |
| 4089 backface_matrix.RotateAboutYAxis(180.0); | |
| 4090 backface_matrix.Translate(-50.0, -50.0); | |
| 4091 | |
| 4092 SetLayerPropertiesForTesting(parent.get(), | |
| 4093 identity_matrix, | |
| 4094 gfx::Point3F(), | |
| 4095 gfx::PointF(), | |
| 4096 gfx::Size(100, 100), | |
| 4097 false, | |
| 4098 true); // parent transform style is preserve3d. | |
| 4099 SetLayerPropertiesForTesting(front_facing_surface.get(), | |
| 4100 identity_matrix, | |
| 4101 gfx::Point3F(), | |
| 4102 gfx::PointF(), | |
| 4103 gfx::Size(100, 100), | |
| 4104 true, | |
| 4105 true); // surface transform style is flat. | |
| 4106 SetLayerPropertiesForTesting(back_facing_surface.get(), | |
| 4107 backface_matrix, | |
| 4108 gfx::Point3F(), | |
| 4109 gfx::PointF(), | |
| 4110 gfx::Size(100, 100), | |
| 4111 true, | |
| 4112 true); // surface transform style is flat. | |
| 4113 SetLayerPropertiesForTesting(child1.get(), | |
| 4114 identity_matrix, | |
| 4115 gfx::Point3F(), | |
| 4116 gfx::PointF(), | |
| 4117 gfx::Size(100, 100), | |
| 4118 true, | |
| 4119 false); | |
| 4120 SetLayerPropertiesForTesting(child2.get(), | |
| 4121 identity_matrix, | |
| 4122 gfx::Point3F(), | |
| 4123 gfx::PointF(), | |
| 4124 gfx::Size(100, 100), | |
| 4125 true, | |
| 4126 false); | |
| 4127 | |
| 4128 front_facing_surface->Set3dSortingContextId(1); | |
| 4129 back_facing_surface->Set3dSortingContextId(1); | |
| 4130 | |
| 4131 RenderSurfaceLayerList render_surface_layer_list; | |
| 4132 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 4133 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 4134 inputs.can_adjust_raster_scales = true; | |
| 4135 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 4136 | |
| 4137 // Verify which render surfaces were created and used. | |
| 4138 EXPECT_TRUE(front_facing_surface->render_surface()); | |
| 4139 | |
| 4140 // We expect the render surface to have been created, but remain unused. | |
| 4141 EXPECT_TRUE(back_facing_surface->render_surface()); | |
| 4142 EXPECT_NE(back_facing_surface->render_target(), | |
| 4143 back_facing_surface); // because it should be culled | |
| 4144 EXPECT_FALSE(child1->render_surface()); | |
| 4145 EXPECT_FALSE(child2->render_surface()); | |
| 4146 | |
| 4147 // Verify the render_surface_layer_list. The back-facing surface should be | |
| 4148 // culled. | |
| 4149 ASSERT_EQ(2u, render_surface_layer_list.size()); | |
| 4150 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); | |
| 4151 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); | |
| 4152 | |
| 4153 // Verify root surface's layer list. | |
| 4154 ASSERT_EQ( | |
| 4155 1u, | |
| 4156 render_surface_layer_list.at(0)->render_surface()->layer_list().size()); | |
| 4157 EXPECT_EQ(front_facing_surface->id(), | |
| 4158 render_surface_layer_list.at(0) | |
| 4159 ->render_surface()->layer_list().at(0)->id()); | |
| 4160 | |
| 4161 // Verify front_facing_surface's layer list. | |
| 4162 ASSERT_EQ( | |
| 4163 2u, | |
| 4164 render_surface_layer_list.at(1)->render_surface()->layer_list().size()); | |
| 4165 EXPECT_EQ(front_facing_surface->id(), | |
| 4166 render_surface_layer_list.at(1) | |
| 4167 ->render_surface()->layer_list().at(0)->id()); | |
| 4168 EXPECT_EQ(child1->id(), | |
| 4169 render_surface_layer_list.at(1) | |
| 4170 ->render_surface()->layer_list().at(1)->id()); | |
| 4171 } | |
| 4172 | |
| 4173 class NoScaleContentLayer : public ContentLayer { | |
| 4174 public: | |
| 4175 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { | |
| 4176 return make_scoped_refptr(new NoScaleContentLayer(client)); | |
| 4177 } | |
| 4178 | |
| 4179 void CalculateContentsScale(float ideal_contents_scale, | |
| 4180 float* contents_scale_x, | |
| 4181 float* contents_scale_y, | |
| 4182 gfx::Size* content_bounds) override { | |
| 4183 // Skip over the ContentLayer to the base Layer class. | |
| 4184 Layer::CalculateContentsScale(ideal_contents_scale, | |
| 4185 contents_scale_x, | |
| 4186 contents_scale_y, | |
| 4187 content_bounds); | |
| 4188 } | |
| 4189 | |
| 4190 protected: | |
| 4191 explicit NoScaleContentLayer(ContentLayerClient* client) | |
| 4192 : ContentLayer(client) {} | |
| 4193 ~NoScaleContentLayer() override {} | |
| 4194 }; | |
| 4195 | |
| 4196 scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer( | |
| 4197 ContentLayerClient* delegate) { | |
| 4198 scoped_refptr<NoScaleContentLayer> to_return = | |
| 4199 NoScaleContentLayer::Create(delegate); | |
| 4200 to_return->SetIsDrawable(true); | |
| 4201 return to_return; | |
| 4202 } | |
| 4203 | |
| 4204 TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) { | |
| 4205 // Verify draw and screen space transforms of layers not in a surface. | |
| 4206 MockContentLayerClient delegate; | |
| 4207 gfx::Transform identity_matrix; | |
| 4208 | |
| 4209 scoped_refptr<FakePictureLayer> parent = | |
| 4210 CreateDrawablePictureLayer(&delegate); | |
| 4211 SetLayerPropertiesForTesting(parent.get(), | |
| 4212 identity_matrix, | |
| 4213 gfx::Point3F(), | |
| 4214 gfx::PointF(), | |
| 4215 gfx::Size(100, 100), | |
| 4216 false, | |
| 4217 true); | |
| 4218 | |
| 4219 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); | |
| 4220 SetLayerPropertiesForTesting(child.get(), | |
| 4221 identity_matrix, | |
| 4222 gfx::Point3F(), | |
| 4223 gfx::PointF(2.f, 2.f), | |
| 4224 gfx::Size(10, 10), | |
| 4225 false, | |
| 4226 true); | |
| 4227 | |
| 4228 scoped_refptr<FakePictureLayer> child_empty = | |
| 4229 CreateDrawablePictureLayer(&delegate); | |
| 4230 SetLayerPropertiesForTesting(child_empty.get(), | |
| 4231 identity_matrix, | |
| 4232 gfx::Point3F(), | |
| 4233 gfx::PointF(2.f, 2.f), | |
| 4234 gfx::Size(), | |
| 4235 false, | |
| 4236 true); | |
| 4237 | |
| 4238 parent->AddChild(child); | |
| 4239 parent->AddChild(child_empty); | |
| 4240 | |
| 4241 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 4242 host->SetRootLayer(parent); | |
| 4243 | |
| 4244 float device_scale_factor = 2.5f; | |
| 4245 float page_scale_factor = 1.f; | |
| 4246 | |
| 4247 RenderSurfaceLayerList render_surface_layer_list; | |
| 4248 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 4249 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 4250 inputs.device_scale_factor = device_scale_factor; | |
| 4251 inputs.page_scale_factor = page_scale_factor; | |
| 4252 inputs.can_adjust_raster_scales = true; | |
| 4253 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 4254 | |
| 4255 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); | |
| 4256 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child); | |
| 4257 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child_empty); | |
| 4258 | |
| 4259 EXPECT_EQ(1u, render_surface_layer_list.size()); | |
| 4260 | |
| 4261 // Verify parent transforms | |
| 4262 gfx::Transform expected_parent_transform; | |
| 4263 expected_parent_transform.Scale(device_scale_factor * page_scale_factor, | |
| 4264 device_scale_factor * page_scale_factor); | |
| 4265 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, | |
| 4266 parent->screen_space_transform()); | |
| 4267 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, | |
| 4268 parent->draw_transform()); | |
| 4269 | |
| 4270 // Verify results of transformed parent rects | |
| 4271 gfx::RectF parent_content_bounds(parent->content_bounds()); | |
| 4272 | |
| 4273 gfx::RectF parent_draw_rect = | |
| 4274 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); | |
| 4275 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( | |
| 4276 parent->screen_space_transform(), parent_content_bounds); | |
| 4277 | |
| 4278 gfx::RectF expected_parent_draw_rect(parent->bounds()); | |
| 4279 expected_parent_draw_rect.Scale(device_scale_factor); | |
| 4280 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); | |
| 4281 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); | |
| 4282 | |
| 4283 // Verify child and child_empty transforms. They should match. | |
| 4284 gfx::Transform expected_child_transform; | |
| 4285 expected_child_transform.Scale(device_scale_factor, device_scale_factor); | |
| 4286 expected_child_transform.Translate(child->position().x(), | |
| 4287 child->position().y()); | |
| 4288 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
| 4289 child->draw_transform()); | |
| 4290 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
| 4291 child->screen_space_transform()); | |
| 4292 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
| 4293 child_empty->draw_transform()); | |
| 4294 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
| 4295 child_empty->screen_space_transform()); | |
| 4296 | |
| 4297 // Verify results of transformed child and child_empty rects. They should | |
| 4298 // match. | |
| 4299 gfx::RectF child_content_bounds(child->content_bounds()); | |
| 4300 | |
| 4301 gfx::RectF child_draw_rect = | |
| 4302 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); | |
| 4303 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( | |
| 4304 child->screen_space_transform(), child_content_bounds); | |
| 4305 | |
| 4306 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect( | |
| 4307 child_empty->draw_transform(), child_content_bounds); | |
| 4308 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect( | |
| 4309 child_empty->screen_space_transform(), child_content_bounds); | |
| 4310 | |
| 4311 gfx::RectF expected_child_draw_rect(child->position(), child->bounds()); | |
| 4312 expected_child_draw_rect.Scale(device_scale_factor); | |
| 4313 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); | |
| 4314 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); | |
| 4315 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect); | |
| 4316 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect); | |
| 4317 } | |
| 4318 | |
| 4319 TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) { | |
| 4320 // Verify draw and screen space transforms of layers in a surface. | |
| 4321 MockContentLayerClient delegate; | |
| 4322 gfx::Transform identity_matrix; | |
| 4323 | |
| 4324 gfx::Transform perspective_matrix; | |
| 4325 perspective_matrix.ApplyPerspectiveDepth(2.0); | |
| 4326 | |
| 4327 gfx::Transform scale_small_matrix; | |
| 4328 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); | |
| 4329 | |
| 4330 scoped_refptr<Layer> root = Layer::Create(); | |
| 4331 | |
| 4332 scoped_refptr<FakePictureLayer> parent = | |
| 4333 CreateDrawablePictureLayer(&delegate); | |
| 4334 SetLayerPropertiesForTesting(parent.get(), | |
| 4335 identity_matrix, | |
| 4336 gfx::Point3F(), | |
| 4337 gfx::PointF(), | |
| 4338 gfx::Size(100, 100), | |
| 4339 false, | |
| 4340 true); | |
| 4341 | |
| 4342 scoped_refptr<FakePictureLayer> perspective_surface = | |
| 4343 CreateDrawablePictureLayer(&delegate); | |
| 4344 SetLayerPropertiesForTesting(perspective_surface.get(), | |
| 4345 perspective_matrix * scale_small_matrix, | |
| 4346 gfx::Point3F(), | |
| 4347 gfx::PointF(2.f, 2.f), | |
| 4348 gfx::Size(10, 10), | |
| 4349 false, | |
| 4350 true); | |
| 4351 | |
| 4352 scoped_refptr<FakePictureLayer> scale_surface = | |
| 4353 CreateDrawablePictureLayer(&delegate); | |
| 4354 SetLayerPropertiesForTesting(scale_surface.get(), | |
| 4355 scale_small_matrix, | |
| 4356 gfx::Point3F(), | |
| 4357 gfx::PointF(2.f, 2.f), | |
| 4358 gfx::Size(10, 10), | |
| 4359 false, | |
| 4360 true); | |
| 4361 | |
| 4362 perspective_surface->SetForceRenderSurface(true); | |
| 4363 scale_surface->SetForceRenderSurface(true); | |
| 4364 | |
| 4365 parent->AddChild(perspective_surface); | |
| 4366 parent->AddChild(scale_surface); | |
| 4367 root->AddChild(parent); | |
| 4368 | |
| 4369 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 4370 host->SetRootLayer(root); | |
| 4371 | |
| 4372 float device_scale_factor = 2.5f; | |
| 4373 float page_scale_factor = 3.f; | |
| 4374 | |
| 4375 RenderSurfaceLayerList render_surface_layer_list; | |
| 4376 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 4377 root.get(), parent->bounds(), &render_surface_layer_list); | |
| 4378 inputs.device_scale_factor = device_scale_factor; | |
| 4379 inputs.page_scale_factor = page_scale_factor; | |
| 4380 inputs.page_scale_application_layer = root.get(); | |
| 4381 inputs.can_adjust_raster_scales = true; | |
| 4382 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 4383 | |
| 4384 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); | |
| 4385 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, | |
| 4386 perspective_surface); | |
| 4387 // Ideal scale is the max 2d scale component of the combined transform up to | |
| 4388 // the nearest render target. Here this includes the layer transform as well | |
| 4389 // as the device and page scale factors. | |
| 4390 gfx::Transform transform = scale_small_matrix; | |
| 4391 transform.Scale(device_scale_factor * page_scale_factor, | |
| 4392 device_scale_factor * page_scale_factor); | |
| 4393 gfx::Vector2dF scales = | |
| 4394 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); | |
| 4395 float max_2d_scale = std::max(scales.x(), scales.y()); | |
| 4396 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface); | |
| 4397 | |
| 4398 // The ideal scale will draw 1:1 with its render target space along | |
| 4399 // the larger-scale axis. | |
| 4400 gfx::Vector2dF target_space_transform_scales = | |
| 4401 MathUtil::ComputeTransform2dScaleComponents( | |
| 4402 scale_surface->draw_properties().target_space_transform, 0.f); | |
| 4403 EXPECT_FLOAT_EQ(max_2d_scale, | |
| 4404 std::max(target_space_transform_scales.x(), | |
| 4405 target_space_transform_scales.y())); | |
| 4406 | |
| 4407 EXPECT_EQ(3u, render_surface_layer_list.size()); | |
| 4408 | |
| 4409 gfx::Transform expected_parent_draw_transform; | |
| 4410 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, | |
| 4411 device_scale_factor * page_scale_factor); | |
| 4412 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, | |
| 4413 parent->draw_transform()); | |
| 4414 | |
| 4415 // The scale for the perspective surface is not known, so it is rendered 1:1 | |
| 4416 // with the screen, and then scaled during drawing. | |
| 4417 gfx::Transform expected_perspective_surface_draw_transform; | |
| 4418 expected_perspective_surface_draw_transform.Translate( | |
| 4419 device_scale_factor * page_scale_factor * | |
| 4420 perspective_surface->position().x(), | |
| 4421 device_scale_factor * page_scale_factor * | |
| 4422 perspective_surface->position().y()); | |
| 4423 expected_perspective_surface_draw_transform.PreconcatTransform( | |
| 4424 perspective_matrix); | |
| 4425 expected_perspective_surface_draw_transform.PreconcatTransform( | |
| 4426 scale_small_matrix); | |
| 4427 gfx::Transform expected_perspective_surface_layer_draw_transform; | |
| 4428 expected_perspective_surface_layer_draw_transform.Scale( | |
| 4429 device_scale_factor * page_scale_factor, | |
| 4430 device_scale_factor * page_scale_factor); | |
| 4431 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 4432 expected_perspective_surface_draw_transform, | |
| 4433 perspective_surface->render_surface()->draw_transform()); | |
| 4434 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 4435 expected_perspective_surface_layer_draw_transform, | |
| 4436 perspective_surface->draw_transform()); | |
| 4437 } | |
| 4438 | |
| 4439 // TODO(sohanjg): Remove this test when ContentLayer is removed. | |
| 4440 TEST_F(LayerTreeHostCommonTest, | |
| 4441 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) { | |
| 4442 // Verify draw and screen space transforms of layers not in a surface. | |
| 4443 MockContentLayerClient delegate; | |
| 4444 gfx::Transform identity_matrix; | |
| 4445 | |
| 4446 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); | |
| 4447 SetLayerPropertiesForTesting(parent.get(), | |
| 4448 identity_matrix, | |
| 4449 gfx::Point3F(), | |
| 4450 gfx::PointF(), | |
| 4451 gfx::Size(133, 133), | |
| 4452 false, | |
| 4453 true); | |
| 4454 | |
| 4455 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); | |
| 4456 SetLayerPropertiesForTesting(child.get(), | |
| 4457 identity_matrix, | |
| 4458 gfx::Point3F(), | |
| 4459 gfx::PointF(), | |
| 4460 gfx::Size(13, 13), | |
| 4461 false, | |
| 4462 true); | |
| 4463 | |
| 4464 scoped_refptr<NoScaleContentLayer> child_no_scale = | |
| 4465 CreateNoScaleDrawableContentLayer(&delegate); | |
| 4466 SetLayerPropertiesForTesting(child_no_scale.get(), | |
| 4467 identity_matrix, | |
| 4468 gfx::Point3F(), | |
| 4469 gfx::PointF(), | |
| 4470 gfx::Size(13, 13), | |
| 4471 false, | |
| 4472 true); | |
| 4473 | |
| 4474 parent->AddChild(child); | |
| 4475 parent->AddChild(child_no_scale); | |
| 4476 | |
| 4477 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 4478 host->SetRootLayer(parent); | |
| 4479 | |
| 4480 float device_scale_factor = 1.7f; | |
| 4481 float page_scale_factor = 1.f; | |
| 4482 | |
| 4483 RenderSurfaceLayerList render_surface_layer_list; | |
| 4484 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 4485 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 4486 inputs.device_scale_factor = device_scale_factor; | |
| 4487 inputs.page_scale_factor = page_scale_factor; | |
| 4488 inputs.page_scale_application_layer = parent.get(); | |
| 4489 inputs.can_adjust_raster_scales = true; | |
| 4490 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 4491 | |
| 4492 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); | |
| 4493 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); | |
| 4494 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); | |
| 4495 | |
| 4496 EXPECT_EQ(1u, render_surface_layer_list.size()); | |
| 4497 | |
| 4498 // Verify parent transforms | |
| 4499 gfx::Transform expected_parent_transform; | |
| 4500 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, | |
| 4501 parent->screen_space_transform()); | |
| 4502 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, | |
| 4503 parent->draw_transform()); | |
| 4504 | |
| 4505 // Verify results of transformed parent rects | |
| 4506 gfx::RectF parent_content_bounds(parent->content_bounds()); | |
| 4507 | |
| 4508 gfx::RectF parent_draw_rect = | |
| 4509 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); | |
| 4510 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( | |
| 4511 parent->screen_space_transform(), parent_content_bounds); | |
| 4512 | |
| 4513 gfx::RectF expected_parent_draw_rect(parent->bounds()); | |
| 4514 expected_parent_draw_rect.Scale(device_scale_factor); | |
| 4515 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width())); | |
| 4516 expected_parent_draw_rect.set_height( | |
| 4517 ceil(expected_parent_draw_rect.height())); | |
| 4518 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); | |
| 4519 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); | |
| 4520 | |
| 4521 // Verify child transforms | |
| 4522 gfx::Transform expected_child_transform; | |
| 4523 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
| 4524 child->draw_transform()); | |
| 4525 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
| 4526 child->screen_space_transform()); | |
| 4527 | |
| 4528 // Verify results of transformed child rects | |
| 4529 gfx::RectF child_content_bounds(child->content_bounds()); | |
| 4530 | |
| 4531 gfx::RectF child_draw_rect = | |
| 4532 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); | |
| 4533 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( | |
| 4534 child->screen_space_transform(), child_content_bounds); | |
| 4535 | |
| 4536 gfx::RectF expected_child_draw_rect(child->bounds()); | |
| 4537 expected_child_draw_rect.Scale(device_scale_factor); | |
| 4538 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width())); | |
| 4539 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height())); | |
| 4540 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); | |
| 4541 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); | |
| 4542 | |
| 4543 // Verify child_no_scale transforms | |
| 4544 gfx::Transform expected_child_no_scale_transform = child->draw_transform(); | |
| 4545 // All transforms operate on content rects. The child's content rect | |
| 4546 // incorporates device scale, but the child_no_scale does not; add it here. | |
| 4547 expected_child_no_scale_transform.Scale(device_scale_factor, | |
| 4548 device_scale_factor); | |
| 4549 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, | |
| 4550 child_no_scale->draw_transform()); | |
| 4551 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, | |
| 4552 child_no_scale->screen_space_transform()); | |
| 4553 } | |
| 4554 | |
| 4555 // TODO(sohanjg): Remove this test when ContentLayer is removed. | |
| 4556 TEST_F(LayerTreeHostCommonTest, ContentsScale) { | |
| 4557 MockContentLayerClient delegate; | |
| 4558 gfx::Transform identity_matrix; | |
| 4559 | |
| 4560 gfx::Transform parent_scale_matrix; | |
| 4561 SkMScalar initial_parent_scale = 1.75; | |
| 4562 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); | |
| 4563 | |
| 4564 gfx::Transform child_scale_matrix; | |
| 4565 SkMScalar initial_child_scale = 1.25; | |
| 4566 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); | |
| 4567 | |
| 4568 scoped_refptr<Layer> root = Layer::Create(); | |
| 4569 root->SetBounds(gfx::Size(100, 100)); | |
| 4570 | |
| 4571 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); | |
| 4572 SetLayerPropertiesForTesting(parent.get(), | |
| 4573 parent_scale_matrix, | |
| 4574 gfx::Point3F(), | |
| 4575 gfx::PointF(), | |
| 4576 gfx::Size(100, 100), | |
| 4577 false, | |
| 4578 true); | |
| 4579 | |
| 4580 scoped_refptr<ContentLayer> child_scale = | |
| 4581 CreateDrawableContentLayer(&delegate); | |
| 4582 SetLayerPropertiesForTesting(child_scale.get(), | |
| 4583 child_scale_matrix, | |
| 4584 gfx::Point3F(), | |
| 4585 gfx::PointF(2.f, 2.f), | |
| 4586 gfx::Size(10, 10), | |
| 4587 false, | |
| 4588 true); | |
| 4589 | |
| 4590 scoped_refptr<ContentLayer> child_empty = | |
| 4591 CreateDrawableContentLayer(&delegate); | |
| 4592 SetLayerPropertiesForTesting(child_empty.get(), | |
| 4593 child_scale_matrix, | |
| 4594 gfx::Point3F(), | |
| 4595 gfx::PointF(2.f, 2.f), | |
| 4596 gfx::Size(), | |
| 4597 false, | |
| 4598 true); | |
| 4599 | |
| 4600 scoped_refptr<NoScaleContentLayer> child_no_scale = | |
| 4601 CreateNoScaleDrawableContentLayer(&delegate); | |
| 4602 SetLayerPropertiesForTesting(child_no_scale.get(), | |
| 4603 child_scale_matrix, | |
| 4604 gfx::Point3F(), | |
| 4605 gfx::PointF(12.f, 12.f), | |
| 4606 gfx::Size(10, 10), | |
| 4607 false, | |
| 4608 true); | |
| 4609 | |
| 4610 root->AddChild(parent); | |
| 4611 | |
| 4612 parent->AddChild(child_scale); | |
| 4613 parent->AddChild(child_empty); | |
| 4614 parent->AddChild(child_no_scale); | |
| 4615 | |
| 4616 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 4617 host->SetRootLayer(root); | |
| 4618 | |
| 4619 float device_scale_factor = 2.5f; | |
| 4620 float page_scale_factor = 1.f; | |
| 4621 | |
| 4622 { | |
| 4623 RenderSurfaceLayerList render_surface_layer_list; | |
| 4624 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 4625 root.get(), root->bounds(), &render_surface_layer_list); | |
| 4626 inputs.device_scale_factor = device_scale_factor; | |
| 4627 inputs.page_scale_factor = page_scale_factor; | |
| 4628 inputs.page_scale_application_layer = root.get(); | |
| 4629 inputs.can_adjust_raster_scales = true; | |
| 4630 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 4631 | |
| 4632 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * | |
| 4633 initial_parent_scale, parent); | |
| 4634 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * | |
| 4635 initial_parent_scale * initial_child_scale, | |
| 4636 child_scale); | |
| 4637 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * | |
| 4638 initial_parent_scale * initial_child_scale, | |
| 4639 child_empty); | |
| 4640 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); | |
| 4641 | |
| 4642 // The parent is scaled up and shouldn't need to scale during draw. The | |
| 4643 // child that can scale its contents should also not need to scale during | |
| 4644 // draw. This shouldn't change if the child has empty bounds. The other | |
| 4645 // children should. | |
| 4646 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); | |
| 4647 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); | |
| 4648 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0)); | |
| 4649 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1)); | |
| 4650 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0)); | |
| 4651 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1)); | |
| 4652 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * | |
| 4653 initial_parent_scale * initial_child_scale, | |
| 4654 child_no_scale->draw_transform().matrix().get(0, 0)); | |
| 4655 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * | |
| 4656 initial_parent_scale * initial_child_scale, | |
| 4657 child_no_scale->draw_transform().matrix().get(1, 1)); | |
| 4658 } | |
| 4659 | |
| 4660 // If the device_scale_factor or page_scale_factor changes, then it should be | |
| 4661 // updated using the initial transform as the raster scale. | |
| 4662 device_scale_factor = 2.25f; | |
| 4663 page_scale_factor = 1.25f; | |
| 4664 | |
| 4665 { | |
| 4666 RenderSurfaceLayerList render_surface_layer_list; | |
| 4667 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 4668 root.get(), root->bounds(), &render_surface_layer_list); | |
| 4669 inputs.device_scale_factor = device_scale_factor; | |
| 4670 inputs.page_scale_factor = page_scale_factor; | |
| 4671 inputs.page_scale_application_layer = root.get(); | |
| 4672 inputs.can_adjust_raster_scales = true; | |
| 4673 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 4674 | |
| 4675 EXPECT_CONTENTS_SCALE_EQ( | |
| 4676 device_scale_factor * page_scale_factor * initial_parent_scale, parent); | |
| 4677 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * | |
| 4678 initial_parent_scale * initial_child_scale, | |
| 4679 child_scale); | |
| 4680 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * | |
| 4681 initial_parent_scale * initial_child_scale, | |
| 4682 child_empty); | |
| 4683 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); | |
| 4684 } | |
| 4685 | |
| 4686 // If the transform changes, we expect the raster scale to be reset to 1.0. | |
| 4687 SkMScalar second_child_scale = 1.75; | |
| 4688 child_scale_matrix.Scale(second_child_scale / initial_child_scale, | |
| 4689 second_child_scale / initial_child_scale); | |
| 4690 child_scale->SetTransform(child_scale_matrix); | |
| 4691 child_empty->SetTransform(child_scale_matrix); | |
| 4692 | |
| 4693 { | |
| 4694 RenderSurfaceLayerList render_surface_layer_list; | |
| 4695 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 4696 root.get(), root->bounds(), &render_surface_layer_list); | |
| 4697 inputs.device_scale_factor = device_scale_factor; | |
| 4698 inputs.page_scale_factor = page_scale_factor; | |
| 4699 inputs.page_scale_application_layer = root.get(); | |
| 4700 inputs.can_adjust_raster_scales = true; | |
| 4701 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 4702 | |
| 4703 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * | |
| 4704 initial_parent_scale, | |
| 4705 parent); | |
| 4706 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | |
| 4707 child_scale); | |
| 4708 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | |
| 4709 child_empty); | |
| 4710 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); | |
| 4711 } | |
| 4712 | |
| 4713 // If the device_scale_factor or page_scale_factor changes, then it should be | |
| 4714 // updated, but still using 1.0 as the raster scale. | |
| 4715 device_scale_factor = 2.75f; | |
| 4716 page_scale_factor = 1.75f; | |
| 4717 | |
| 4718 { | |
| 4719 RenderSurfaceLayerList render_surface_layer_list; | |
| 4720 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 4721 root.get(), root->bounds(), &render_surface_layer_list); | |
| 4722 inputs.device_scale_factor = device_scale_factor; | |
| 4723 inputs.page_scale_factor = page_scale_factor; | |
| 4724 inputs.page_scale_application_layer = root.get(); | |
| 4725 inputs.can_adjust_raster_scales = true; | |
| 4726 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 4727 | |
| 4728 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * | |
| 4729 initial_parent_scale, | |
| 4730 parent); | |
| 4731 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | |
| 4732 child_scale); | |
| 4733 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | |
| 4734 child_empty); | |
| 4735 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); | |
| 4736 } | |
| 4737 } | |
| 4738 | |
| 4739 // TODO(sohanjg): Remove this test when ContentLayer is removed. | |
| 4740 TEST_F(LayerTreeHostCommonTest, | |
| 4741 ContentsScale_LayerTransformsDontAffectContentsScale) { | |
| 4742 MockContentLayerClient delegate; | |
| 4743 gfx::Transform identity_matrix; | |
| 4744 | |
| 4745 gfx::Transform parent_scale_matrix; | |
| 4746 SkMScalar initial_parent_scale = 1.75; | |
| 4747 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); | |
| 4748 | |
| 4749 gfx::Transform child_scale_matrix; | |
| 4750 SkMScalar initial_child_scale = 1.25; | |
| 4751 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); | |
| 4752 | |
| 4753 scoped_refptr<Layer> root = Layer::Create(); | |
| 4754 root->SetBounds(gfx::Size(100, 100)); | |
| 4755 | |
| 4756 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); | |
| 4757 SetLayerPropertiesForTesting(parent.get(), | |
| 4758 parent_scale_matrix, | |
| 4759 gfx::Point3F(), | |
| 4760 gfx::PointF(), | |
| 4761 gfx::Size(100, 100), | |
| 4762 false, | |
| 4763 true); | |
| 4764 | |
| 4765 scoped_refptr<ContentLayer> child_scale = | |
| 4766 CreateDrawableContentLayer(&delegate); | |
| 4767 SetLayerPropertiesForTesting(child_scale.get(), | |
| 4768 child_scale_matrix, | |
| 4769 gfx::Point3F(), | |
| 4770 gfx::PointF(2.f, 2.f), | |
| 4771 gfx::Size(10, 10), | |
| 4772 false, | |
| 4773 true); | |
| 4774 | |
| 4775 scoped_refptr<ContentLayer> child_empty = | |
| 4776 CreateDrawableContentLayer(&delegate); | |
| 4777 SetLayerPropertiesForTesting(child_empty.get(), | |
| 4778 child_scale_matrix, | |
| 4779 gfx::Point3F(), | |
| 4780 gfx::PointF(2.f, 2.f), | |
| 4781 gfx::Size(), | |
| 4782 false, | |
| 4783 true); | |
| 4784 | |
| 4785 scoped_refptr<NoScaleContentLayer> child_no_scale = | |
| 4786 CreateNoScaleDrawableContentLayer(&delegate); | |
| 4787 SetLayerPropertiesForTesting(child_no_scale.get(), | |
| 4788 child_scale_matrix, | |
| 4789 gfx::Point3F(), | |
| 4790 gfx::PointF(12.f, 12.f), | |
| 4791 gfx::Size(10, 10), | |
| 4792 false, | |
| 4793 true); | |
| 4794 | |
| 4795 root->AddChild(parent); | |
| 4796 | |
| 4797 parent->AddChild(child_scale); | |
| 4798 parent->AddChild(child_empty); | |
| 4799 parent->AddChild(child_no_scale); | |
| 4800 | |
| 4801 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 4802 host->SetRootLayer(root); | |
| 4803 | |
| 4804 RenderSurfaceLayerList render_surface_layer_list; | |
| 4805 | |
| 4806 float device_scale_factor = 2.5f; | |
| 4807 float page_scale_factor = 1.f; | |
| 4808 | |
| 4809 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 4810 root.get(), root->bounds(), &render_surface_layer_list); | |
| 4811 inputs.device_scale_factor = device_scale_factor; | |
| 4812 inputs.page_scale_factor = page_scale_factor; | |
| 4813 inputs.page_scale_application_layer = root.get(), | |
| 4814 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 4815 | |
| 4816 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); | |
| 4817 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | |
| 4818 child_scale); | |
| 4819 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | |
| 4820 child_empty); | |
| 4821 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); | |
| 4822 | |
| 4823 // Since the transform scale does not affect contents scale, it should affect | |
| 4824 // the draw transform instead. | |
| 4825 EXPECT_FLOAT_EQ(initial_parent_scale, | |
| 4826 parent->draw_transform().matrix().get(0, 0)); | |
| 4827 EXPECT_FLOAT_EQ(initial_parent_scale, | |
| 4828 parent->draw_transform().matrix().get(1, 1)); | |
| 4829 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, | |
| 4830 child_scale->draw_transform().matrix().get(0, 0)); | |
| 4831 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, | |
| 4832 child_scale->draw_transform().matrix().get(1, 1)); | |
| 4833 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, | |
| 4834 child_empty->draw_transform().matrix().get(0, 0)); | |
| 4835 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, | |
| 4836 child_empty->draw_transform().matrix().get(1, 1)); | |
| 4837 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * | |
| 4838 initial_parent_scale * initial_child_scale, | |
| 4839 child_no_scale->draw_transform().matrix().get(0, 0)); | |
| 4840 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * | |
| 4841 initial_parent_scale * initial_child_scale, | |
| 4842 child_no_scale->draw_transform().matrix().get(1, 1)); | |
| 4843 } | |
| 4844 | |
| 4845 TEST_F(LayerTreeHostCommonTest, SmallIdealScale) { | |
| 4846 MockContentLayerClient delegate; | |
| 4847 gfx::Transform identity_matrix; | |
| 4848 | |
| 4849 gfx::Transform parent_scale_matrix; | |
| 4850 SkMScalar initial_parent_scale = 1.75; | |
| 4851 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); | |
| 4852 | |
| 4853 gfx::Transform child_scale_matrix; | |
| 4854 SkMScalar initial_child_scale = 0.25; | |
| 4855 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); | |
| 4856 | |
| 4857 scoped_refptr<Layer> root = Layer::Create(); | |
| 4858 root->SetBounds(gfx::Size(100, 100)); | |
| 4859 | |
| 4860 scoped_refptr<FakePictureLayer> parent = | |
| 4861 CreateDrawablePictureLayer(&delegate); | |
| 4862 SetLayerPropertiesForTesting(parent.get(), | |
| 4863 parent_scale_matrix, | |
| 4864 gfx::Point3F(), | |
| 4865 gfx::PointF(), | |
| 4866 gfx::Size(100, 100), | |
| 4867 false, | |
| 4868 true); | |
| 4869 | |
| 4870 scoped_refptr<FakePictureLayer> child_scale = | |
| 4871 CreateDrawablePictureLayer(&delegate); | |
| 4872 SetLayerPropertiesForTesting(child_scale.get(), | |
| 4873 child_scale_matrix, | |
| 4874 gfx::Point3F(), | |
| 4875 gfx::PointF(2.f, 2.f), | |
| 4876 gfx::Size(10, 10), | |
| 4877 false, | |
| 4878 true); | |
| 4879 | |
| 4880 root->AddChild(parent); | |
| 4881 | |
| 4882 parent->AddChild(child_scale); | |
| 4883 | |
| 4884 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 4885 host->SetRootLayer(root); | |
| 4886 | |
| 4887 float device_scale_factor = 2.5f; | |
| 4888 float page_scale_factor = 0.01f; | |
| 4889 | |
| 4890 { | |
| 4891 RenderSurfaceLayerList render_surface_layer_list; | |
| 4892 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 4893 root.get(), root->bounds(), &render_surface_layer_list); | |
| 4894 inputs.device_scale_factor = device_scale_factor; | |
| 4895 inputs.page_scale_factor = page_scale_factor; | |
| 4896 inputs.page_scale_application_layer = root.get(); | |
| 4897 inputs.can_adjust_raster_scales = true; | |
| 4898 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 4899 | |
| 4900 // The ideal scale is able to go below 1. | |
| 4901 float expected_ideal_scale = | |
| 4902 device_scale_factor * page_scale_factor * initial_parent_scale; | |
| 4903 EXPECT_LT(expected_ideal_scale, 1.f); | |
| 4904 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent); | |
| 4905 | |
| 4906 expected_ideal_scale = device_scale_factor * page_scale_factor * | |
| 4907 initial_parent_scale * initial_child_scale; | |
| 4908 EXPECT_LT(expected_ideal_scale, 1.f); | |
| 4909 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale); | |
| 4910 } | |
| 4911 } | |
| 4912 | |
| 4913 TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) { | |
| 4914 MockContentLayerClient delegate; | |
| 4915 gfx::Transform identity_matrix; | |
| 4916 | |
| 4917 gfx::Transform parent_scale_matrix; | |
| 4918 SkMScalar initial_parent_scale = 2.0; | |
| 4919 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); | |
| 4920 | |
| 4921 gfx::Transform child_scale_matrix; | |
| 4922 SkMScalar initial_child_scale = 3.0; | |
| 4923 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); | |
| 4924 | |
| 4925 scoped_refptr<Layer> root = Layer::Create(); | |
| 4926 root->SetBounds(gfx::Size(100, 100)); | |
| 4927 | |
| 4928 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); | |
| 4929 SetLayerPropertiesForTesting(parent.get(), | |
| 4930 parent_scale_matrix, | |
| 4931 gfx::Point3F(), | |
| 4932 gfx::PointF(), | |
| 4933 gfx::Size(100, 100), | |
| 4934 false, | |
| 4935 true); | |
| 4936 | |
| 4937 scoped_refptr<ContentLayer> surface_scale = | |
| 4938 CreateDrawableContentLayer(&delegate); | |
| 4939 SetLayerPropertiesForTesting(surface_scale.get(), | |
| 4940 child_scale_matrix, | |
| 4941 gfx::Point3F(), | |
| 4942 gfx::PointF(2.f, 2.f), | |
| 4943 gfx::Size(10, 10), | |
| 4944 false, | |
| 4945 true); | |
| 4946 | |
| 4947 scoped_refptr<ContentLayer> surface_scale_child_scale = | |
| 4948 CreateDrawableContentLayer(&delegate); | |
| 4949 SetLayerPropertiesForTesting(surface_scale_child_scale.get(), | |
| 4950 child_scale_matrix, | |
| 4951 gfx::Point3F(), | |
| 4952 gfx::PointF(), | |
| 4953 gfx::Size(10, 10), | |
| 4954 false, | |
| 4955 true); | |
| 4956 | |
| 4957 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = | |
| 4958 CreateNoScaleDrawableContentLayer(&delegate); | |
| 4959 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), | |
| 4960 child_scale_matrix, | |
| 4961 gfx::Point3F(), | |
| 4962 gfx::PointF(), | |
| 4963 gfx::Size(10, 10), | |
| 4964 false, | |
| 4965 true); | |
| 4966 | |
| 4967 scoped_refptr<NoScaleContentLayer> surface_no_scale = | |
| 4968 CreateNoScaleDrawableContentLayer(&delegate); | |
| 4969 SetLayerPropertiesForTesting(surface_no_scale.get(), | |
| 4970 child_scale_matrix, | |
| 4971 gfx::Point3F(), | |
| 4972 gfx::PointF(12.f, 12.f), | |
| 4973 gfx::Size(10, 10), | |
| 4974 false, | |
| 4975 true); | |
| 4976 | |
| 4977 scoped_refptr<ContentLayer> surface_no_scale_child_scale = | |
| 4978 CreateDrawableContentLayer(&delegate); | |
| 4979 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), | |
| 4980 child_scale_matrix, | |
| 4981 gfx::Point3F(), | |
| 4982 gfx::PointF(), | |
| 4983 gfx::Size(10, 10), | |
| 4984 false, | |
| 4985 true); | |
| 4986 | |
| 4987 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = | |
| 4988 CreateNoScaleDrawableContentLayer(&delegate); | |
| 4989 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), | |
| 4990 child_scale_matrix, | |
| 4991 gfx::Point3F(), | |
| 4992 gfx::PointF(), | |
| 4993 gfx::Size(10, 10), | |
| 4994 false, | |
| 4995 true); | |
| 4996 | |
| 4997 root->AddChild(parent); | |
| 4998 | |
| 4999 parent->AddChild(surface_scale); | |
| 5000 parent->AddChild(surface_no_scale); | |
| 5001 | |
| 5002 surface_scale->SetForceRenderSurface(true); | |
| 5003 surface_scale->AddChild(surface_scale_child_scale); | |
| 5004 surface_scale->AddChild(surface_scale_child_no_scale); | |
| 5005 | |
| 5006 surface_no_scale->SetForceRenderSurface(true); | |
| 5007 surface_no_scale->AddChild(surface_no_scale_child_scale); | |
| 5008 surface_no_scale->AddChild(surface_no_scale_child_no_scale); | |
| 5009 | |
| 5010 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 5011 host->SetRootLayer(root); | |
| 5012 | |
| 5013 SkMScalar device_scale_factor = 5; | |
| 5014 SkMScalar page_scale_factor = 7; | |
| 5015 | |
| 5016 RenderSurfaceLayerList render_surface_layer_list; | |
| 5017 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 5018 root.get(), root->bounds(), &render_surface_layer_list); | |
| 5019 inputs.device_scale_factor = device_scale_factor; | |
| 5020 inputs.page_scale_factor = page_scale_factor; | |
| 5021 inputs.page_scale_application_layer = root.get(); | |
| 5022 inputs.can_adjust_raster_scales = true; | |
| 5023 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 5024 | |
| 5025 EXPECT_CONTENTS_SCALE_EQ( | |
| 5026 device_scale_factor * page_scale_factor * initial_parent_scale, parent); | |
| 5027 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * | |
| 5028 initial_parent_scale * initial_child_scale, | |
| 5029 surface_scale); | |
| 5030 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale); | |
| 5031 EXPECT_CONTENTS_SCALE_EQ( | |
| 5032 device_scale_factor * page_scale_factor * initial_parent_scale * | |
| 5033 initial_child_scale * initial_child_scale, | |
| 5034 surface_scale_child_scale); | |
| 5035 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale); | |
| 5036 EXPECT_CONTENTS_SCALE_EQ( | |
| 5037 device_scale_factor * page_scale_factor * initial_parent_scale * | |
| 5038 initial_child_scale * initial_child_scale, | |
| 5039 surface_no_scale_child_scale); | |
| 5040 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale); | |
| 5041 | |
| 5042 // The parent is scaled up and shouldn't need to scale during draw. | |
| 5043 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); | |
| 5044 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); | |
| 5045 | |
| 5046 // RenderSurfaces should always be 1:1 with their target. | |
| 5047 EXPECT_FLOAT_EQ( | |
| 5048 1.0, | |
| 5049 surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); | |
| 5050 EXPECT_FLOAT_EQ( | |
| 5051 1.0, | |
| 5052 surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); | |
| 5053 | |
| 5054 // The surface_scale can apply contents scale so the layer shouldn't need to | |
| 5055 // scale during draw. | |
| 5056 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0)); | |
| 5057 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1)); | |
| 5058 | |
| 5059 // The surface_scale_child_scale can apply contents scale so it shouldn't need | |
| 5060 // to scale during draw. | |
| 5061 EXPECT_FLOAT_EQ( | |
| 5062 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0)); | |
| 5063 EXPECT_FLOAT_EQ( | |
| 5064 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1)); | |
| 5065 | |
| 5066 // The surface_scale_child_no_scale can not apply contents scale, so it needs | |
| 5067 // to be scaled during draw. | |
| 5068 EXPECT_FLOAT_EQ( | |
| 5069 device_scale_factor * page_scale_factor * initial_parent_scale * | |
| 5070 initial_child_scale * initial_child_scale, | |
| 5071 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); | |
| 5072 EXPECT_FLOAT_EQ( | |
| 5073 device_scale_factor * page_scale_factor * initial_parent_scale * | |
| 5074 initial_child_scale * initial_child_scale, | |
| 5075 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); | |
| 5076 | |
| 5077 // RenderSurfaces should always be 1:1 with their target. | |
| 5078 EXPECT_FLOAT_EQ( | |
| 5079 1.0, | |
| 5080 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); | |
| 5081 EXPECT_FLOAT_EQ( | |
| 5082 1.0, | |
| 5083 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); | |
| 5084 | |
| 5085 // The surface_no_scale layer can not apply contents scale, so it needs to be | |
| 5086 // scaled during draw. | |
| 5087 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * | |
| 5088 initial_parent_scale * initial_child_scale, | |
| 5089 surface_no_scale->draw_transform().matrix().get(0, 0)); | |
| 5090 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * | |
| 5091 initial_parent_scale * initial_child_scale, | |
| 5092 surface_no_scale->draw_transform().matrix().get(1, 1)); | |
| 5093 | |
| 5094 // The surface_scale_child_scale can apply contents scale so it shouldn't need | |
| 5095 // to scale during draw. | |
| 5096 EXPECT_FLOAT_EQ( | |
| 5097 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); | |
| 5098 EXPECT_FLOAT_EQ( | |
| 5099 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); | |
| 5100 | |
| 5101 // The surface_scale_child_no_scale can not apply contents scale, so it needs | |
| 5102 // to be scaled during draw. | |
| 5103 EXPECT_FLOAT_EQ( | |
| 5104 device_scale_factor * page_scale_factor * initial_parent_scale * | |
| 5105 initial_child_scale * initial_child_scale, | |
| 5106 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); | |
| 5107 EXPECT_FLOAT_EQ( | |
| 5108 device_scale_factor * page_scale_factor * initial_parent_scale * | |
| 5109 initial_child_scale * initial_child_scale, | |
| 5110 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); | |
| 5111 } | |
| 5112 | |
| 5113 // TODO(sohanjg): Remove this test when ContentLayer is removed. | |
| 5114 TEST_F(LayerTreeHostCommonTest, | |
| 5115 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) { | |
| 5116 MockContentLayerClient delegate; | |
| 5117 gfx::Transform identity_matrix; | |
| 5118 | |
| 5119 gfx::Transform parent_scale_matrix; | |
| 5120 SkMScalar initial_parent_scale = 2.0; | |
| 5121 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); | |
| 5122 | |
| 5123 gfx::Transform child_scale_matrix; | |
| 5124 SkMScalar initial_child_scale = 3.0; | |
| 5125 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); | |
| 5126 | |
| 5127 scoped_refptr<Layer> root = Layer::Create(); | |
| 5128 root->SetBounds(gfx::Size(100, 100)); | |
| 5129 | |
| 5130 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); | |
| 5131 SetLayerPropertiesForTesting(parent.get(), | |
| 5132 parent_scale_matrix, | |
| 5133 gfx::Point3F(), | |
| 5134 gfx::PointF(), | |
| 5135 gfx::Size(100, 100), | |
| 5136 false, | |
| 5137 true); | |
| 5138 | |
| 5139 scoped_refptr<ContentLayer> surface_scale = | |
| 5140 CreateDrawableContentLayer(&delegate); | |
| 5141 SetLayerPropertiesForTesting(surface_scale.get(), | |
| 5142 child_scale_matrix, | |
| 5143 gfx::Point3F(), | |
| 5144 gfx::PointF(2.f, 2.f), | |
| 5145 gfx::Size(10, 10), | |
| 5146 false, | |
| 5147 true); | |
| 5148 | |
| 5149 scoped_refptr<ContentLayer> surface_scale_child_scale = | |
| 5150 CreateDrawableContentLayer(&delegate); | |
| 5151 SetLayerPropertiesForTesting(surface_scale_child_scale.get(), | |
| 5152 child_scale_matrix, | |
| 5153 gfx::Point3F(), | |
| 5154 gfx::PointF(), | |
| 5155 gfx::Size(10, 10), | |
| 5156 false, | |
| 5157 true); | |
| 5158 | |
| 5159 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = | |
| 5160 CreateNoScaleDrawableContentLayer(&delegate); | |
| 5161 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), | |
| 5162 child_scale_matrix, | |
| 5163 gfx::Point3F(), | |
| 5164 gfx::PointF(), | |
| 5165 gfx::Size(10, 10), | |
| 5166 false, | |
| 5167 true); | |
| 5168 | |
| 5169 scoped_refptr<NoScaleContentLayer> surface_no_scale = | |
| 5170 CreateNoScaleDrawableContentLayer(&delegate); | |
| 5171 SetLayerPropertiesForTesting(surface_no_scale.get(), | |
| 5172 child_scale_matrix, | |
| 5173 gfx::Point3F(), | |
| 5174 gfx::PointF(12.f, 12.f), | |
| 5175 gfx::Size(10, 10), | |
| 5176 false, | |
| 5177 true); | |
| 5178 | |
| 5179 scoped_refptr<ContentLayer> surface_no_scale_child_scale = | |
| 5180 CreateDrawableContentLayer(&delegate); | |
| 5181 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), | |
| 5182 child_scale_matrix, | |
| 5183 gfx::Point3F(), | |
| 5184 gfx::PointF(), | |
| 5185 gfx::Size(10, 10), | |
| 5186 false, | |
| 5187 true); | |
| 5188 | |
| 5189 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = | |
| 5190 CreateNoScaleDrawableContentLayer(&delegate); | |
| 5191 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), | |
| 5192 child_scale_matrix, | |
| 5193 gfx::Point3F(), | |
| 5194 gfx::PointF(), | |
| 5195 gfx::Size(10, 10), | |
| 5196 false, | |
| 5197 true); | |
| 5198 | |
| 5199 root->AddChild(parent); | |
| 5200 | |
| 5201 parent->AddChild(surface_scale); | |
| 5202 parent->AddChild(surface_no_scale); | |
| 5203 | |
| 5204 surface_scale->SetForceRenderSurface(true); | |
| 5205 surface_scale->AddChild(surface_scale_child_scale); | |
| 5206 surface_scale->AddChild(surface_scale_child_no_scale); | |
| 5207 | |
| 5208 surface_no_scale->SetForceRenderSurface(true); | |
| 5209 surface_no_scale->AddChild(surface_no_scale_child_scale); | |
| 5210 surface_no_scale->AddChild(surface_no_scale_child_no_scale); | |
| 5211 | |
| 5212 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 5213 host->SetRootLayer(root); | |
| 5214 | |
| 5215 RenderSurfaceLayerList render_surface_layer_list; | |
| 5216 | |
| 5217 SkMScalar device_scale_factor = 5.0; | |
| 5218 SkMScalar page_scale_factor = 7.0; | |
| 5219 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 5220 root.get(), root->bounds(), &render_surface_layer_list); | |
| 5221 inputs.device_scale_factor = device_scale_factor; | |
| 5222 inputs.page_scale_factor = page_scale_factor; | |
| 5223 inputs.page_scale_application_layer = root.get(); | |
| 5224 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 5225 | |
| 5226 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | |
| 5227 parent); | |
| 5228 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | |
| 5229 surface_scale); | |
| 5230 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale); | |
| 5231 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | |
| 5232 surface_scale_child_scale); | |
| 5233 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale); | |
| 5234 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | |
| 5235 surface_no_scale_child_scale); | |
| 5236 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale); | |
| 5237 | |
| 5238 // The parent is scaled up during draw, since its contents are not scaled by | |
| 5239 // the transform hierarchy. | |
| 5240 EXPECT_FLOAT_EQ(initial_parent_scale, | |
| 5241 parent->draw_transform().matrix().get(0, 0)); | |
| 5242 EXPECT_FLOAT_EQ(initial_parent_scale, | |
| 5243 parent->draw_transform().matrix().get(1, 1)); | |
| 5244 | |
| 5245 // The child surface is not scaled up during draw since its subtree is scaled | |
| 5246 // by the transform hierarchy. | |
| 5247 EXPECT_FLOAT_EQ( | |
| 5248 1.f, | |
| 5249 surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); | |
| 5250 EXPECT_FLOAT_EQ( | |
| 5251 1.f, | |
| 5252 surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); | |
| 5253 | |
| 5254 // The surface_scale's RenderSurface is not scaled during draw, so the layer | |
| 5255 // needs to be scaled when drawing into its surface. | |
| 5256 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, | |
| 5257 surface_scale->draw_transform().matrix().get(0, 0)); | |
| 5258 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, | |
| 5259 surface_scale->draw_transform().matrix().get(1, 1)); | |
| 5260 | |
| 5261 // The surface_scale_child_scale is not scaled when drawing into its surface, | |
| 5262 // since its content bounds are scaled by the transform hierarchy. | |
| 5263 EXPECT_FLOAT_EQ( | |
| 5264 initial_child_scale * initial_child_scale * initial_parent_scale, | |
| 5265 surface_scale_child_scale->draw_transform().matrix().get(0, 0)); | |
| 5266 EXPECT_FLOAT_EQ( | |
| 5267 initial_child_scale * initial_child_scale * initial_parent_scale, | |
| 5268 surface_scale_child_scale->draw_transform().matrix().get(1, 1)); | |
| 5269 | |
| 5270 // The surface_scale_child_no_scale is scaled by the device scale, page scale | |
| 5271 // and transform hierarchy. | |
| 5272 EXPECT_FLOAT_EQ( | |
| 5273 device_scale_factor * page_scale_factor * initial_parent_scale * | |
| 5274 initial_child_scale * initial_child_scale, | |
| 5275 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); | |
| 5276 EXPECT_FLOAT_EQ( | |
| 5277 device_scale_factor * page_scale_factor * initial_parent_scale * | |
| 5278 initial_child_scale * initial_child_scale, | |
| 5279 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); | |
| 5280 | |
| 5281 // The child surface is not scaled up during draw since its subtree is scaled | |
| 5282 // by the transform hierarchy. | |
| 5283 EXPECT_FLOAT_EQ( | |
| 5284 1.f, | |
| 5285 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); | |
| 5286 EXPECT_FLOAT_EQ( | |
| 5287 1.f, | |
| 5288 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); | |
| 5289 | |
| 5290 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to | |
| 5291 // be scaled by the device and page scale factors. Its surface is already | |
| 5292 // scaled by the transform hierarchy so those don't need to scale the layer's | |
| 5293 // drawing. | |
| 5294 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale * | |
| 5295 device_scale_factor * page_scale_factor, | |
| 5296 surface_no_scale->draw_transform().matrix().get(0, 0)); | |
| 5297 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale * | |
| 5298 device_scale_factor * page_scale_factor, | |
| 5299 surface_no_scale->draw_transform().matrix().get(1, 1)); | |
| 5300 | |
| 5301 // The surface_no_scale_child_scale has its contents scaled by the page and | |
| 5302 // device scale factors, but needs to be scaled by the transform hierarchy | |
| 5303 // when drawing. | |
| 5304 EXPECT_FLOAT_EQ( | |
| 5305 initial_parent_scale * initial_child_scale * initial_child_scale, | |
| 5306 surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); | |
| 5307 EXPECT_FLOAT_EQ( | |
| 5308 initial_parent_scale * initial_child_scale * initial_child_scale, | |
| 5309 surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); | |
| 5310 | |
| 5311 // The surface_no_scale_child_no_scale needs to be scaled by the device and | |
| 5312 // page scale factors and by any transform heirarchy below its target surface. | |
| 5313 EXPECT_FLOAT_EQ( | |
| 5314 device_scale_factor * page_scale_factor * initial_parent_scale * | |
| 5315 initial_child_scale * initial_child_scale, | |
| 5316 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); | |
| 5317 EXPECT_FLOAT_EQ( | |
| 5318 device_scale_factor * page_scale_factor * initial_parent_scale * | |
| 5319 initial_child_scale * initial_child_scale, | |
| 5320 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); | |
| 5321 } | |
| 5322 | |
| 5323 TEST_F(LayerTreeHostCommonTest, IdealScaleForAnimatingLayer) { | |
| 5324 MockContentLayerClient delegate; | |
| 5325 gfx::Transform identity_matrix; | |
| 5326 | |
| 5327 gfx::Transform parent_scale_matrix; | |
| 5328 SkMScalar initial_parent_scale = 1.75; | |
| 5329 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); | |
| 5330 | |
| 5331 gfx::Transform child_scale_matrix; | |
| 5332 SkMScalar initial_child_scale = 1.25; | |
| 5333 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); | |
| 5334 | |
| 5335 scoped_refptr<Layer> root = Layer::Create(); | |
| 5336 root->SetBounds(gfx::Size(100, 100)); | |
| 5337 | |
| 5338 scoped_refptr<FakePictureLayer> parent = | |
| 5339 CreateDrawablePictureLayer(&delegate); | |
| 5340 SetLayerPropertiesForTesting(parent.get(), | |
| 5341 parent_scale_matrix, | |
| 5342 gfx::Point3F(), | |
| 5343 gfx::PointF(), | |
| 5344 gfx::Size(100, 100), | |
| 5345 false, | |
| 5346 true); | |
| 5347 | |
| 5348 scoped_refptr<FakePictureLayer> child_scale = | |
| 5349 CreateDrawablePictureLayer(&delegate); | |
| 5350 SetLayerPropertiesForTesting(child_scale.get(), | |
| 5351 child_scale_matrix, | |
| 5352 gfx::Point3F(), | |
| 5353 gfx::PointF(2.f, 2.f), | |
| 5354 gfx::Size(10, 10), | |
| 5355 false, | |
| 5356 true); | |
| 5357 | |
| 5358 root->AddChild(parent); | |
| 5359 | |
| 5360 parent->AddChild(child_scale); | |
| 5361 | |
| 5362 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 5363 host->SetRootLayer(root); | |
| 5364 | |
| 5365 { | |
| 5366 RenderSurfaceLayerList render_surface_layer_list; | |
| 5367 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 5368 root.get(), root->bounds(), &render_surface_layer_list); | |
| 5369 inputs.can_adjust_raster_scales = true; | |
| 5370 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 5371 | |
| 5372 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent); | |
| 5373 // Animating layers compute ideal scale in the same way as when | |
| 5374 // they are static. | |
| 5375 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale, | |
| 5376 child_scale); | |
| 5377 } | |
| 5378 } | |
| 5379 | |
| 5380 // TODO(sohanjg): Remove this test when ContentLayer is removed. | |
| 5381 TEST_F(LayerTreeHostCommonTest, | |
| 5382 ChangeInContentBoundsOrScaleTriggersPushProperties) { | |
| 5383 MockContentLayerClient delegate; | |
| 5384 scoped_refptr<Layer> root = Layer::Create(); | |
| 5385 scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate); | |
| 5386 root->AddChild(child); | |
| 5387 | |
| 5388 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 5389 host->SetRootLayer(root); | |
| 5390 | |
| 5391 gfx::Transform identity_matrix; | |
| 5392 SetLayerPropertiesForTesting(root.get(), | |
| 5393 identity_matrix, | |
| 5394 gfx::Point3F(), | |
| 5395 gfx::PointF(), | |
| 5396 gfx::Size(100, 100), | |
| 5397 true, | |
| 5398 false); | |
| 5399 SetLayerPropertiesForTesting(child.get(), | |
| 5400 identity_matrix, | |
| 5401 gfx::Point3F(), | |
| 5402 gfx::PointF(), | |
| 5403 gfx::Size(100, 100), | |
| 5404 true, | |
| 5405 false); | |
| 5406 | |
| 5407 root->reset_needs_push_properties_for_testing(); | |
| 5408 child->reset_needs_push_properties_for_testing(); | |
| 5409 | |
| 5410 // This will change both layers' content bounds. | |
| 5411 ExecuteCalculateDrawProperties(root.get()); | |
| 5412 EXPECT_TRUE(root->needs_push_properties()); | |
| 5413 EXPECT_TRUE(child->needs_push_properties()); | |
| 5414 | |
| 5415 root->reset_needs_push_properties_for_testing(); | |
| 5416 child->reset_needs_push_properties_for_testing(); | |
| 5417 | |
| 5418 // This will change only the child layer's contents scale and content bounds, | |
| 5419 // since the root layer is not a ContentsScalingLayer. | |
| 5420 ExecuteCalculateDrawProperties(root.get(), 2.f); | |
| 5421 EXPECT_FALSE(root->needs_push_properties()); | |
| 5422 EXPECT_TRUE(child->needs_push_properties()); | |
| 5423 | |
| 5424 root->reset_needs_push_properties_for_testing(); | |
| 5425 child->reset_needs_push_properties_for_testing(); | |
| 5426 | |
| 5427 // This will not change either layer's contents scale or content bounds. | |
| 5428 ExecuteCalculateDrawProperties(root.get(), 2.f); | |
| 5429 EXPECT_FALSE(root->needs_push_properties()); | |
| 5430 EXPECT_FALSE(child->needs_push_properties()); | |
| 5431 } | |
| 5432 | |
| 5433 TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { | |
| 5434 MockContentLayerClient delegate; | |
| 5435 gfx::Transform identity_matrix; | |
| 5436 | |
| 5437 scoped_refptr<FakePictureLayer> parent = | |
| 5438 CreateDrawablePictureLayer(&delegate); | |
| 5439 SetLayerPropertiesForTesting(parent.get(), | |
| 5440 identity_matrix, | |
| 5441 gfx::Point3F(), | |
| 5442 gfx::PointF(), | |
| 5443 gfx::Size(30, 30), | |
| 5444 false, | |
| 5445 true); | |
| 5446 | |
| 5447 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); | |
| 5448 SetLayerPropertiesForTesting(child.get(), | |
| 5449 identity_matrix, | |
| 5450 gfx::Point3F(), | |
| 5451 gfx::PointF(2.f, 2.f), | |
| 5452 gfx::Size(10, 10), | |
| 5453 false, | |
| 5454 true); | |
| 5455 | |
| 5456 gfx::Transform replica_transform; | |
| 5457 replica_transform.Scale(1.0, -1.0); | |
| 5458 scoped_refptr<FakePictureLayer> replica = | |
| 5459 CreateDrawablePictureLayer(&delegate); | |
| 5460 SetLayerPropertiesForTesting(replica.get(), | |
| 5461 replica_transform, | |
| 5462 gfx::Point3F(), | |
| 5463 gfx::PointF(2.f, 2.f), | |
| 5464 gfx::Size(10, 10), | |
| 5465 false, | |
| 5466 true); | |
| 5467 | |
| 5468 // This layer should end up in the same surface as child, with the same draw | |
| 5469 // and screen space transforms. | |
| 5470 scoped_refptr<FakePictureLayer> duplicate_child_non_owner = | |
| 5471 CreateDrawablePictureLayer(&delegate); | |
| 5472 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), | |
| 5473 identity_matrix, | |
| 5474 gfx::Point3F(), | |
| 5475 gfx::PointF(), | |
| 5476 gfx::Size(10, 10), | |
| 5477 false, | |
| 5478 true); | |
| 5479 | |
| 5480 parent->AddChild(child); | |
| 5481 child->AddChild(duplicate_child_non_owner); | |
| 5482 child->SetReplicaLayer(replica.get()); | |
| 5483 | |
| 5484 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 5485 host->SetRootLayer(parent); | |
| 5486 | |
| 5487 RenderSurfaceLayerList render_surface_layer_list; | |
| 5488 | |
| 5489 float device_scale_factor = 1.5f; | |
| 5490 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 5491 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 5492 inputs.device_scale_factor = device_scale_factor; | |
| 5493 inputs.can_adjust_raster_scales = true; | |
| 5494 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 5495 | |
| 5496 // We should have two render surfaces. The root's render surface and child's | |
| 5497 // render surface (it needs one because it has a replica layer). | |
| 5498 EXPECT_EQ(2u, render_surface_layer_list.size()); | |
| 5499 | |
| 5500 gfx::Transform expected_parent_transform; | |
| 5501 expected_parent_transform.Scale(device_scale_factor, device_scale_factor); | |
| 5502 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, | |
| 5503 parent->screen_space_transform()); | |
| 5504 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, | |
| 5505 parent->draw_transform()); | |
| 5506 | |
| 5507 gfx::Transform expected_draw_transform; | |
| 5508 expected_draw_transform.Scale(device_scale_factor, device_scale_factor); | |
| 5509 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, | |
| 5510 child->draw_transform()); | |
| 5511 | |
| 5512 gfx::Transform expected_screen_space_transform; | |
| 5513 expected_screen_space_transform.Scale(device_scale_factor, | |
| 5514 device_scale_factor); | |
| 5515 expected_screen_space_transform.Translate(child->position().x(), | |
| 5516 child->position().y()); | |
| 5517 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, | |
| 5518 child->screen_space_transform()); | |
| 5519 | |
| 5520 gfx::Transform expected_duplicate_child_draw_transform = | |
| 5521 child->draw_transform(); | |
| 5522 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(), | |
| 5523 duplicate_child_non_owner->draw_transform()); | |
| 5524 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 5525 child->screen_space_transform(), | |
| 5526 duplicate_child_non_owner->screen_space_transform()); | |
| 5527 EXPECT_EQ(child->drawable_content_rect(), | |
| 5528 duplicate_child_non_owner->drawable_content_rect()); | |
| 5529 EXPECT_EQ(child->content_bounds(), | |
| 5530 duplicate_child_non_owner->content_bounds()); | |
| 5531 | |
| 5532 gfx::Transform expected_render_surface_draw_transform; | |
| 5533 expected_render_surface_draw_transform.Translate( | |
| 5534 device_scale_factor * child->position().x(), | |
| 5535 device_scale_factor * child->position().y()); | |
| 5536 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, | |
| 5537 child->render_surface()->draw_transform()); | |
| 5538 | |
| 5539 gfx::Transform expected_surface_draw_transform; | |
| 5540 expected_surface_draw_transform.Translate(device_scale_factor * 2.f, | |
| 5541 device_scale_factor * 2.f); | |
| 5542 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, | |
| 5543 child->render_surface()->draw_transform()); | |
| 5544 | |
| 5545 gfx::Transform expected_surface_screen_space_transform; | |
| 5546 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, | |
| 5547 device_scale_factor * 2.f); | |
| 5548 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 5549 expected_surface_screen_space_transform, | |
| 5550 child->render_surface()->screen_space_transform()); | |
| 5551 | |
| 5552 gfx::Transform expected_replica_draw_transform; | |
| 5553 expected_replica_draw_transform.matrix().set(1, 1, -1.0); | |
| 5554 expected_replica_draw_transform.matrix().set(0, 3, 6.0); | |
| 5555 expected_replica_draw_transform.matrix().set(1, 3, 6.0); | |
| 5556 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 5557 expected_replica_draw_transform, | |
| 5558 child->render_surface()->replica_draw_transform()); | |
| 5559 | |
| 5560 gfx::Transform expected_replica_screen_space_transform; | |
| 5561 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); | |
| 5562 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); | |
| 5563 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); | |
| 5564 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 5565 expected_replica_screen_space_transform, | |
| 5566 child->render_surface()->replica_screen_space_transform()); | |
| 5567 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 5568 expected_replica_screen_space_transform, | |
| 5569 child->render_surface()->replica_screen_space_transform()); | |
| 5570 } | |
| 5571 | |
| 5572 TEST_F(LayerTreeHostCommonTest, | |
| 5573 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { | |
| 5574 MockContentLayerClient delegate; | |
| 5575 gfx::Transform identity_matrix; | |
| 5576 | |
| 5577 scoped_refptr<FakePictureLayer> parent = | |
| 5578 CreateDrawablePictureLayer(&delegate); | |
| 5579 SetLayerPropertiesForTesting(parent.get(), | |
| 5580 identity_matrix, | |
| 5581 gfx::Point3F(), | |
| 5582 gfx::PointF(), | |
| 5583 gfx::Size(33, 31), | |
| 5584 false, | |
| 5585 true); | |
| 5586 | |
| 5587 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); | |
| 5588 SetLayerPropertiesForTesting(child.get(), | |
| 5589 identity_matrix, | |
| 5590 gfx::Point3F(), | |
| 5591 gfx::PointF(), | |
| 5592 gfx::Size(13, 11), | |
| 5593 false, | |
| 5594 true); | |
| 5595 | |
| 5596 gfx::Transform replica_transform; | |
| 5597 replica_transform.Scale(1.0, -1.0); | |
| 5598 scoped_refptr<FakePictureLayer> replica = | |
| 5599 CreateDrawablePictureLayer(&delegate); | |
| 5600 SetLayerPropertiesForTesting(replica.get(), | |
| 5601 replica_transform, | |
| 5602 gfx::Point3F(), | |
| 5603 gfx::PointF(), | |
| 5604 gfx::Size(13, 11), | |
| 5605 false, | |
| 5606 true); | |
| 5607 | |
| 5608 parent->AddChild(child); | |
| 5609 child->SetReplicaLayer(replica.get()); | |
| 5610 | |
| 5611 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 5612 host->SetRootLayer(parent); | |
| 5613 | |
| 5614 float device_scale_factor = 1.7f; | |
| 5615 | |
| 5616 RenderSurfaceLayerList render_surface_layer_list; | |
| 5617 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 5618 parent.get(), parent->bounds(), &render_surface_layer_list); | |
| 5619 inputs.device_scale_factor = device_scale_factor; | |
| 5620 inputs.can_adjust_raster_scales = true; | |
| 5621 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 5622 | |
| 5623 // We should have two render surfaces. The root's render surface and child's | |
| 5624 // render surface (it needs one because it has a replica layer). | |
| 5625 EXPECT_EQ(2u, render_surface_layer_list.size()); | |
| 5626 | |
| 5627 gfx::Transform identity_transform; | |
| 5628 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, | |
| 5629 child->render_surface()->draw_transform()); | |
| 5630 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, | |
| 5631 child->render_surface()->draw_transform()); | |
| 5632 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 5633 identity_transform, child->render_surface()->screen_space_transform()); | |
| 5634 | |
| 5635 gfx::Transform expected_replica_draw_transform; | |
| 5636 expected_replica_draw_transform.matrix().set(1, 1, -1.0); | |
| 5637 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 5638 expected_replica_draw_transform, | |
| 5639 child->render_surface()->replica_draw_transform()); | |
| 5640 | |
| 5641 gfx::Transform expected_replica_screen_space_transform; | |
| 5642 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); | |
| 5643 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 5644 expected_replica_screen_space_transform, | |
| 5645 child->render_surface()->replica_screen_space_transform()); | |
| 5646 } | |
| 5647 | |
| 5648 TEST_F(LayerTreeHostCommonTest, SubtreeSearch) { | |
| 5649 scoped_refptr<Layer> root = Layer::Create(); | |
| 5650 scoped_refptr<Layer> child = Layer::Create(); | |
| 5651 scoped_refptr<Layer> grand_child = Layer::Create(); | |
| 5652 scoped_refptr<Layer> mask_layer = Layer::Create(); | |
| 5653 scoped_refptr<Layer> replica_layer = Layer::Create(); | |
| 5654 | |
| 5655 grand_child->SetReplicaLayer(replica_layer.get()); | |
| 5656 child->AddChild(grand_child.get()); | |
| 5657 child->SetMaskLayer(mask_layer.get()); | |
| 5658 root->AddChild(child.get()); | |
| 5659 | |
| 5660 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 5661 host->SetRootLayer(root); | |
| 5662 | |
| 5663 int nonexistent_id = -1; | |
| 5664 EXPECT_EQ(root.get(), | |
| 5665 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id())); | |
| 5666 EXPECT_EQ(child.get(), | |
| 5667 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id())); | |
| 5668 EXPECT_EQ( | |
| 5669 grand_child.get(), | |
| 5670 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id())); | |
| 5671 EXPECT_EQ( | |
| 5672 mask_layer.get(), | |
| 5673 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id())); | |
| 5674 EXPECT_EQ( | |
| 5675 replica_layer.get(), | |
| 5676 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id())); | |
| 5677 EXPECT_EQ( | |
| 5678 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id)); | |
| 5679 } | |
| 5680 | |
| 5681 TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { | |
| 5682 scoped_refptr<Layer> root = Layer::Create(); | |
| 5683 scoped_refptr<Layer> child = Layer::Create(); | |
| 5684 scoped_refptr<LayerWithForcedDrawsContent> grand_child = | |
| 5685 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 5686 | |
| 5687 const gfx::Transform identity_matrix; | |
| 5688 SetLayerPropertiesForTesting(root.get(), | |
| 5689 identity_matrix, | |
| 5690 gfx::Point3F(), | |
| 5691 gfx::PointF(), | |
| 5692 gfx::Size(100, 100), | |
| 5693 true, | |
| 5694 false); | |
| 5695 SetLayerPropertiesForTesting(child.get(), | |
| 5696 identity_matrix, | |
| 5697 gfx::Point3F(), | |
| 5698 gfx::PointF(), | |
| 5699 gfx::Size(10, 10), | |
| 5700 true, | |
| 5701 false); | |
| 5702 SetLayerPropertiesForTesting(grand_child.get(), | |
| 5703 identity_matrix, | |
| 5704 gfx::Point3F(), | |
| 5705 gfx::PointF(), | |
| 5706 gfx::Size(10, 10), | |
| 5707 true, | |
| 5708 false); | |
| 5709 | |
| 5710 root->AddChild(child); | |
| 5711 child->AddChild(grand_child); | |
| 5712 child->SetOpacity(0.5f); | |
| 5713 | |
| 5714 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 5715 host->SetRootLayer(root); | |
| 5716 | |
| 5717 ExecuteCalculateDrawProperties(root.get()); | |
| 5718 | |
| 5719 EXPECT_FALSE(child->render_surface()); | |
| 5720 } | |
| 5721 | |
| 5722 TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { | |
| 5723 FakeImplProxy proxy; | |
| 5724 TestSharedBitmapManager shared_bitmap_manager; | |
| 5725 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 5726 host_impl.CreatePendingTree(); | |
| 5727 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); | |
| 5728 | |
| 5729 const gfx::Transform identity_matrix; | |
| 5730 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), | |
| 5731 gfx::PointF(), gfx::Size(100, 100), true, false, | |
| 5732 false); | |
| 5733 root->SetDrawsContent(true); | |
| 5734 | |
| 5735 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); | |
| 5736 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), | |
| 5737 gfx::PointF(), gfx::Size(50, 50), true, false, | |
| 5738 false); | |
| 5739 child->SetDrawsContent(true); | |
| 5740 child->SetOpacity(0.0f); | |
| 5741 | |
| 5742 // Add opacity animation. | |
| 5743 AddOpacityTransitionToController( | |
| 5744 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false); | |
| 5745 | |
| 5746 root->AddChild(child.Pass()); | |
| 5747 root->SetHasRenderSurface(true); | |
| 5748 | |
| 5749 LayerImplList render_surface_layer_list; | |
| 5750 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 5751 root.get(), root->bounds(), &render_surface_layer_list); | |
| 5752 inputs.can_adjust_raster_scales = true; | |
| 5753 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 5754 | |
| 5755 // We should have one render surface and two layers. The child | |
| 5756 // layer should be included even though it is transparent. | |
| 5757 ASSERT_EQ(1u, render_surface_layer_list.size()); | |
| 5758 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); | |
| 5759 } | |
| 5760 | |
| 5761 using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; | |
| 5762 class LCDTextTest | |
| 5763 : public LayerTreeHostCommonTestBase, | |
| 5764 public testing::TestWithParam<LCDTextTestParam> { | |
| 5765 public: | |
| 5766 LCDTextTest() | |
| 5767 : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_), | |
| 5768 root_(nullptr), | |
| 5769 child_(nullptr), | |
| 5770 grand_child_(nullptr) {} | |
| 5771 | |
| 5772 protected: | |
| 5773 void SetUp() override { | |
| 5774 can_use_lcd_text_ = std::tr1::get<0>(GetParam()); | |
| 5775 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); | |
| 5776 | |
| 5777 scoped_ptr<LayerImpl> root_ptr = | |
| 5778 LayerImpl::Create(host_impl_.active_tree(), 1); | |
| 5779 scoped_ptr<LayerImpl> child_ptr = | |
| 5780 LayerImpl::Create(host_impl_.active_tree(), 2); | |
| 5781 scoped_ptr<LayerImpl> grand_child_ptr = | |
| 5782 LayerImpl::Create(host_impl_.active_tree(), 3); | |
| 5783 | |
| 5784 // Stash raw pointers to look at later. | |
| 5785 root_ = root_ptr.get(); | |
| 5786 child_ = child_ptr.get(); | |
| 5787 grand_child_ = grand_child_ptr.get(); | |
| 5788 | |
| 5789 child_->AddChild(grand_child_ptr.Pass()); | |
| 5790 root_->AddChild(child_ptr.Pass()); | |
| 5791 host_impl_.active_tree()->SetRootLayer(root_ptr.Pass()); | |
| 5792 | |
| 5793 root_->SetContentsOpaque(true); | |
| 5794 child_->SetContentsOpaque(true); | |
| 5795 grand_child_->SetContentsOpaque(true); | |
| 5796 | |
| 5797 gfx::Transform identity_matrix; | |
| 5798 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(), | |
| 5799 gfx::PointF(), gfx::Size(1, 1), true, false, | |
| 5800 true); | |
| 5801 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(), | |
| 5802 gfx::PointF(), gfx::Size(1, 1), true, false, | |
| 5803 std::tr1::get<2>(GetParam())); | |
| 5804 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(), | |
| 5805 gfx::PointF(), gfx::Size(1, 1), true, false, | |
| 5806 false); | |
| 5807 } | |
| 5808 | |
| 5809 bool can_use_lcd_text_; | |
| 5810 bool layers_always_allowed_lcd_text_; | |
| 5811 | |
| 5812 FakeImplProxy proxy_; | |
| 5813 TestSharedBitmapManager shared_bitmap_manager_; | |
| 5814 TestTaskGraphRunner task_graph_runner_; | |
| 5815 FakeLayerTreeHostImpl host_impl_; | |
| 5816 | |
| 5817 LayerImpl* root_; | |
| 5818 LayerImpl* child_; | |
| 5819 LayerImpl* grand_child_; | |
| 5820 }; | |
| 5821 | |
| 5822 TEST_P(LCDTextTest, CanUseLCDText) { | |
| 5823 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; | |
| 5824 bool expect_not_lcd_text = layers_always_allowed_lcd_text_; | |
| 5825 | |
| 5826 // Case 1: Identity transform. | |
| 5827 gfx::Transform identity_matrix; | |
| 5828 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, | |
| 5829 layers_always_allowed_lcd_text_); | |
| 5830 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | |
| 5831 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); | |
| 5832 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); | |
| 5833 | |
| 5834 // Case 2: Integral translation. | |
| 5835 gfx::Transform integral_translation; | |
| 5836 integral_translation.Translate(1.0, 2.0); | |
| 5837 child_->SetTransform(integral_translation); | |
| 5838 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, | |
| 5839 layers_always_allowed_lcd_text_); | |
| 5840 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | |
| 5841 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); | |
| 5842 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); | |
| 5843 | |
| 5844 // Case 3: Non-integral translation. | |
| 5845 gfx::Transform non_integral_translation; | |
| 5846 non_integral_translation.Translate(1.5, 2.5); | |
| 5847 child_->SetTransform(non_integral_translation); | |
| 5848 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, | |
| 5849 layers_always_allowed_lcd_text_); | |
| 5850 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | |
| 5851 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); | |
| 5852 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); | |
| 5853 | |
| 5854 // Case 4: Rotation. | |
| 5855 gfx::Transform rotation; | |
| 5856 rotation.Rotate(10.0); | |
| 5857 child_->SetTransform(rotation); | |
| 5858 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, | |
| 5859 layers_always_allowed_lcd_text_); | |
| 5860 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | |
| 5861 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); | |
| 5862 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); | |
| 5863 | |
| 5864 // Case 5: Scale. | |
| 5865 gfx::Transform scale; | |
| 5866 scale.Scale(2.0, 2.0); | |
| 5867 child_->SetTransform(scale); | |
| 5868 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, | |
| 5869 layers_always_allowed_lcd_text_); | |
| 5870 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | |
| 5871 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); | |
| 5872 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); | |
| 5873 | |
| 5874 // Case 6: Skew. | |
| 5875 gfx::Transform skew; | |
| 5876 skew.SkewX(10.0); | |
| 5877 child_->SetTransform(skew); | |
| 5878 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, | |
| 5879 layers_always_allowed_lcd_text_); | |
| 5880 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | |
| 5881 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); | |
| 5882 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); | |
| 5883 | |
| 5884 // Case 7: Translucent. | |
| 5885 child_->SetTransform(identity_matrix); | |
| 5886 child_->SetOpacity(0.5f); | |
| 5887 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, | |
| 5888 layers_always_allowed_lcd_text_); | |
| 5889 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | |
| 5890 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); | |
| 5891 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); | |
| 5892 | |
| 5893 // Case 8: Sanity check: restore transform and opacity. | |
| 5894 child_->SetTransform(identity_matrix); | |
| 5895 child_->SetOpacity(1.f); | |
| 5896 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, | |
| 5897 layers_always_allowed_lcd_text_); | |
| 5898 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | |
| 5899 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); | |
| 5900 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); | |
| 5901 | |
| 5902 // Case 9: Non-opaque content. | |
| 5903 child_->SetContentsOpaque(false); | |
| 5904 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, | |
| 5905 layers_always_allowed_lcd_text_); | |
| 5906 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | |
| 5907 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); | |
| 5908 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); | |
| 5909 | |
| 5910 // Case 10: Sanity check: restore content opaqueness. | |
| 5911 child_->SetContentsOpaque(true); | |
| 5912 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, | |
| 5913 layers_always_allowed_lcd_text_); | |
| 5914 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | |
| 5915 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); | |
| 5916 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); | |
| 5917 } | |
| 5918 | |
| 5919 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { | |
| 5920 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; | |
| 5921 | |
| 5922 // Sanity check: Make sure can_use_lcd_text_ is set on each node. | |
| 5923 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, | |
| 5924 layers_always_allowed_lcd_text_); | |
| 5925 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | |
| 5926 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); | |
| 5927 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); | |
| 5928 | |
| 5929 // Add opacity animation. | |
| 5930 child_->SetOpacity(0.9f); | |
| 5931 AddOpacityTransitionToController( | |
| 5932 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); | |
| 5933 | |
| 5934 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, | |
| 5935 layers_always_allowed_lcd_text_); | |
| 5936 // Text AA should not be adjusted while animation is active. | |
| 5937 // Make sure LCD text AA setting remains unchanged. | |
| 5938 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | |
| 5939 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); | |
| 5940 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); | |
| 5941 } | |
| 5942 | |
| 5943 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, | |
| 5944 LCDTextTest, | |
| 5945 testing::Combine(testing::Bool(), | |
| 5946 testing::Bool(), | |
| 5947 testing::Bool())); | |
| 5948 | |
| 5949 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) { | |
| 5950 FakeImplProxy proxy; | |
| 5951 TestSharedBitmapManager shared_bitmap_manager; | |
| 5952 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 5953 host_impl.CreatePendingTree(); | |
| 5954 const gfx::Transform identity_matrix; | |
| 5955 | |
| 5956 scoped_refptr<Layer> root = Layer::Create(); | |
| 5957 SetLayerPropertiesForTesting(root.get(), | |
| 5958 identity_matrix, | |
| 5959 gfx::Point3F(), | |
| 5960 gfx::PointF(), | |
| 5961 gfx::Size(50, 50), | |
| 5962 true, | |
| 5963 false); | |
| 5964 root->SetIsDrawable(true); | |
| 5965 | |
| 5966 scoped_refptr<Layer> child = Layer::Create(); | |
| 5967 SetLayerPropertiesForTesting(child.get(), | |
| 5968 identity_matrix, | |
| 5969 gfx::Point3F(), | |
| 5970 gfx::PointF(), | |
| 5971 gfx::Size(40, 40), | |
| 5972 true, | |
| 5973 false); | |
| 5974 child->SetIsDrawable(true); | |
| 5975 | |
| 5976 scoped_refptr<Layer> grand_child = Layer::Create(); | |
| 5977 SetLayerPropertiesForTesting(grand_child.get(), | |
| 5978 identity_matrix, | |
| 5979 gfx::Point3F(), | |
| 5980 gfx::PointF(), | |
| 5981 gfx::Size(30, 30), | |
| 5982 true, | |
| 5983 false); | |
| 5984 grand_child->SetIsDrawable(true); | |
| 5985 grand_child->SetHideLayerAndSubtree(true); | |
| 5986 | |
| 5987 child->AddChild(grand_child); | |
| 5988 root->AddChild(child); | |
| 5989 | |
| 5990 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 5991 host->SetRootLayer(root); | |
| 5992 | |
| 5993 RenderSurfaceLayerList render_surface_layer_list; | |
| 5994 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 5995 root.get(), root->bounds(), &render_surface_layer_list); | |
| 5996 inputs.can_adjust_raster_scales = true; | |
| 5997 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 5998 | |
| 5999 // We should have one render surface and two layers. The grand child has | |
| 6000 // hidden itself. | |
| 6001 ASSERT_EQ(1u, render_surface_layer_list.size()); | |
| 6002 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); | |
| 6003 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); | |
| 6004 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id()); | |
| 6005 } | |
| 6006 | |
| 6007 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { | |
| 6008 FakeImplProxy proxy; | |
| 6009 TestSharedBitmapManager shared_bitmap_manager; | |
| 6010 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 6011 host_impl.CreatePendingTree(); | |
| 6012 const gfx::Transform identity_matrix; | |
| 6013 | |
| 6014 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); | |
| 6015 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), | |
| 6016 gfx::PointF(), gfx::Size(50, 50), true, false, | |
| 6017 false); | |
| 6018 root->SetDrawsContent(true); | |
| 6019 | |
| 6020 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); | |
| 6021 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), | |
| 6022 gfx::PointF(), gfx::Size(40, 40), true, false, | |
| 6023 false); | |
| 6024 child->SetDrawsContent(true); | |
| 6025 | |
| 6026 scoped_ptr<LayerImpl> grand_child = | |
| 6027 LayerImpl::Create(host_impl.pending_tree(), 3); | |
| 6028 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, | |
| 6029 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), | |
| 6030 true, false, false); | |
| 6031 grand_child->SetDrawsContent(true); | |
| 6032 grand_child->SetHideLayerAndSubtree(true); | |
| 6033 | |
| 6034 child->AddChild(grand_child.Pass()); | |
| 6035 root->AddChild(child.Pass()); | |
| 6036 root->SetHasRenderSurface(true); | |
| 6037 | |
| 6038 LayerImplList render_surface_layer_list; | |
| 6039 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 6040 root.get(), root->bounds(), &render_surface_layer_list); | |
| 6041 inputs.can_adjust_raster_scales = true; | |
| 6042 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 6043 | |
| 6044 // We should have one render surface and two layers. The grand child has | |
| 6045 // hidden itself. | |
| 6046 ASSERT_EQ(1u, render_surface_layer_list.size()); | |
| 6047 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); | |
| 6048 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); | |
| 6049 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id()); | |
| 6050 } | |
| 6051 | |
| 6052 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) { | |
| 6053 FakeImplProxy proxy; | |
| 6054 TestSharedBitmapManager shared_bitmap_manager; | |
| 6055 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 6056 host_impl.CreatePendingTree(); | |
| 6057 const gfx::Transform identity_matrix; | |
| 6058 | |
| 6059 scoped_refptr<Layer> root = Layer::Create(); | |
| 6060 SetLayerPropertiesForTesting(root.get(), | |
| 6061 identity_matrix, | |
| 6062 gfx::Point3F(), | |
| 6063 gfx::PointF(), | |
| 6064 gfx::Size(50, 50), | |
| 6065 true, | |
| 6066 false); | |
| 6067 root->SetIsDrawable(true); | |
| 6068 | |
| 6069 scoped_refptr<Layer> child = Layer::Create(); | |
| 6070 SetLayerPropertiesForTesting(child.get(), | |
| 6071 identity_matrix, | |
| 6072 gfx::Point3F(), | |
| 6073 gfx::PointF(), | |
| 6074 gfx::Size(40, 40), | |
| 6075 true, | |
| 6076 false); | |
| 6077 child->SetIsDrawable(true); | |
| 6078 child->SetHideLayerAndSubtree(true); | |
| 6079 | |
| 6080 scoped_refptr<Layer> grand_child = Layer::Create(); | |
| 6081 SetLayerPropertiesForTesting(grand_child.get(), | |
| 6082 identity_matrix, | |
| 6083 gfx::Point3F(), | |
| 6084 gfx::PointF(), | |
| 6085 gfx::Size(30, 30), | |
| 6086 true, | |
| 6087 false); | |
| 6088 grand_child->SetIsDrawable(true); | |
| 6089 | |
| 6090 child->AddChild(grand_child); | |
| 6091 root->AddChild(child); | |
| 6092 | |
| 6093 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 6094 host->SetRootLayer(root); | |
| 6095 | |
| 6096 RenderSurfaceLayerList render_surface_layer_list; | |
| 6097 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 6098 root.get(), root->bounds(), &render_surface_layer_list); | |
| 6099 inputs.can_adjust_raster_scales = true; | |
| 6100 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 6101 | |
| 6102 // We should have one render surface and one layers. The child has | |
| 6103 // hidden itself and the grand child. | |
| 6104 ASSERT_EQ(1u, render_surface_layer_list.size()); | |
| 6105 ASSERT_EQ(1u, root->render_surface()->layer_list().size()); | |
| 6106 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); | |
| 6107 } | |
| 6108 | |
| 6109 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { | |
| 6110 FakeImplProxy proxy; | |
| 6111 TestSharedBitmapManager shared_bitmap_manager; | |
| 6112 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 6113 host_impl.CreatePendingTree(); | |
| 6114 const gfx::Transform identity_matrix; | |
| 6115 | |
| 6116 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); | |
| 6117 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), | |
| 6118 gfx::PointF(), gfx::Size(50, 50), true, false, | |
| 6119 true); | |
| 6120 root->SetDrawsContent(true); | |
| 6121 | |
| 6122 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); | |
| 6123 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), | |
| 6124 gfx::PointF(), gfx::Size(40, 40), true, false, | |
| 6125 false); | |
| 6126 child->SetDrawsContent(true); | |
| 6127 child->SetHideLayerAndSubtree(true); | |
| 6128 | |
| 6129 scoped_ptr<LayerImpl> grand_child = | |
| 6130 LayerImpl::Create(host_impl.pending_tree(), 3); | |
| 6131 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, | |
| 6132 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), | |
| 6133 true, false, false); | |
| 6134 grand_child->SetDrawsContent(true); | |
| 6135 | |
| 6136 child->AddChild(grand_child.Pass()); | |
| 6137 root->AddChild(child.Pass()); | |
| 6138 | |
| 6139 LayerImplList render_surface_layer_list; | |
| 6140 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 6141 root.get(), root->bounds(), &render_surface_layer_list); | |
| 6142 inputs.can_adjust_raster_scales = true; | |
| 6143 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 6144 | |
| 6145 // We should have one render surface and one layers. The child has | |
| 6146 // hidden itself and the grand child. | |
| 6147 ASSERT_EQ(1u, render_surface_layer_list.size()); | |
| 6148 ASSERT_EQ(1u, root->render_surface()->layer_list().size()); | |
| 6149 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); | |
| 6150 } | |
| 6151 | |
| 6152 void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} | |
| 6153 | |
| 6154 TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { | |
| 6155 FakeImplProxy proxy; | |
| 6156 TestSharedBitmapManager shared_bitmap_manager; | |
| 6157 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 6158 host_impl.CreatePendingTree(); | |
| 6159 const gfx::Transform identity_matrix; | |
| 6160 | |
| 6161 scoped_refptr<Layer> root = Layer::Create(); | |
| 6162 SetLayerPropertiesForTesting(root.get(), | |
| 6163 identity_matrix, | |
| 6164 gfx::Point3F(), | |
| 6165 gfx::PointF(), | |
| 6166 gfx::Size(50, 50), | |
| 6167 true, | |
| 6168 false); | |
| 6169 root->SetIsDrawable(true); | |
| 6170 | |
| 6171 scoped_refptr<Layer> copy_grand_parent = Layer::Create(); | |
| 6172 SetLayerPropertiesForTesting(copy_grand_parent.get(), | |
| 6173 identity_matrix, | |
| 6174 gfx::Point3F(), | |
| 6175 gfx::PointF(), | |
| 6176 gfx::Size(40, 40), | |
| 6177 true, | |
| 6178 false); | |
| 6179 copy_grand_parent->SetIsDrawable(true); | |
| 6180 | |
| 6181 scoped_refptr<Layer> copy_parent = Layer::Create(); | |
| 6182 SetLayerPropertiesForTesting(copy_parent.get(), | |
| 6183 identity_matrix, | |
| 6184 gfx::Point3F(), | |
| 6185 gfx::PointF(), | |
| 6186 gfx::Size(30, 30), | |
| 6187 true, | |
| 6188 false); | |
| 6189 copy_parent->SetIsDrawable(true); | |
| 6190 copy_parent->SetForceRenderSurface(true); | |
| 6191 | |
| 6192 scoped_refptr<Layer> copy_layer = Layer::Create(); | |
| 6193 SetLayerPropertiesForTesting(copy_layer.get(), | |
| 6194 identity_matrix, | |
| 6195 gfx::Point3F(), | |
| 6196 gfx::PointF(), | |
| 6197 gfx::Size(20, 20), | |
| 6198 true, | |
| 6199 false); | |
| 6200 copy_layer->SetIsDrawable(true); | |
| 6201 | |
| 6202 scoped_refptr<Layer> copy_child = Layer::Create(); | |
| 6203 SetLayerPropertiesForTesting(copy_child.get(), | |
| 6204 identity_matrix, | |
| 6205 gfx::Point3F(), | |
| 6206 gfx::PointF(), | |
| 6207 gfx::Size(20, 20), | |
| 6208 true, | |
| 6209 false); | |
| 6210 copy_child->SetIsDrawable(true); | |
| 6211 | |
| 6212 scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create(); | |
| 6213 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), | |
| 6214 identity_matrix, | |
| 6215 gfx::Point3F(), | |
| 6216 gfx::PointF(), | |
| 6217 gfx::Size(40, 40), | |
| 6218 true, | |
| 6219 false); | |
| 6220 copy_grand_parent_sibling_before->SetIsDrawable(true); | |
| 6221 | |
| 6222 scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create(); | |
| 6223 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), | |
| 6224 identity_matrix, | |
| 6225 gfx::Point3F(), | |
| 6226 gfx::PointF(), | |
| 6227 gfx::Size(40, 40), | |
| 6228 true, | |
| 6229 false); | |
| 6230 copy_grand_parent_sibling_after->SetIsDrawable(true); | |
| 6231 | |
| 6232 copy_layer->AddChild(copy_child); | |
| 6233 copy_parent->AddChild(copy_layer); | |
| 6234 copy_grand_parent->AddChild(copy_parent); | |
| 6235 root->AddChild(copy_grand_parent_sibling_before); | |
| 6236 root->AddChild(copy_grand_parent); | |
| 6237 root->AddChild(copy_grand_parent_sibling_after); | |
| 6238 | |
| 6239 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 6240 host->SetRootLayer(root); | |
| 6241 | |
| 6242 // Hide the copy_grand_parent and its subtree. But make a copy request in that | |
| 6243 // hidden subtree on copy_layer. | |
| 6244 copy_grand_parent->SetHideLayerAndSubtree(true); | |
| 6245 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true); | |
| 6246 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true); | |
| 6247 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( | |
| 6248 base::Bind(&EmptyCopyOutputCallback))); | |
| 6249 EXPECT_TRUE(copy_layer->HasCopyRequest()); | |
| 6250 | |
| 6251 RenderSurfaceLayerList render_surface_layer_list; | |
| 6252 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 6253 root.get(), root->bounds(), &render_surface_layer_list); | |
| 6254 inputs.can_adjust_raster_scales = true; | |
| 6255 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 6256 | |
| 6257 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request); | |
| 6258 EXPECT_TRUE(copy_grand_parent->draw_properties(). | |
| 6259 layer_or_descendant_has_copy_request); | |
| 6260 EXPECT_TRUE(copy_parent->draw_properties(). | |
| 6261 layer_or_descendant_has_copy_request); | |
| 6262 EXPECT_TRUE(copy_layer->draw_properties(). | |
| 6263 layer_or_descendant_has_copy_request); | |
| 6264 EXPECT_FALSE(copy_child->draw_properties(). | |
| 6265 layer_or_descendant_has_copy_request); | |
| 6266 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties(). | |
| 6267 layer_or_descendant_has_copy_request); | |
| 6268 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties(). | |
| 6269 layer_or_descendant_has_copy_request); | |
| 6270 | |
| 6271 // We should have three render surfaces, one for the root, one for the parent | |
| 6272 // since it owns a surface, and one for the copy_layer. | |
| 6273 ASSERT_EQ(3u, render_surface_layer_list.size()); | |
| 6274 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); | |
| 6275 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id()); | |
| 6276 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id()); | |
| 6277 | |
| 6278 // The root render surface should have 2 contributing layers. The | |
| 6279 // copy_grand_parent is hidden along with its siblings, but the copy_parent | |
| 6280 // will appear since something in its subtree needs to be drawn for a copy | |
| 6281 // request. | |
| 6282 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); | |
| 6283 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); | |
| 6284 EXPECT_EQ(copy_parent->id(), | |
| 6285 root->render_surface()->layer_list().at(1)->id()); | |
| 6286 | |
| 6287 // Nothing actually draws into the copy parent, so only the copy_layer will | |
| 6288 // appear in its list, since it needs to be drawn for the copy request. | |
| 6289 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size()); | |
| 6290 EXPECT_EQ(copy_layer->id(), | |
| 6291 copy_parent->render_surface()->layer_list().at(0)->id()); | |
| 6292 | |
| 6293 // The copy_layer's render surface should have two contributing layers. | |
| 6294 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); | |
| 6295 EXPECT_EQ(copy_layer->id(), | |
| 6296 copy_layer->render_surface()->layer_list().at(0)->id()); | |
| 6297 EXPECT_EQ(copy_child->id(), | |
| 6298 copy_layer->render_surface()->layer_list().at(1)->id()); | |
| 6299 } | |
| 6300 | |
| 6301 TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { | |
| 6302 FakeImplProxy proxy; | |
| 6303 TestSharedBitmapManager shared_bitmap_manager; | |
| 6304 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 6305 host_impl.CreatePendingTree(); | |
| 6306 const gfx::Transform identity_matrix; | |
| 6307 | |
| 6308 scoped_refptr<Layer> root = Layer::Create(); | |
| 6309 SetLayerPropertiesForTesting(root.get(), | |
| 6310 identity_matrix, | |
| 6311 gfx::Point3F(), | |
| 6312 gfx::PointF(), | |
| 6313 gfx::Size(50, 50), | |
| 6314 true, | |
| 6315 false); | |
| 6316 root->SetIsDrawable(true); | |
| 6317 | |
| 6318 scoped_refptr<Layer> copy_parent = Layer::Create(); | |
| 6319 SetLayerPropertiesForTesting(copy_parent.get(), | |
| 6320 identity_matrix, | |
| 6321 gfx::Point3F(), | |
| 6322 gfx::PointF(), | |
| 6323 gfx::Size(), | |
| 6324 true, | |
| 6325 false); | |
| 6326 copy_parent->SetIsDrawable(true); | |
| 6327 copy_parent->SetMasksToBounds(true); | |
| 6328 | |
| 6329 scoped_refptr<Layer> copy_layer = Layer::Create(); | |
| 6330 SetLayerPropertiesForTesting(copy_layer.get(), | |
| 6331 identity_matrix, | |
| 6332 gfx::Point3F(), | |
| 6333 gfx::PointF(), | |
| 6334 gfx::Size(30, 30), | |
| 6335 true, | |
| 6336 false); | |
| 6337 copy_layer->SetIsDrawable(true); | |
| 6338 | |
| 6339 scoped_refptr<Layer> copy_child = Layer::Create(); | |
| 6340 SetLayerPropertiesForTesting(copy_child.get(), | |
| 6341 identity_matrix, | |
| 6342 gfx::Point3F(), | |
| 6343 gfx::PointF(), | |
| 6344 gfx::Size(20, 20), | |
| 6345 true, | |
| 6346 false); | |
| 6347 copy_child->SetIsDrawable(true); | |
| 6348 | |
| 6349 copy_layer->AddChild(copy_child); | |
| 6350 copy_parent->AddChild(copy_layer); | |
| 6351 root->AddChild(copy_parent); | |
| 6352 | |
| 6353 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 6354 host->SetRootLayer(root); | |
| 6355 | |
| 6356 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( | |
| 6357 base::Bind(&EmptyCopyOutputCallback))); | |
| 6358 EXPECT_TRUE(copy_layer->HasCopyRequest()); | |
| 6359 | |
| 6360 RenderSurfaceLayerList render_surface_layer_list; | |
| 6361 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 6362 root.get(), root->bounds(), &render_surface_layer_list); | |
| 6363 inputs.can_adjust_raster_scales = true; | |
| 6364 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 6365 | |
| 6366 // We should have one render surface, as the others are clipped out. | |
| 6367 ASSERT_EQ(1u, render_surface_layer_list.size()); | |
| 6368 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); | |
| 6369 | |
| 6370 // The root render surface should only have 1 contributing layer, since the | |
| 6371 // other layers are empty/clipped away. | |
| 6372 ASSERT_EQ(1u, root->render_surface()->layer_list().size()); | |
| 6373 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); | |
| 6374 } | |
| 6375 | |
| 6376 TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { | |
| 6377 FakeImplProxy proxy; | |
| 6378 TestSharedBitmapManager shared_bitmap_manager; | |
| 6379 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 6380 host_impl.CreatePendingTree(); | |
| 6381 const gfx::Transform identity_matrix; | |
| 6382 | |
| 6383 scoped_refptr<Layer> root = Layer::Create(); | |
| 6384 SetLayerPropertiesForTesting(root.get(), | |
| 6385 identity_matrix, | |
| 6386 gfx::Point3F(), | |
| 6387 gfx::PointF(), | |
| 6388 gfx::Size(50, 50), | |
| 6389 true, | |
| 6390 false); | |
| 6391 root->SetIsDrawable(true); | |
| 6392 | |
| 6393 // The surface is moved slightly outside of the viewport. | |
| 6394 scoped_refptr<Layer> surface = Layer::Create(); | |
| 6395 SetLayerPropertiesForTesting(surface.get(), | |
| 6396 identity_matrix, | |
| 6397 gfx::Point3F(), | |
| 6398 gfx::PointF(-10, -20), | |
| 6399 gfx::Size(), | |
| 6400 true, | |
| 6401 false); | |
| 6402 surface->SetForceRenderSurface(true); | |
| 6403 | |
| 6404 scoped_refptr<Layer> surface_child = Layer::Create(); | |
| 6405 SetLayerPropertiesForTesting(surface_child.get(), | |
| 6406 identity_matrix, | |
| 6407 gfx::Point3F(), | |
| 6408 gfx::PointF(), | |
| 6409 gfx::Size(50, 50), | |
| 6410 true, | |
| 6411 false); | |
| 6412 surface_child->SetIsDrawable(true); | |
| 6413 | |
| 6414 surface->AddChild(surface_child); | |
| 6415 root->AddChild(surface); | |
| 6416 | |
| 6417 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 6418 host->SetRootLayer(root); | |
| 6419 | |
| 6420 RenderSurfaceLayerList render_surface_layer_list; | |
| 6421 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 6422 root.get(), root->bounds(), &render_surface_layer_list); | |
| 6423 inputs.can_adjust_raster_scales = true; | |
| 6424 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 6425 | |
| 6426 // The visible_content_rect for the |surface_child| should not be clipped by | |
| 6427 // the viewport. | |
| 6428 EXPECT_EQ(gfx::Rect(50, 50).ToString(), | |
| 6429 surface_child->visible_content_rect().ToString()); | |
| 6430 } | |
| 6431 | |
| 6432 TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { | |
| 6433 // Ensure that a transform between the layer and its render surface is not a | |
| 6434 // problem. Constructs the following layer tree. | |
| 6435 // | |
| 6436 // root (a render surface) | |
| 6437 // + render_surface | |
| 6438 // + clip_parent (scaled) | |
| 6439 // + intervening_clipping_layer | |
| 6440 // + clip_child | |
| 6441 // | |
| 6442 // The render surface should be resized correctly and the clip child should | |
| 6443 // inherit the right clip rect. | |
| 6444 scoped_refptr<Layer> root = Layer::Create(); | |
| 6445 scoped_refptr<Layer> render_surface = Layer::Create(); | |
| 6446 scoped_refptr<Layer> clip_parent = Layer::Create(); | |
| 6447 scoped_refptr<Layer> intervening = Layer::Create(); | |
| 6448 scoped_refptr<LayerWithForcedDrawsContent> clip_child = | |
| 6449 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 6450 | |
| 6451 root->AddChild(render_surface); | |
| 6452 render_surface->AddChild(clip_parent); | |
| 6453 clip_parent->AddChild(intervening); | |
| 6454 intervening->AddChild(clip_child); | |
| 6455 | |
| 6456 clip_child->SetClipParent(clip_parent.get()); | |
| 6457 | |
| 6458 intervening->SetMasksToBounds(true); | |
| 6459 clip_parent->SetMasksToBounds(true); | |
| 6460 | |
| 6461 render_surface->SetForceRenderSurface(true); | |
| 6462 | |
| 6463 gfx::Transform scale_transform; | |
| 6464 scale_transform.Scale(2, 2); | |
| 6465 | |
| 6466 gfx::Transform identity_transform; | |
| 6467 | |
| 6468 SetLayerPropertiesForTesting(root.get(), | |
| 6469 identity_transform, | |
| 6470 gfx::Point3F(), | |
| 6471 gfx::PointF(), | |
| 6472 gfx::Size(50, 50), | |
| 6473 true, | |
| 6474 false); | |
| 6475 SetLayerPropertiesForTesting(render_surface.get(), | |
| 6476 identity_transform, | |
| 6477 gfx::Point3F(), | |
| 6478 gfx::PointF(), | |
| 6479 gfx::Size(10, 10), | |
| 6480 true, | |
| 6481 false); | |
| 6482 SetLayerPropertiesForTesting(clip_parent.get(), | |
| 6483 scale_transform, | |
| 6484 gfx::Point3F(), | |
| 6485 gfx::PointF(1.f, 1.f), | |
| 6486 gfx::Size(10, 10), | |
| 6487 true, | |
| 6488 false); | |
| 6489 SetLayerPropertiesForTesting(intervening.get(), | |
| 6490 identity_transform, | |
| 6491 gfx::Point3F(), | |
| 6492 gfx::PointF(1.f, 1.f), | |
| 6493 gfx::Size(5, 5), | |
| 6494 true, | |
| 6495 false); | |
| 6496 SetLayerPropertiesForTesting(clip_child.get(), | |
| 6497 identity_transform, | |
| 6498 gfx::Point3F(), | |
| 6499 gfx::PointF(1.f, 1.f), | |
| 6500 gfx::Size(10, 10), | |
| 6501 true, | |
| 6502 false); | |
| 6503 | |
| 6504 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 6505 host->SetRootLayer(root); | |
| 6506 | |
| 6507 ExecuteCalculateDrawProperties(root.get()); | |
| 6508 | |
| 6509 ASSERT_TRUE(root->render_surface()); | |
| 6510 ASSERT_TRUE(render_surface->render_surface()); | |
| 6511 | |
| 6512 // Ensure that we've inherited our clip parent's clip and weren't affected | |
| 6513 // by the intervening clip layer. | |
| 6514 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(), | |
| 6515 clip_parent->clip_rect().ToString()); | |
| 6516 ASSERT_EQ(clip_parent->clip_rect().ToString(), | |
| 6517 clip_child->clip_rect().ToString()); | |
| 6518 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(), | |
| 6519 intervening->clip_rect().ToString()); | |
| 6520 | |
| 6521 // Ensure that the render surface reports a content rect that has been grown | |
| 6522 // to accomodate for the clip child. | |
| 6523 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(), | |
| 6524 render_surface->render_surface()->content_rect().ToString()); | |
| 6525 | |
| 6526 // The above check implies the two below, but they nicely demonstrate that | |
| 6527 // we've grown, despite the intervening layer's clip. | |
| 6528 ASSERT_TRUE(clip_parent->clip_rect().Contains( | |
| 6529 render_surface->render_surface()->content_rect())); | |
| 6530 ASSERT_FALSE(intervening->clip_rect().Contains( | |
| 6531 render_surface->render_surface()->content_rect())); | |
| 6532 } | |
| 6533 | |
| 6534 TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { | |
| 6535 // Ensure that intervening render surfaces are not a problem in the basic | |
| 6536 // case. In the following tree, both render surfaces should be resized to | |
| 6537 // accomodate for the clip child, despite an intervening clip. | |
| 6538 // | |
| 6539 // root (a render surface) | |
| 6540 // + clip_parent (masks to bounds) | |
| 6541 // + render_surface1 (sets opacity) | |
| 6542 // + intervening (masks to bounds) | |
| 6543 // + render_surface2 (also sets opacity) | |
| 6544 // + clip_child | |
| 6545 // | |
| 6546 scoped_refptr<Layer> root = Layer::Create(); | |
| 6547 scoped_refptr<Layer> clip_parent = Layer::Create(); | |
| 6548 scoped_refptr<Layer> render_surface1 = Layer::Create(); | |
| 6549 scoped_refptr<Layer> intervening = Layer::Create(); | |
| 6550 scoped_refptr<Layer> render_surface2 = Layer::Create(); | |
| 6551 scoped_refptr<LayerWithForcedDrawsContent> clip_child = | |
| 6552 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 6553 | |
| 6554 root->AddChild(clip_parent); | |
| 6555 clip_parent->AddChild(render_surface1); | |
| 6556 render_surface1->AddChild(intervening); | |
| 6557 intervening->AddChild(render_surface2); | |
| 6558 render_surface2->AddChild(clip_child); | |
| 6559 | |
| 6560 clip_child->SetClipParent(clip_parent.get()); | |
| 6561 | |
| 6562 intervening->SetMasksToBounds(true); | |
| 6563 clip_parent->SetMasksToBounds(true); | |
| 6564 | |
| 6565 render_surface1->SetForceRenderSurface(true); | |
| 6566 render_surface2->SetForceRenderSurface(true); | |
| 6567 | |
| 6568 gfx::Transform translation_transform; | |
| 6569 translation_transform.Translate(2, 2); | |
| 6570 | |
| 6571 gfx::Transform identity_transform; | |
| 6572 SetLayerPropertiesForTesting(root.get(), | |
| 6573 identity_transform, | |
| 6574 gfx::Point3F(), | |
| 6575 gfx::PointF(), | |
| 6576 gfx::Size(50, 50), | |
| 6577 true, | |
| 6578 false); | |
| 6579 SetLayerPropertiesForTesting(clip_parent.get(), | |
| 6580 translation_transform, | |
| 6581 gfx::Point3F(), | |
| 6582 gfx::PointF(1.f, 1.f), | |
| 6583 gfx::Size(40, 40), | |
| 6584 true, | |
| 6585 false); | |
| 6586 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 6587 identity_transform, | |
| 6588 gfx::Point3F(), | |
| 6589 gfx::PointF(), | |
| 6590 gfx::Size(10, 10), | |
| 6591 true, | |
| 6592 false); | |
| 6593 SetLayerPropertiesForTesting(intervening.get(), | |
| 6594 identity_transform, | |
| 6595 gfx::Point3F(), | |
| 6596 gfx::PointF(1.f, 1.f), | |
| 6597 gfx::Size(5, 5), | |
| 6598 true, | |
| 6599 false); | |
| 6600 SetLayerPropertiesForTesting(render_surface2.get(), | |
| 6601 identity_transform, | |
| 6602 gfx::Point3F(), | |
| 6603 gfx::PointF(), | |
| 6604 gfx::Size(10, 10), | |
| 6605 true, | |
| 6606 false); | |
| 6607 SetLayerPropertiesForTesting(clip_child.get(), | |
| 6608 identity_transform, | |
| 6609 gfx::Point3F(), | |
| 6610 gfx::PointF(-10.f, -10.f), | |
| 6611 gfx::Size(60, 60), | |
| 6612 true, | |
| 6613 false); | |
| 6614 | |
| 6615 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 6616 host->SetRootLayer(root); | |
| 6617 | |
| 6618 ExecuteCalculateDrawProperties(root.get()); | |
| 6619 | |
| 6620 EXPECT_TRUE(root->render_surface()); | |
| 6621 EXPECT_TRUE(render_surface1->render_surface()); | |
| 6622 EXPECT_TRUE(render_surface2->render_surface()); | |
| 6623 | |
| 6624 // Since the render surfaces could have expanded, they should not clip (their | |
| 6625 // bounds would no longer be reliable). We should resort to layer clipping | |
| 6626 // in this case. | |
| 6627 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), | |
| 6628 render_surface1->render_surface()->clip_rect().ToString()); | |
| 6629 EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); | |
| 6630 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), | |
| 6631 render_surface2->render_surface()->clip_rect().ToString()); | |
| 6632 EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); | |
| 6633 | |
| 6634 // NB: clip rects are in target space. | |
| 6635 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), | |
| 6636 render_surface1->clip_rect().ToString()); | |
| 6637 EXPECT_TRUE(render_surface1->is_clipped()); | |
| 6638 | |
| 6639 // This value is inherited from the clipping ancestor layer, 'intervening'. | |
| 6640 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), | |
| 6641 render_surface2->clip_rect().ToString()); | |
| 6642 EXPECT_TRUE(render_surface2->is_clipped()); | |
| 6643 | |
| 6644 // The content rects of both render surfaces should both have expanded to | |
| 6645 // contain the clip child. | |
| 6646 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), | |
| 6647 render_surface1->render_surface()->content_rect().ToString()); | |
| 6648 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), | |
| 6649 render_surface2->render_surface()->content_rect().ToString()); | |
| 6650 | |
| 6651 // The clip child should have inherited the clip parent's clip (projected to | |
| 6652 // the right space, of course), and should have the correctly sized visible | |
| 6653 // content rect. | |
| 6654 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), | |
| 6655 clip_child->clip_rect().ToString()); | |
| 6656 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(), | |
| 6657 clip_child->visible_content_rect().ToString()); | |
| 6658 EXPECT_TRUE(clip_child->is_clipped()); | |
| 6659 } | |
| 6660 | |
| 6661 TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { | |
| 6662 // Ensure that intervening render surfaces are not a problem, even if there | |
| 6663 // is a scroll involved. Note, we do _not_ have to consider any other sort | |
| 6664 // of transform. | |
| 6665 // | |
| 6666 // root (a render surface) | |
| 6667 // + clip_parent (masks to bounds) | |
| 6668 // + render_surface1 (sets opacity) | |
| 6669 // + intervening (masks to bounds AND scrolls) | |
| 6670 // + render_surface2 (also sets opacity) | |
| 6671 // + clip_child | |
| 6672 // | |
| 6673 scoped_refptr<Layer> root = Layer::Create(); | |
| 6674 scoped_refptr<Layer> clip_parent = Layer::Create(); | |
| 6675 scoped_refptr<Layer> render_surface1 = Layer::Create(); | |
| 6676 scoped_refptr<Layer> intervening = Layer::Create(); | |
| 6677 scoped_refptr<Layer> render_surface2 = Layer::Create(); | |
| 6678 scoped_refptr<LayerWithForcedDrawsContent> clip_child = | |
| 6679 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 6680 | |
| 6681 root->AddChild(clip_parent); | |
| 6682 clip_parent->AddChild(render_surface1); | |
| 6683 render_surface1->AddChild(intervening); | |
| 6684 intervening->AddChild(render_surface2); | |
| 6685 render_surface2->AddChild(clip_child); | |
| 6686 | |
| 6687 clip_child->SetClipParent(clip_parent.get()); | |
| 6688 | |
| 6689 intervening->SetMasksToBounds(true); | |
| 6690 clip_parent->SetMasksToBounds(true); | |
| 6691 intervening->SetScrollClipLayerId(clip_parent->id()); | |
| 6692 intervening->SetScrollOffset(gfx::ScrollOffset(3, 3)); | |
| 6693 | |
| 6694 render_surface1->SetForceRenderSurface(true); | |
| 6695 render_surface2->SetForceRenderSurface(true); | |
| 6696 | |
| 6697 gfx::Transform translation_transform; | |
| 6698 translation_transform.Translate(2, 2); | |
| 6699 | |
| 6700 gfx::Transform identity_transform; | |
| 6701 SetLayerPropertiesForTesting(root.get(), | |
| 6702 identity_transform, | |
| 6703 gfx::Point3F(), | |
| 6704 gfx::PointF(), | |
| 6705 gfx::Size(50, 50), | |
| 6706 true, | |
| 6707 false); | |
| 6708 SetLayerPropertiesForTesting(clip_parent.get(), | |
| 6709 translation_transform, | |
| 6710 gfx::Point3F(), | |
| 6711 gfx::PointF(1.f, 1.f), | |
| 6712 gfx::Size(40, 40), | |
| 6713 true, | |
| 6714 false); | |
| 6715 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 6716 identity_transform, | |
| 6717 gfx::Point3F(), | |
| 6718 gfx::PointF(), | |
| 6719 gfx::Size(10, 10), | |
| 6720 true, | |
| 6721 false); | |
| 6722 SetLayerPropertiesForTesting(intervening.get(), | |
| 6723 identity_transform, | |
| 6724 gfx::Point3F(), | |
| 6725 gfx::PointF(1.f, 1.f), | |
| 6726 gfx::Size(5, 5), | |
| 6727 true, | |
| 6728 false); | |
| 6729 SetLayerPropertiesForTesting(render_surface2.get(), | |
| 6730 identity_transform, | |
| 6731 gfx::Point3F(), | |
| 6732 gfx::PointF(), | |
| 6733 gfx::Size(10, 10), | |
| 6734 true, | |
| 6735 false); | |
| 6736 SetLayerPropertiesForTesting(clip_child.get(), | |
| 6737 identity_transform, | |
| 6738 gfx::Point3F(), | |
| 6739 gfx::PointF(-10.f, -10.f), | |
| 6740 gfx::Size(60, 60), | |
| 6741 true, | |
| 6742 false); | |
| 6743 | |
| 6744 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 6745 host->SetRootLayer(root); | |
| 6746 | |
| 6747 ExecuteCalculateDrawProperties(root.get()); | |
| 6748 | |
| 6749 EXPECT_TRUE(root->render_surface()); | |
| 6750 EXPECT_TRUE(render_surface1->render_surface()); | |
| 6751 EXPECT_TRUE(render_surface2->render_surface()); | |
| 6752 | |
| 6753 // Since the render surfaces could have expanded, they should not clip (their | |
| 6754 // bounds would no longer be reliable). We should resort to layer clipping | |
| 6755 // in this case. | |
| 6756 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), | |
| 6757 render_surface1->render_surface()->clip_rect().ToString()); | |
| 6758 EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); | |
| 6759 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), | |
| 6760 render_surface2->render_surface()->clip_rect().ToString()); | |
| 6761 EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); | |
| 6762 | |
| 6763 // NB: clip rects are in target space. | |
| 6764 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), | |
| 6765 render_surface1->clip_rect().ToString()); | |
| 6766 EXPECT_TRUE(render_surface1->is_clipped()); | |
| 6767 | |
| 6768 // This value is inherited from the clipping ancestor layer, 'intervening'. | |
| 6769 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(), | |
| 6770 render_surface2->clip_rect().ToString()); | |
| 6771 EXPECT_TRUE(render_surface2->is_clipped()); | |
| 6772 | |
| 6773 // The content rects of both render surfaces should both have expanded to | |
| 6774 // contain the clip child. | |
| 6775 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), | |
| 6776 render_surface1->render_surface()->content_rect().ToString()); | |
| 6777 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), | |
| 6778 render_surface2->render_surface()->content_rect().ToString()); | |
| 6779 | |
| 6780 // The clip child should have inherited the clip parent's clip (projected to | |
| 6781 // the right space, of course), and should have the correctly sized visible | |
| 6782 // content rect. | |
| 6783 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), | |
| 6784 clip_child->clip_rect().ToString()); | |
| 6785 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(), | |
| 6786 clip_child->visible_content_rect().ToString()); | |
| 6787 EXPECT_TRUE(clip_child->is_clipped()); | |
| 6788 } | |
| 6789 | |
| 6790 TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { | |
| 6791 // Ensures that descendants of the clip child inherit the correct clip. | |
| 6792 // | |
| 6793 // root (a render surface) | |
| 6794 // + clip_parent (masks to bounds) | |
| 6795 // + intervening (masks to bounds) | |
| 6796 // + clip_child | |
| 6797 // + child | |
| 6798 // | |
| 6799 scoped_refptr<Layer> root = Layer::Create(); | |
| 6800 scoped_refptr<Layer> clip_parent = Layer::Create(); | |
| 6801 scoped_refptr<Layer> intervening = Layer::Create(); | |
| 6802 scoped_refptr<Layer> clip_child = Layer::Create(); | |
| 6803 scoped_refptr<LayerWithForcedDrawsContent> child = | |
| 6804 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 6805 | |
| 6806 root->AddChild(clip_parent); | |
| 6807 clip_parent->AddChild(intervening); | |
| 6808 intervening->AddChild(clip_child); | |
| 6809 clip_child->AddChild(child); | |
| 6810 | |
| 6811 clip_child->SetClipParent(clip_parent.get()); | |
| 6812 | |
| 6813 intervening->SetMasksToBounds(true); | |
| 6814 clip_parent->SetMasksToBounds(true); | |
| 6815 | |
| 6816 gfx::Transform identity_transform; | |
| 6817 SetLayerPropertiesForTesting(root.get(), | |
| 6818 identity_transform, | |
| 6819 gfx::Point3F(), | |
| 6820 gfx::PointF(), | |
| 6821 gfx::Size(50, 50), | |
| 6822 true, | |
| 6823 false); | |
| 6824 SetLayerPropertiesForTesting(clip_parent.get(), | |
| 6825 identity_transform, | |
| 6826 gfx::Point3F(), | |
| 6827 gfx::PointF(), | |
| 6828 gfx::Size(40, 40), | |
| 6829 true, | |
| 6830 false); | |
| 6831 SetLayerPropertiesForTesting(intervening.get(), | |
| 6832 identity_transform, | |
| 6833 gfx::Point3F(), | |
| 6834 gfx::PointF(), | |
| 6835 gfx::Size(5, 5), | |
| 6836 true, | |
| 6837 false); | |
| 6838 SetLayerPropertiesForTesting(clip_child.get(), | |
| 6839 identity_transform, | |
| 6840 gfx::Point3F(), | |
| 6841 gfx::PointF(), | |
| 6842 gfx::Size(60, 60), | |
| 6843 true, | |
| 6844 false); | |
| 6845 SetLayerPropertiesForTesting(child.get(), | |
| 6846 identity_transform, | |
| 6847 gfx::Point3F(), | |
| 6848 gfx::PointF(), | |
| 6849 gfx::Size(60, 60), | |
| 6850 true, | |
| 6851 false); | |
| 6852 | |
| 6853 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 6854 host->SetRootLayer(root); | |
| 6855 | |
| 6856 ExecuteCalculateDrawProperties(root.get()); | |
| 6857 | |
| 6858 EXPECT_TRUE(root->render_surface()); | |
| 6859 | |
| 6860 // Neither the clip child nor its descendant should have inherited the clip | |
| 6861 // from |intervening|. | |
| 6862 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), | |
| 6863 clip_child->clip_rect().ToString()); | |
| 6864 EXPECT_TRUE(clip_child->is_clipped()); | |
| 6865 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), | |
| 6866 child->visible_content_rect().ToString()); | |
| 6867 EXPECT_TRUE(child->is_clipped()); | |
| 6868 } | |
| 6869 | |
| 6870 TEST_F(LayerTreeHostCommonTest, | |
| 6871 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { | |
| 6872 // Ensures that non-descendant clip children in the tree do not affect | |
| 6873 // render surfaces. | |
| 6874 // | |
| 6875 // root (a render surface) | |
| 6876 // + clip_parent (masks to bounds) | |
| 6877 // + render_surface1 | |
| 6878 // + clip_child | |
| 6879 // + render_surface2 | |
| 6880 // + non_clip_child | |
| 6881 // | |
| 6882 // In this example render_surface2 should be unaffected by clip_child. | |
| 6883 scoped_refptr<Layer> root = Layer::Create(); | |
| 6884 scoped_refptr<Layer> clip_parent = Layer::Create(); | |
| 6885 scoped_refptr<Layer> render_surface1 = Layer::Create(); | |
| 6886 scoped_refptr<LayerWithForcedDrawsContent> clip_child = | |
| 6887 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 6888 scoped_refptr<Layer> render_surface2 = Layer::Create(); | |
| 6889 scoped_refptr<LayerWithForcedDrawsContent> non_clip_child = | |
| 6890 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 6891 | |
| 6892 root->AddChild(clip_parent); | |
| 6893 clip_parent->AddChild(render_surface1); | |
| 6894 render_surface1->AddChild(clip_child); | |
| 6895 clip_parent->AddChild(render_surface2); | |
| 6896 render_surface2->AddChild(non_clip_child); | |
| 6897 | |
| 6898 clip_child->SetClipParent(clip_parent.get()); | |
| 6899 | |
| 6900 clip_parent->SetMasksToBounds(true); | |
| 6901 render_surface1->SetMasksToBounds(true); | |
| 6902 | |
| 6903 gfx::Transform identity_transform; | |
| 6904 SetLayerPropertiesForTesting(root.get(), | |
| 6905 identity_transform, | |
| 6906 gfx::Point3F(), | |
| 6907 gfx::PointF(), | |
| 6908 gfx::Size(15, 15), | |
| 6909 true, | |
| 6910 false); | |
| 6911 SetLayerPropertiesForTesting(clip_parent.get(), | |
| 6912 identity_transform, | |
| 6913 gfx::Point3F(), | |
| 6914 gfx::PointF(), | |
| 6915 gfx::Size(10, 10), | |
| 6916 true, | |
| 6917 false); | |
| 6918 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 6919 identity_transform, | |
| 6920 gfx::Point3F(), | |
| 6921 gfx::PointF(5, 5), | |
| 6922 gfx::Size(5, 5), | |
| 6923 true, | |
| 6924 false); | |
| 6925 SetLayerPropertiesForTesting(render_surface2.get(), | |
| 6926 identity_transform, | |
| 6927 gfx::Point3F(), | |
| 6928 gfx::PointF(), | |
| 6929 gfx::Size(5, 5), | |
| 6930 true, | |
| 6931 false); | |
| 6932 SetLayerPropertiesForTesting(clip_child.get(), | |
| 6933 identity_transform, | |
| 6934 gfx::Point3F(), | |
| 6935 gfx::PointF(-1, 1), | |
| 6936 gfx::Size(10, 10), | |
| 6937 true, | |
| 6938 false); | |
| 6939 SetLayerPropertiesForTesting(non_clip_child.get(), | |
| 6940 identity_transform, | |
| 6941 gfx::Point3F(), | |
| 6942 gfx::PointF(), | |
| 6943 gfx::Size(5, 5), | |
| 6944 true, | |
| 6945 false); | |
| 6946 | |
| 6947 render_surface1->SetForceRenderSurface(true); | |
| 6948 render_surface2->SetForceRenderSurface(true); | |
| 6949 | |
| 6950 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 6951 host->SetRootLayer(root); | |
| 6952 | |
| 6953 ExecuteCalculateDrawProperties(root.get()); | |
| 6954 | |
| 6955 EXPECT_TRUE(root->render_surface()); | |
| 6956 EXPECT_TRUE(render_surface1->render_surface()); | |
| 6957 EXPECT_TRUE(render_surface2->render_surface()); | |
| 6958 | |
| 6959 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), | |
| 6960 render_surface1->clip_rect().ToString()); | |
| 6961 EXPECT_TRUE(render_surface1->is_clipped()); | |
| 6962 | |
| 6963 // The render surface should not clip (it has unclipped descendants), instead | |
| 6964 // it should rely on layer clipping. | |
| 6965 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), | |
| 6966 render_surface1->render_surface()->clip_rect().ToString()); | |
| 6967 EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); | |
| 6968 | |
| 6969 // That said, it should have grown to accomodate the unclipped descendant. | |
| 6970 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(), | |
| 6971 render_surface1->render_surface()->content_rect().ToString()); | |
| 6972 | |
| 6973 // This render surface should clip. It has no unclipped descendants. | |
| 6974 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), | |
| 6975 render_surface2->clip_rect().ToString()); | |
| 6976 EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); | |
| 6977 | |
| 6978 // It also shouldn't have grown to accomodate the clip child. | |
| 6979 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), | |
| 6980 render_surface2->render_surface()->content_rect().ToString()); | |
| 6981 | |
| 6982 // Sanity check our num_unclipped_descendants values. | |
| 6983 EXPECT_EQ(1, render_surface1->num_unclipped_descendants()); | |
| 6984 EXPECT_EQ(0, render_surface2->num_unclipped_descendants()); | |
| 6985 } | |
| 6986 | |
| 6987 TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { | |
| 6988 FakeImplProxy proxy; | |
| 6989 TestSharedBitmapManager shared_bitmap_manager; | |
| 6990 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 6991 scoped_ptr<LayerImpl> root = | |
| 6992 LayerImpl::Create(host_impl.active_tree(), 12345); | |
| 6993 scoped_ptr<LayerImpl> child1 = | |
| 6994 LayerImpl::Create(host_impl.active_tree(), 123456); | |
| 6995 scoped_ptr<LayerImpl> child2 = | |
| 6996 LayerImpl::Create(host_impl.active_tree(), 1234567); | |
| 6997 scoped_ptr<LayerImpl> child3 = | |
| 6998 LayerImpl::Create(host_impl.active_tree(), 12345678); | |
| 6999 | |
| 7000 gfx::Transform identity_matrix; | |
| 7001 gfx::Point3F transform_origin; | |
| 7002 gfx::PointF position; | |
| 7003 gfx::Size bounds(100, 100); | |
| 7004 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, | |
| 7005 position, bounds, true, false, true); | |
| 7006 root->SetDrawsContent(true); | |
| 7007 | |
| 7008 // This layer structure normally forces render surface due to preserves3d | |
| 7009 // behavior. | |
| 7010 SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin, | |
| 7011 position, bounds, false, true, true); | |
| 7012 child1->SetDrawsContent(true); | |
| 7013 SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin, | |
| 7014 position, bounds, true, false, false); | |
| 7015 child2->SetDrawsContent(true); | |
| 7016 SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin, | |
| 7017 position, bounds, true, false, false); | |
| 7018 child3->SetDrawsContent(true); | |
| 7019 | |
| 7020 child2->Set3dSortingContextId(1); | |
| 7021 child3->Set3dSortingContextId(1); | |
| 7022 | |
| 7023 child2->AddChild(child3.Pass()); | |
| 7024 child1->AddChild(child2.Pass()); | |
| 7025 root->AddChild(child1.Pass()); | |
| 7026 | |
| 7027 { | |
| 7028 LayerImplList render_surface_layer_list; | |
| 7029 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get()); | |
| 7030 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 7031 root.get(), root->bounds(), &render_surface_layer_list); | |
| 7032 inputs.can_render_to_separate_surface = true; | |
| 7033 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 7034 | |
| 7035 EXPECT_EQ(2u, render_surface_layer_list.size()); | |
| 7036 | |
| 7037 int count_represents_target_render_surface = 0; | |
| 7038 int count_represents_contributing_render_surface = 0; | |
| 7039 int count_represents_itself = 0; | |
| 7040 auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list); | |
| 7041 for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list); | |
| 7042 it != end; ++it) { | |
| 7043 if (it.represents_target_render_surface()) | |
| 7044 count_represents_target_render_surface++; | |
| 7045 if (it.represents_contributing_render_surface()) | |
| 7046 count_represents_contributing_render_surface++; | |
| 7047 if (it.represents_itself()) | |
| 7048 count_represents_itself++; | |
| 7049 } | |
| 7050 | |
| 7051 // Two render surfaces. | |
| 7052 EXPECT_EQ(2, count_represents_target_render_surface); | |
| 7053 // Second render surface contributes to root render surface. | |
| 7054 EXPECT_EQ(1, count_represents_contributing_render_surface); | |
| 7055 // All 4 layers represent itself. | |
| 7056 EXPECT_EQ(4, count_represents_itself); | |
| 7057 } | |
| 7058 | |
| 7059 { | |
| 7060 LayerImplList render_surface_layer_list; | |
| 7061 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 7062 root.get(), root->bounds(), &render_surface_layer_list); | |
| 7063 inputs.can_render_to_separate_surface = false; | |
| 7064 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 7065 | |
| 7066 EXPECT_EQ(1u, render_surface_layer_list.size()); | |
| 7067 | |
| 7068 int count_represents_target_render_surface = 0; | |
| 7069 int count_represents_contributing_render_surface = 0; | |
| 7070 int count_represents_itself = 0; | |
| 7071 auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list); | |
| 7072 for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list); | |
| 7073 it != end; ++it) { | |
| 7074 if (it.represents_target_render_surface()) | |
| 7075 count_represents_target_render_surface++; | |
| 7076 if (it.represents_contributing_render_surface()) | |
| 7077 count_represents_contributing_render_surface++; | |
| 7078 if (it.represents_itself()) | |
| 7079 count_represents_itself++; | |
| 7080 } | |
| 7081 | |
| 7082 // Only root layer has a render surface. | |
| 7083 EXPECT_EQ(1, count_represents_target_render_surface); | |
| 7084 // No layer contributes a render surface to root render surface. | |
| 7085 EXPECT_EQ(0, count_represents_contributing_render_surface); | |
| 7086 // All 4 layers represent itself. | |
| 7087 EXPECT_EQ(4, count_represents_itself); | |
| 7088 } | |
| 7089 } | |
| 7090 | |
| 7091 TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { | |
| 7092 scoped_refptr<Layer> root = Layer::Create(); | |
| 7093 scoped_refptr<Layer> render_surface = Layer::Create(); | |
| 7094 scoped_refptr<LayerWithForcedDrawsContent> child = | |
| 7095 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7096 | |
| 7097 root->AddChild(render_surface); | |
| 7098 render_surface->AddChild(child); | |
| 7099 | |
| 7100 gfx::Transform identity_transform; | |
| 7101 SetLayerPropertiesForTesting(root.get(), | |
| 7102 identity_transform, | |
| 7103 gfx::Point3F(), | |
| 7104 gfx::PointF(), | |
| 7105 gfx::Size(50, 50), | |
| 7106 true, | |
| 7107 false); | |
| 7108 SetLayerPropertiesForTesting(render_surface.get(), | |
| 7109 identity_transform, | |
| 7110 gfx::Point3F(), | |
| 7111 gfx::PointF(), | |
| 7112 gfx::Size(30, 30), | |
| 7113 false, | |
| 7114 true); | |
| 7115 SetLayerPropertiesForTesting(child.get(), | |
| 7116 identity_transform, | |
| 7117 gfx::Point3F(), | |
| 7118 gfx::PointF(), | |
| 7119 gfx::Size(20, 20), | |
| 7120 true, | |
| 7121 false); | |
| 7122 | |
| 7123 root->SetShouldFlattenTransform(false); | |
| 7124 root->Set3dSortingContextId(1); | |
| 7125 render_surface->SetDoubleSided(false); | |
| 7126 render_surface->SetForceRenderSurface(true); | |
| 7127 | |
| 7128 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 7129 host->SetRootLayer(root); | |
| 7130 | |
| 7131 ExecuteCalculateDrawProperties(root.get()); | |
| 7132 | |
| 7133 EXPECT_EQ(2u, render_surface_layer_list()->size()); | |
| 7134 EXPECT_EQ(1u, | |
| 7135 render_surface_layer_list()->at(0) | |
| 7136 ->render_surface()->layer_list().size()); | |
| 7137 EXPECT_EQ(1u, | |
| 7138 render_surface_layer_list()->at(1) | |
| 7139 ->render_surface()->layer_list().size()); | |
| 7140 | |
| 7141 gfx::Transform rotation_transform = identity_transform; | |
| 7142 rotation_transform.RotateAboutXAxis(180.0); | |
| 7143 | |
| 7144 render_surface->SetTransform(rotation_transform); | |
| 7145 | |
| 7146 ExecuteCalculateDrawProperties(root.get()); | |
| 7147 | |
| 7148 EXPECT_EQ(1u, render_surface_layer_list()->size()); | |
| 7149 EXPECT_EQ(0u, | |
| 7150 render_surface_layer_list()->at(0) | |
| 7151 ->render_surface()->layer_list().size()); | |
| 7152 } | |
| 7153 | |
| 7154 TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { | |
| 7155 // Checks that the simple case (being clipped by a scroll parent that would | |
| 7156 // have been processed before you anyhow) results in the right clips. | |
| 7157 // | |
| 7158 // + root | |
| 7159 // + scroll_parent_border | |
| 7160 // | + scroll_parent_clip | |
| 7161 // | + scroll_parent | |
| 7162 // + scroll_child | |
| 7163 // | |
| 7164 scoped_refptr<Layer> root = Layer::Create(); | |
| 7165 scoped_refptr<Layer> scroll_parent_border = Layer::Create(); | |
| 7166 scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); | |
| 7167 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = | |
| 7168 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7169 scoped_refptr<LayerWithForcedDrawsContent> scroll_child = | |
| 7170 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7171 | |
| 7172 root->AddChild(scroll_child); | |
| 7173 | |
| 7174 root->AddChild(scroll_parent_border); | |
| 7175 scroll_parent_border->AddChild(scroll_parent_clip); | |
| 7176 scroll_parent_clip->AddChild(scroll_parent); | |
| 7177 | |
| 7178 scroll_parent_clip->SetMasksToBounds(true); | |
| 7179 | |
| 7180 scroll_child->SetScrollParent(scroll_parent.get()); | |
| 7181 | |
| 7182 gfx::Transform identity_transform; | |
| 7183 SetLayerPropertiesForTesting(root.get(), | |
| 7184 identity_transform, | |
| 7185 gfx::Point3F(), | |
| 7186 gfx::PointF(), | |
| 7187 gfx::Size(50, 50), | |
| 7188 true, | |
| 7189 false); | |
| 7190 SetLayerPropertiesForTesting(scroll_parent_border.get(), | |
| 7191 identity_transform, | |
| 7192 gfx::Point3F(), | |
| 7193 gfx::PointF(), | |
| 7194 gfx::Size(40, 40), | |
| 7195 true, | |
| 7196 false); | |
| 7197 SetLayerPropertiesForTesting(scroll_parent_clip.get(), | |
| 7198 identity_transform, | |
| 7199 gfx::Point3F(), | |
| 7200 gfx::PointF(), | |
| 7201 gfx::Size(30, 30), | |
| 7202 true, | |
| 7203 false); | |
| 7204 SetLayerPropertiesForTesting(scroll_parent.get(), | |
| 7205 identity_transform, | |
| 7206 gfx::Point3F(), | |
| 7207 gfx::PointF(), | |
| 7208 gfx::Size(50, 50), | |
| 7209 true, | |
| 7210 false); | |
| 7211 SetLayerPropertiesForTesting(scroll_child.get(), | |
| 7212 identity_transform, | |
| 7213 gfx::Point3F(), | |
| 7214 gfx::PointF(), | |
| 7215 gfx::Size(50, 50), | |
| 7216 true, | |
| 7217 false); | |
| 7218 | |
| 7219 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 7220 host->SetRootLayer(root); | |
| 7221 | |
| 7222 ExecuteCalculateDrawProperties(root.get()); | |
| 7223 | |
| 7224 EXPECT_TRUE(root->render_surface()); | |
| 7225 | |
| 7226 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), | |
| 7227 scroll_child->clip_rect().ToString()); | |
| 7228 EXPECT_TRUE(scroll_child->is_clipped()); | |
| 7229 } | |
| 7230 | |
| 7231 TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { | |
| 7232 scoped_refptr<LayerWithForcedDrawsContent> root = | |
| 7233 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7234 scoped_refptr<LayerWithForcedDrawsContent> parent = | |
| 7235 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7236 scoped_refptr<LayerWithForcedDrawsContent> child = | |
| 7237 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7238 | |
| 7239 root->AddChild(parent); | |
| 7240 parent->AddChild(child); | |
| 7241 | |
| 7242 gfx::Transform identity_transform; | |
| 7243 SetLayerPropertiesForTesting(root.get(), | |
| 7244 identity_transform, | |
| 7245 gfx::Point3F(), | |
| 7246 gfx::PointF(), | |
| 7247 gfx::Size(50, 50), | |
| 7248 true, | |
| 7249 true); | |
| 7250 root->SetForceRenderSurface(true); | |
| 7251 SetLayerPropertiesForTesting(parent.get(), | |
| 7252 identity_transform, | |
| 7253 gfx::Point3F(), | |
| 7254 gfx::PointF(), | |
| 7255 gfx::Size(30, 30), | |
| 7256 true, | |
| 7257 true); | |
| 7258 parent->SetForceRenderSurface(true); | |
| 7259 SetLayerPropertiesForTesting(child.get(), | |
| 7260 identity_transform, | |
| 7261 gfx::Point3F(), | |
| 7262 gfx::PointF(), | |
| 7263 gfx::Size(20, 20), | |
| 7264 true, | |
| 7265 true); | |
| 7266 child->SetForceRenderSurface(true); | |
| 7267 | |
| 7268 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 7269 host->SetRootLayer(root); | |
| 7270 | |
| 7271 ExecuteCalculateDrawProperties(root.get()); | |
| 7272 | |
| 7273 EXPECT_EQ(3u, render_surface_layer_list()->size()); | |
| 7274 | |
| 7275 gfx::Transform singular_transform; | |
| 7276 singular_transform.Scale3d( | |
| 7277 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); | |
| 7278 | |
| 7279 child->SetTransform(singular_transform); | |
| 7280 | |
| 7281 ExecuteCalculateDrawProperties(root.get()); | |
| 7282 | |
| 7283 EXPECT_EQ(2u, render_surface_layer_list()->size()); | |
| 7284 | |
| 7285 // Ensure that the entire subtree under a layer with singular transform does | |
| 7286 // not get rendered. | |
| 7287 parent->SetTransform(singular_transform); | |
| 7288 child->SetTransform(identity_transform); | |
| 7289 | |
| 7290 ExecuteCalculateDrawProperties(root.get()); | |
| 7291 | |
| 7292 EXPECT_EQ(1u, render_surface_layer_list()->size()); | |
| 7293 } | |
| 7294 | |
| 7295 TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { | |
| 7296 // Checks that clipping by a scroll parent that follows you in paint order | |
| 7297 // still results in correct clipping. | |
| 7298 // | |
| 7299 // + root | |
| 7300 // + scroll_child | |
| 7301 // + scroll_parent_border | |
| 7302 // + scroll_parent_clip | |
| 7303 // + scroll_parent | |
| 7304 // | |
| 7305 scoped_refptr<Layer> root = Layer::Create(); | |
| 7306 scoped_refptr<Layer> scroll_parent_border = Layer::Create(); | |
| 7307 scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); | |
| 7308 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = | |
| 7309 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7310 scoped_refptr<LayerWithForcedDrawsContent> scroll_child = | |
| 7311 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7312 | |
| 7313 root->AddChild(scroll_parent_border); | |
| 7314 scroll_parent_border->AddChild(scroll_parent_clip); | |
| 7315 scroll_parent_clip->AddChild(scroll_parent); | |
| 7316 | |
| 7317 root->AddChild(scroll_child); | |
| 7318 | |
| 7319 scroll_parent_clip->SetMasksToBounds(true); | |
| 7320 | |
| 7321 scroll_child->SetScrollParent(scroll_parent.get()); | |
| 7322 | |
| 7323 gfx::Transform identity_transform; | |
| 7324 SetLayerPropertiesForTesting(root.get(), | |
| 7325 identity_transform, | |
| 7326 gfx::Point3F(), | |
| 7327 gfx::PointF(), | |
| 7328 gfx::Size(50, 50), | |
| 7329 true, | |
| 7330 false); | |
| 7331 SetLayerPropertiesForTesting(scroll_parent_border.get(), | |
| 7332 identity_transform, | |
| 7333 gfx::Point3F(), | |
| 7334 gfx::PointF(), | |
| 7335 gfx::Size(40, 40), | |
| 7336 true, | |
| 7337 false); | |
| 7338 SetLayerPropertiesForTesting(scroll_parent_clip.get(), | |
| 7339 identity_transform, | |
| 7340 gfx::Point3F(), | |
| 7341 gfx::PointF(), | |
| 7342 gfx::Size(30, 30), | |
| 7343 true, | |
| 7344 false); | |
| 7345 SetLayerPropertiesForTesting(scroll_parent.get(), | |
| 7346 identity_transform, | |
| 7347 gfx::Point3F(), | |
| 7348 gfx::PointF(), | |
| 7349 gfx::Size(50, 50), | |
| 7350 true, | |
| 7351 false); | |
| 7352 SetLayerPropertiesForTesting(scroll_child.get(), | |
| 7353 identity_transform, | |
| 7354 gfx::Point3F(), | |
| 7355 gfx::PointF(), | |
| 7356 gfx::Size(50, 50), | |
| 7357 true, | |
| 7358 false); | |
| 7359 | |
| 7360 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 7361 host->SetRootLayer(root); | |
| 7362 | |
| 7363 ExecuteCalculateDrawProperties(root.get()); | |
| 7364 | |
| 7365 EXPECT_TRUE(root->render_surface()); | |
| 7366 | |
| 7367 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), | |
| 7368 scroll_child->clip_rect().ToString()); | |
| 7369 EXPECT_TRUE(scroll_child->is_clipped()); | |
| 7370 } | |
| 7371 | |
| 7372 TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { | |
| 7373 // Checks that clipping by a scroll parent and scroll grandparent that follow | |
| 7374 // you in paint order still results in correct clipping. | |
| 7375 // | |
| 7376 // + root | |
| 7377 // + scroll_child | |
| 7378 // + scroll_parent_border | |
| 7379 // | + scroll_parent_clip | |
| 7380 // | + scroll_parent | |
| 7381 // + scroll_grandparent_border | |
| 7382 // + scroll_grandparent_clip | |
| 7383 // + scroll_grandparent | |
| 7384 // | |
| 7385 scoped_refptr<Layer> root = Layer::Create(); | |
| 7386 scoped_refptr<Layer> scroll_parent_border = Layer::Create(); | |
| 7387 scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); | |
| 7388 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = | |
| 7389 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7390 | |
| 7391 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); | |
| 7392 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); | |
| 7393 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = | |
| 7394 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7395 | |
| 7396 scoped_refptr<LayerWithForcedDrawsContent> scroll_child = | |
| 7397 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7398 | |
| 7399 root->AddChild(scroll_child); | |
| 7400 | |
| 7401 root->AddChild(scroll_parent_border); | |
| 7402 scroll_parent_border->AddChild(scroll_parent_clip); | |
| 7403 scroll_parent_clip->AddChild(scroll_parent); | |
| 7404 | |
| 7405 root->AddChild(scroll_grandparent_border); | |
| 7406 scroll_grandparent_border->AddChild(scroll_grandparent_clip); | |
| 7407 scroll_grandparent_clip->AddChild(scroll_grandparent); | |
| 7408 | |
| 7409 scroll_parent_clip->SetMasksToBounds(true); | |
| 7410 scroll_grandparent_clip->SetMasksToBounds(true); | |
| 7411 | |
| 7412 scroll_child->SetScrollParent(scroll_parent.get()); | |
| 7413 scroll_parent_border->SetScrollParent(scroll_grandparent.get()); | |
| 7414 | |
| 7415 gfx::Transform identity_transform; | |
| 7416 SetLayerPropertiesForTesting(root.get(), | |
| 7417 identity_transform, | |
| 7418 gfx::Point3F(), | |
| 7419 gfx::PointF(), | |
| 7420 gfx::Size(50, 50), | |
| 7421 true, | |
| 7422 false); | |
| 7423 SetLayerPropertiesForTesting(scroll_grandparent_border.get(), | |
| 7424 identity_transform, | |
| 7425 gfx::Point3F(), | |
| 7426 gfx::PointF(), | |
| 7427 gfx::Size(40, 40), | |
| 7428 true, | |
| 7429 false); | |
| 7430 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), | |
| 7431 identity_transform, | |
| 7432 gfx::Point3F(), | |
| 7433 gfx::PointF(), | |
| 7434 gfx::Size(20, 20), | |
| 7435 true, | |
| 7436 false); | |
| 7437 SetLayerPropertiesForTesting(scroll_grandparent.get(), | |
| 7438 identity_transform, | |
| 7439 gfx::Point3F(), | |
| 7440 gfx::PointF(), | |
| 7441 gfx::Size(50, 50), | |
| 7442 true, | |
| 7443 false); | |
| 7444 SetLayerPropertiesForTesting(scroll_parent_border.get(), | |
| 7445 identity_transform, | |
| 7446 gfx::Point3F(), | |
| 7447 gfx::PointF(), | |
| 7448 gfx::Size(40, 40), | |
| 7449 true, | |
| 7450 false); | |
| 7451 SetLayerPropertiesForTesting(scroll_parent_clip.get(), | |
| 7452 identity_transform, | |
| 7453 gfx::Point3F(), | |
| 7454 gfx::PointF(), | |
| 7455 gfx::Size(30, 30), | |
| 7456 true, | |
| 7457 false); | |
| 7458 SetLayerPropertiesForTesting(scroll_parent.get(), | |
| 7459 identity_transform, | |
| 7460 gfx::Point3F(), | |
| 7461 gfx::PointF(), | |
| 7462 gfx::Size(50, 50), | |
| 7463 true, | |
| 7464 false); | |
| 7465 SetLayerPropertiesForTesting(scroll_child.get(), | |
| 7466 identity_transform, | |
| 7467 gfx::Point3F(), | |
| 7468 gfx::PointF(), | |
| 7469 gfx::Size(50, 50), | |
| 7470 true, | |
| 7471 false); | |
| 7472 | |
| 7473 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 7474 host->SetRootLayer(root); | |
| 7475 | |
| 7476 ExecuteCalculateDrawProperties(root.get()); | |
| 7477 | |
| 7478 EXPECT_TRUE(root->render_surface()); | |
| 7479 | |
| 7480 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), | |
| 7481 scroll_child->clip_rect().ToString()); | |
| 7482 EXPECT_TRUE(scroll_child->is_clipped()); | |
| 7483 | |
| 7484 // Despite the fact that we visited the above layers out of order to get the | |
| 7485 // correct clip, the layer lists should be unaffected. | |
| 7486 EXPECT_EQ(3u, root->render_surface()->layer_list().size()); | |
| 7487 EXPECT_EQ(scroll_child.get(), | |
| 7488 root->render_surface()->layer_list().at(0).get()); | |
| 7489 EXPECT_EQ(scroll_parent.get(), | |
| 7490 root->render_surface()->layer_list().at(1).get()); | |
| 7491 EXPECT_EQ(scroll_grandparent.get(), | |
| 7492 root->render_surface()->layer_list().at(2).get()); | |
| 7493 } | |
| 7494 | |
| 7495 TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { | |
| 7496 // Ensures that even if we visit layers out of order, we still produce a | |
| 7497 // correctly ordered render surface layer list. | |
| 7498 // + root | |
| 7499 // + scroll_child | |
| 7500 // + scroll_parent_border | |
| 7501 // + scroll_parent_clip | |
| 7502 // + scroll_parent | |
| 7503 // + render_surface1 | |
| 7504 // + scroll_grandparent_border | |
| 7505 // + scroll_grandparent_clip | |
| 7506 // + scroll_grandparent | |
| 7507 // + render_surface2 | |
| 7508 // | |
| 7509 scoped_refptr<LayerWithForcedDrawsContent> root = | |
| 7510 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7511 | |
| 7512 scoped_refptr<Layer> scroll_parent_border = Layer::Create(); | |
| 7513 scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); | |
| 7514 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = | |
| 7515 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7516 scoped_refptr<LayerWithForcedDrawsContent> render_surface1 = | |
| 7517 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7518 | |
| 7519 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); | |
| 7520 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); | |
| 7521 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = | |
| 7522 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7523 scoped_refptr<LayerWithForcedDrawsContent> render_surface2 = | |
| 7524 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7525 | |
| 7526 scoped_refptr<LayerWithForcedDrawsContent> scroll_child = | |
| 7527 make_scoped_refptr(new LayerWithForcedDrawsContent); | |
| 7528 | |
| 7529 root->AddChild(scroll_child); | |
| 7530 | |
| 7531 root->AddChild(scroll_parent_border); | |
| 7532 scroll_parent_border->AddChild(scroll_parent_clip); | |
| 7533 scroll_parent_clip->AddChild(scroll_parent); | |
| 7534 scroll_parent->AddChild(render_surface2); | |
| 7535 | |
| 7536 root->AddChild(scroll_grandparent_border); | |
| 7537 scroll_grandparent_border->AddChild(scroll_grandparent_clip); | |
| 7538 scroll_grandparent_clip->AddChild(scroll_grandparent); | |
| 7539 scroll_grandparent->AddChild(render_surface1); | |
| 7540 | |
| 7541 scroll_parent_clip->SetMasksToBounds(true); | |
| 7542 scroll_grandparent_clip->SetMasksToBounds(true); | |
| 7543 | |
| 7544 scroll_child->SetScrollParent(scroll_parent.get()); | |
| 7545 scroll_parent_border->SetScrollParent(scroll_grandparent.get()); | |
| 7546 | |
| 7547 render_surface1->SetForceRenderSurface(true); | |
| 7548 render_surface2->SetForceRenderSurface(true); | |
| 7549 | |
| 7550 gfx::Transform identity_transform; | |
| 7551 SetLayerPropertiesForTesting(root.get(), | |
| 7552 identity_transform, | |
| 7553 gfx::Point3F(), | |
| 7554 gfx::PointF(), | |
| 7555 gfx::Size(50, 50), | |
| 7556 true, | |
| 7557 false); | |
| 7558 SetLayerPropertiesForTesting(scroll_grandparent_border.get(), | |
| 7559 identity_transform, | |
| 7560 gfx::Point3F(), | |
| 7561 gfx::PointF(), | |
| 7562 gfx::Size(40, 40), | |
| 7563 true, | |
| 7564 false); | |
| 7565 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), | |
| 7566 identity_transform, | |
| 7567 gfx::Point3F(), | |
| 7568 gfx::PointF(), | |
| 7569 gfx::Size(20, 20), | |
| 7570 true, | |
| 7571 false); | |
| 7572 SetLayerPropertiesForTesting(scroll_grandparent.get(), | |
| 7573 identity_transform, | |
| 7574 gfx::Point3F(), | |
| 7575 gfx::PointF(), | |
| 7576 gfx::Size(50, 50), | |
| 7577 true, | |
| 7578 false); | |
| 7579 SetLayerPropertiesForTesting(render_surface1.get(), | |
| 7580 identity_transform, | |
| 7581 gfx::Point3F(), | |
| 7582 gfx::PointF(), | |
| 7583 gfx::Size(50, 50), | |
| 7584 true, | |
| 7585 false); | |
| 7586 SetLayerPropertiesForTesting(scroll_parent_border.get(), | |
| 7587 identity_transform, | |
| 7588 gfx::Point3F(), | |
| 7589 gfx::PointF(), | |
| 7590 gfx::Size(40, 40), | |
| 7591 true, | |
| 7592 false); | |
| 7593 SetLayerPropertiesForTesting(scroll_parent_clip.get(), | |
| 7594 identity_transform, | |
| 7595 gfx::Point3F(), | |
| 7596 gfx::PointF(), | |
| 7597 gfx::Size(30, 30), | |
| 7598 true, | |
| 7599 false); | |
| 7600 SetLayerPropertiesForTesting(scroll_parent.get(), | |
| 7601 identity_transform, | |
| 7602 gfx::Point3F(), | |
| 7603 gfx::PointF(), | |
| 7604 gfx::Size(50, 50), | |
| 7605 true, | |
| 7606 false); | |
| 7607 SetLayerPropertiesForTesting(render_surface2.get(), | |
| 7608 identity_transform, | |
| 7609 gfx::Point3F(), | |
| 7610 gfx::PointF(), | |
| 7611 gfx::Size(50, 50), | |
| 7612 true, | |
| 7613 false); | |
| 7614 SetLayerPropertiesForTesting(scroll_child.get(), | |
| 7615 identity_transform, | |
| 7616 gfx::Point3F(), | |
| 7617 gfx::PointF(), | |
| 7618 gfx::Size(50, 50), | |
| 7619 true, | |
| 7620 false); | |
| 7621 | |
| 7622 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 7623 host->SetRootLayer(root); | |
| 7624 | |
| 7625 RenderSurfaceLayerList render_surface_layer_list; | |
| 7626 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 7627 root.get(), | |
| 7628 root->bounds(), | |
| 7629 identity_transform, | |
| 7630 &render_surface_layer_list); | |
| 7631 | |
| 7632 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 7633 | |
| 7634 EXPECT_TRUE(root->render_surface()); | |
| 7635 | |
| 7636 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), | |
| 7637 scroll_child->clip_rect().ToString()); | |
| 7638 EXPECT_TRUE(scroll_child->is_clipped()); | |
| 7639 | |
| 7640 // Despite the fact that we had to process the layers out of order to get the | |
| 7641 // right clip, our render_surface_layer_list's order should be unaffected. | |
| 7642 EXPECT_EQ(3u, render_surface_layer_list.size()); | |
| 7643 EXPECT_EQ(root.get(), render_surface_layer_list.at(0)); | |
| 7644 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1)); | |
| 7645 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2)); | |
| 7646 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface()); | |
| 7647 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface()); | |
| 7648 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface()); | |
| 7649 } | |
| 7650 | |
| 7651 TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) { | |
| 7652 // Ensures that when we have a render surface between a fixed position layer | |
| 7653 // and its container, we compute the fixed position layer's draw transform | |
| 7654 // with respect to that intervening render surface, not with respect to its | |
| 7655 // container's render target. | |
| 7656 // | |
| 7657 // + root | |
| 7658 // + render_surface | |
| 7659 // + fixed | |
| 7660 // | |
| 7661 scoped_refptr<Layer> root = Layer::Create(); | |
| 7662 scoped_refptr<LayerWithForcedDrawsContent> render_surface = | |
| 7663 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 7664 scoped_refptr<LayerWithForcedDrawsContent> fixed = | |
| 7665 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 7666 | |
| 7667 root->AddChild(render_surface); | |
| 7668 render_surface->AddChild(fixed); | |
| 7669 | |
| 7670 root->SetIsContainerForFixedPositionLayers(true); | |
| 7671 render_surface->SetForceRenderSurface(true); | |
| 7672 | |
| 7673 LayerPositionConstraint constraint; | |
| 7674 constraint.set_is_fixed_position(true); | |
| 7675 fixed->SetPositionConstraint(constraint); | |
| 7676 | |
| 7677 SetLayerPropertiesForTesting(root.get(), gfx::Transform(), gfx::Point3F(), | |
| 7678 gfx::PointF(), gfx::Size(50, 50), true, false); | |
| 7679 SetLayerPropertiesForTesting(render_surface.get(), gfx::Transform(), | |
| 7680 gfx::Point3F(), gfx::PointF(7.f, 9.f), | |
| 7681 gfx::Size(50, 50), true, false); | |
| 7682 SetLayerPropertiesForTesting(fixed.get(), gfx::Transform(), gfx::Point3F(), | |
| 7683 gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true, | |
| 7684 false); | |
| 7685 | |
| 7686 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 7687 host->SetRootLayer(root); | |
| 7688 | |
| 7689 ExecuteCalculateDrawProperties(root.get()); | |
| 7690 | |
| 7691 gfx::Transform expected_draw_transform; | |
| 7692 expected_draw_transform.Translate(10.f, 15.f); | |
| 7693 EXPECT_EQ(expected_draw_transform, fixed->draw_transform()); | |
| 7694 | |
| 7695 gfx::Transform expected_screen_space_transform; | |
| 7696 expected_screen_space_transform.Translate(17.f, 24.f); | |
| 7697 EXPECT_EQ(expected_screen_space_transform, fixed->screen_space_transform()); | |
| 7698 } | |
| 7699 | |
| 7700 TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { | |
| 7701 // This test verifies that a scrolling layer that gets snapped to | |
| 7702 // integer coordinates doesn't move a fixed position child. | |
| 7703 // | |
| 7704 // + root | |
| 7705 // + container | |
| 7706 // + scroller | |
| 7707 // + fixed | |
| 7708 // | |
| 7709 FakeImplProxy proxy; | |
| 7710 TestSharedBitmapManager shared_bitmap_manager; | |
| 7711 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 7712 host_impl.CreatePendingTree(); | |
| 7713 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); | |
| 7714 scoped_ptr<LayerImpl> container = | |
| 7715 LayerImpl::Create(host_impl.active_tree(), 2); | |
| 7716 LayerImpl* container_layer = container.get(); | |
| 7717 scoped_ptr<LayerImpl> scroller = | |
| 7718 LayerImpl::Create(host_impl.active_tree(), 3); | |
| 7719 LayerImpl* scroll_layer = scroller.get(); | |
| 7720 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); | |
| 7721 LayerImpl* fixed_layer = fixed.get(); | |
| 7722 | |
| 7723 container->SetIsContainerForFixedPositionLayers(true); | |
| 7724 | |
| 7725 LayerPositionConstraint constraint; | |
| 7726 constraint.set_is_fixed_position(true); | |
| 7727 fixed->SetPositionConstraint(constraint); | |
| 7728 | |
| 7729 scroller->SetScrollClipLayer(container->id()); | |
| 7730 | |
| 7731 gfx::Transform identity_transform; | |
| 7732 gfx::Transform container_transform; | |
| 7733 container_transform.Translate3d(10.0, 20.0, 0.0); | |
| 7734 gfx::Vector2dF container_offset = container_transform.To2dTranslation(); | |
| 7735 | |
| 7736 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), | |
| 7737 gfx::PointF(), gfx::Size(50, 50), true, false, | |
| 7738 true); | |
| 7739 SetLayerPropertiesForTesting(container.get(), container_transform, | |
| 7740 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), | |
| 7741 true, false, false); | |
| 7742 SetLayerPropertiesForTesting(scroller.get(), identity_transform, | |
| 7743 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), | |
| 7744 true, false, false); | |
| 7745 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), | |
| 7746 gfx::PointF(), gfx::Size(50, 50), true, false, | |
| 7747 false); | |
| 7748 | |
| 7749 scroller->AddChild(fixed.Pass()); | |
| 7750 container->AddChild(scroller.Pass()); | |
| 7751 root->AddChild(container.Pass()); | |
| 7752 | |
| 7753 // Rounded to integers already. | |
| 7754 { | |
| 7755 gfx::Vector2dF scroll_delta(3.0, 5.0); | |
| 7756 scroll_layer->SetScrollDelta(scroll_delta); | |
| 7757 | |
| 7758 LayerImplList render_surface_layer_list; | |
| 7759 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 7760 root.get(), root->bounds(), &render_surface_layer_list); | |
| 7761 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 7762 | |
| 7763 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 7764 container_layer->draw_properties().screen_space_transform, | |
| 7765 fixed_layer->draw_properties().screen_space_transform); | |
| 7766 EXPECT_VECTOR_EQ( | |
| 7767 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), | |
| 7768 container_offset); | |
| 7769 EXPECT_VECTOR_EQ(scroll_layer->draw_properties() | |
| 7770 .screen_space_transform.To2dTranslation(), | |
| 7771 container_offset - scroll_delta); | |
| 7772 } | |
| 7773 | |
| 7774 // Scroll delta requiring rounding. | |
| 7775 { | |
| 7776 gfx::Vector2dF scroll_delta(4.1f, 8.1f); | |
| 7777 scroll_layer->SetScrollDelta(scroll_delta); | |
| 7778 | |
| 7779 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); | |
| 7780 | |
| 7781 LayerImplList render_surface_layer_list; | |
| 7782 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 7783 root.get(), root->bounds(), &render_surface_layer_list); | |
| 7784 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 7785 | |
| 7786 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 7787 container_layer->draw_properties().screen_space_transform, | |
| 7788 fixed_layer->draw_properties().screen_space_transform); | |
| 7789 EXPECT_VECTOR_EQ( | |
| 7790 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), | |
| 7791 container_offset); | |
| 7792 EXPECT_VECTOR_EQ(scroll_layer->draw_properties() | |
| 7793 .screen_space_transform.To2dTranslation(), | |
| 7794 container_offset - rounded_scroll_delta); | |
| 7795 } | |
| 7796 | |
| 7797 // Scale is applied earlier in the tree. | |
| 7798 { | |
| 7799 gfx::Transform scaled_container_transform = container_transform; | |
| 7800 scaled_container_transform.Scale3d(3.0, 3.0, 1.0); | |
| 7801 container_layer->SetTransform(scaled_container_transform); | |
| 7802 | |
| 7803 gfx::Vector2dF scroll_delta(4.5f, 8.5f); | |
| 7804 scroll_layer->SetScrollDelta(scroll_delta); | |
| 7805 | |
| 7806 LayerImplList render_surface_layer_list; | |
| 7807 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 7808 root.get(), root->bounds(), &render_surface_layer_list); | |
| 7809 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 7810 | |
| 7811 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 7812 container_layer->draw_properties().screen_space_transform, | |
| 7813 fixed_layer->draw_properties().screen_space_transform); | |
| 7814 EXPECT_VECTOR_EQ( | |
| 7815 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), | |
| 7816 container_offset); | |
| 7817 | |
| 7818 container_layer->SetTransform(container_transform); | |
| 7819 } | |
| 7820 | |
| 7821 // Scale is applied on the scroll layer itself. | |
| 7822 { | |
| 7823 gfx::Transform scale_transform; | |
| 7824 scale_transform.Scale3d(3.0, 3.0, 1.0); | |
| 7825 scroll_layer->SetTransform(scale_transform); | |
| 7826 | |
| 7827 gfx::Vector2dF scroll_delta(4.5f, 8.5f); | |
| 7828 scroll_layer->SetScrollDelta(scroll_delta); | |
| 7829 | |
| 7830 LayerImplList render_surface_layer_list; | |
| 7831 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 7832 root.get(), root->bounds(), &render_surface_layer_list); | |
| 7833 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 7834 | |
| 7835 EXPECT_VECTOR_EQ( | |
| 7836 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), | |
| 7837 container_offset); | |
| 7838 | |
| 7839 scroll_layer->SetTransform(identity_transform); | |
| 7840 } | |
| 7841 } | |
| 7842 | |
| 7843 TEST_F(LayerTreeHostCommonTest, | |
| 7844 ScrollCompensationMainScrollOffsetFractionalPart) { | |
| 7845 // This test verifies that a scrolling layer that has fractional scroll offset | |
| 7846 // from main doesn't move a fixed position child. | |
| 7847 // | |
| 7848 // + root | |
| 7849 // + container | |
| 7850 // + scroller | |
| 7851 // + fixed | |
| 7852 // | |
| 7853 FakeImplProxy proxy; | |
| 7854 TestSharedBitmapManager shared_bitmap_manager; | |
| 7855 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 7856 host_impl.CreatePendingTree(); | |
| 7857 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); | |
| 7858 scoped_ptr<LayerImpl> container = | |
| 7859 LayerImpl::Create(host_impl.active_tree(), 2); | |
| 7860 LayerImpl* container_layer = container.get(); | |
| 7861 scoped_ptr<LayerImpl> scroller = | |
| 7862 LayerImpl::Create(host_impl.active_tree(), 3); | |
| 7863 LayerImpl* scroll_layer = scroller.get(); | |
| 7864 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); | |
| 7865 LayerImpl* fixed_layer = fixed.get(); | |
| 7866 | |
| 7867 container->SetIsContainerForFixedPositionLayers(true); | |
| 7868 | |
| 7869 LayerPositionConstraint constraint; | |
| 7870 constraint.set_is_fixed_position(true); | |
| 7871 fixed->SetPositionConstraint(constraint); | |
| 7872 | |
| 7873 scroller->SetScrollClipLayer(container->id()); | |
| 7874 | |
| 7875 gfx::Transform identity_transform; | |
| 7876 gfx::Transform container_transform; | |
| 7877 container_transform.Translate3d(10.0, 20.0, 0.0); | |
| 7878 gfx::Vector2dF container_offset = container_transform.To2dTranslation(); | |
| 7879 | |
| 7880 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), | |
| 7881 gfx::PointF(), gfx::Size(50, 50), true, false, | |
| 7882 true); | |
| 7883 SetLayerPropertiesForTesting(container.get(), container_transform, | |
| 7884 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), | |
| 7885 true, false, false); | |
| 7886 SetLayerPropertiesForTesting(scroller.get(), identity_transform, | |
| 7887 gfx::Point3F(), gfx::PointF(0.0, 0.0), | |
| 7888 gfx::Size(30, 30), true, false, false); | |
| 7889 | |
| 7890 gfx::ScrollOffset scroll_offset(3.3, 4.2); | |
| 7891 gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f); | |
| 7892 gfx::Vector2dF scroll_delta(0.1f, 0.4f); | |
| 7893 // Blink only uses the integer part of the scroll_offset for fixed | |
| 7894 // position layer. | |
| 7895 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), | |
| 7896 gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true, | |
| 7897 false, false); | |
| 7898 scroll_layer->PushScrollOffsetFromMainThread(scroll_offset); | |
| 7899 scroll_layer->SetScrollDelta(scroll_delta); | |
| 7900 scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part); | |
| 7901 | |
| 7902 scroller->AddChild(fixed.Pass()); | |
| 7903 container->AddChild(scroller.Pass()); | |
| 7904 root->AddChild(container.Pass()); | |
| 7905 | |
| 7906 LayerImplList render_surface_layer_list; | |
| 7907 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 7908 root.get(), root->bounds(), &render_surface_layer_list); | |
| 7909 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 7910 | |
| 7911 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 7912 container_layer->draw_properties().screen_space_transform, | |
| 7913 fixed_layer->draw_properties().screen_space_transform); | |
| 7914 EXPECT_VECTOR_EQ( | |
| 7915 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), | |
| 7916 container_offset); | |
| 7917 | |
| 7918 gfx::ScrollOffset effective_scroll_offset = | |
| 7919 ScrollOffsetWithDelta(scroll_offset, scroll_delta); | |
| 7920 gfx::Vector2d rounded_effective_scroll_offset = | |
| 7921 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset)); | |
| 7922 EXPECT_VECTOR_EQ( | |
| 7923 scroll_layer->draw_properties().screen_space_transform.To2dTranslation(), | |
| 7924 container_offset - rounded_effective_scroll_offset); | |
| 7925 } | |
| 7926 | |
| 7927 class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { | |
| 7928 public: | |
| 7929 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( | |
| 7930 LayerTreeImpl* tree_impl, | |
| 7931 int id) { | |
| 7932 return make_scoped_ptr( | |
| 7933 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); | |
| 7934 } | |
| 7935 | |
| 7936 ~AnimationScaleFactorTrackingLayerImpl() override {} | |
| 7937 | |
| 7938 private: | |
| 7939 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, | |
| 7940 int id) | |
| 7941 : LayerImpl(tree_impl, id) { | |
| 7942 SetDrawsContent(true); | |
| 7943 } | |
| 7944 }; | |
| 7945 | |
| 7946 TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { | |
| 7947 FakeImplProxy proxy; | |
| 7948 TestSharedBitmapManager shared_bitmap_manager; | |
| 7949 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 7950 gfx::Transform identity_matrix; | |
| 7951 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = | |
| 7952 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); | |
| 7953 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = | |
| 7954 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); | |
| 7955 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child = | |
| 7956 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); | |
| 7957 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = | |
| 7958 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); | |
| 7959 | |
| 7960 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); | |
| 7961 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); | |
| 7962 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); | |
| 7963 | |
| 7964 child->AddChild(grand_child.Pass()); | |
| 7965 parent->AddChild(child.Pass()); | |
| 7966 grand_parent->AddChild(parent.Pass()); | |
| 7967 | |
| 7968 SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix, | |
| 7969 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), | |
| 7970 true, false, true); | |
| 7971 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), | |
| 7972 gfx::PointF(), gfx::Size(1, 2), true, false, | |
| 7973 false); | |
| 7974 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), | |
| 7975 gfx::PointF(), gfx::Size(1, 2), true, false, | |
| 7976 false); | |
| 7977 | |
| 7978 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(), | |
| 7979 gfx::PointF(), gfx::Size(1, 2), true, false, | |
| 7980 false); | |
| 7981 | |
| 7982 ExecuteCalculateDrawProperties(grand_parent.get()); | |
| 7983 | |
| 7984 // No layers have animations. | |
| 7985 EXPECT_EQ(0.f, | |
| 7986 grand_parent->draw_properties().maximum_animation_contents_scale); | |
| 7987 EXPECT_EQ(0.f, | |
| 7988 parent_raw->draw_properties().maximum_animation_contents_scale); | |
| 7989 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); | |
| 7990 EXPECT_EQ( | |
| 7991 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); | |
| 7992 | |
| 7993 TransformOperations translation; | |
| 7994 translation.AppendTranslate(1.f, 2.f, 3.f); | |
| 7995 | |
| 7996 AddAnimatedTransformToLayer( | |
| 7997 parent_raw, 1.0, TransformOperations(), translation); | |
| 7998 | |
| 7999 // No layers have scale-affecting animations. | |
| 8000 EXPECT_EQ(0.f, | |
| 8001 grand_parent->draw_properties().maximum_animation_contents_scale); | |
| 8002 EXPECT_EQ(0.f, | |
| 8003 parent_raw->draw_properties().maximum_animation_contents_scale); | |
| 8004 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8005 EXPECT_EQ( | |
| 8006 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8007 | |
| 8008 TransformOperations scale; | |
| 8009 scale.AppendScale(5.f, 4.f, 3.f); | |
| 8010 | |
| 8011 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale); | |
| 8012 ExecuteCalculateDrawProperties(grand_parent.get()); | |
| 8013 | |
| 8014 // Only |child| has a scale-affecting animation. | |
| 8015 EXPECT_EQ(0.f, | |
| 8016 grand_parent->draw_properties().maximum_animation_contents_scale); | |
| 8017 EXPECT_EQ(0.f, | |
| 8018 parent_raw->draw_properties().maximum_animation_contents_scale); | |
| 8019 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8020 EXPECT_EQ( | |
| 8021 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8022 | |
| 8023 AddAnimatedTransformToLayer( | |
| 8024 grand_parent.get(), 1.0, TransformOperations(), scale); | |
| 8025 ExecuteCalculateDrawProperties(grand_parent.get()); | |
| 8026 | |
| 8027 // |grand_parent| and |child| have scale-affecting animations. | |
| 8028 EXPECT_EQ(5.f, | |
| 8029 grand_parent->draw_properties().maximum_animation_contents_scale); | |
| 8030 EXPECT_EQ(5.f, | |
| 8031 parent_raw->draw_properties().maximum_animation_contents_scale); | |
| 8032 // We don't support combining animated scales from two nodes; 0.f means | |
| 8033 // that the maximum scale could not be computed. | |
| 8034 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8035 EXPECT_EQ( | |
| 8036 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8037 | |
| 8038 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); | |
| 8039 ExecuteCalculateDrawProperties(grand_parent.get()); | |
| 8040 | |
| 8041 // |grand_parent|, |parent|, and |child| have scale-affecting animations. | |
| 8042 EXPECT_EQ(5.f, | |
| 8043 grand_parent->draw_properties().maximum_animation_contents_scale); | |
| 8044 EXPECT_EQ(0.f, | |
| 8045 parent_raw->draw_properties().maximum_animation_contents_scale); | |
| 8046 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8047 EXPECT_EQ( | |
| 8048 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8049 | |
| 8050 grand_parent->layer_animation_controller()->AbortAnimations( | |
| 8051 Animation::TRANSFORM); | |
| 8052 parent_raw->layer_animation_controller()->AbortAnimations( | |
| 8053 Animation::TRANSFORM); | |
| 8054 child_raw->layer_animation_controller()->AbortAnimations( | |
| 8055 Animation::TRANSFORM); | |
| 8056 | |
| 8057 TransformOperations perspective; | |
| 8058 perspective.AppendPerspective(10.f); | |
| 8059 | |
| 8060 AddAnimatedTransformToLayer( | |
| 8061 child_raw, 1.0, TransformOperations(), perspective); | |
| 8062 ExecuteCalculateDrawProperties(grand_parent.get()); | |
| 8063 | |
| 8064 // |child| has a scale-affecting animation but computing the maximum of this | |
| 8065 // animation is not supported. | |
| 8066 EXPECT_EQ(0.f, | |
| 8067 grand_parent->draw_properties().maximum_animation_contents_scale); | |
| 8068 EXPECT_EQ(0.f, | |
| 8069 parent_raw->draw_properties().maximum_animation_contents_scale); | |
| 8070 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8071 EXPECT_EQ( | |
| 8072 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8073 | |
| 8074 child_raw->layer_animation_controller()->AbortAnimations( | |
| 8075 Animation::TRANSFORM); | |
| 8076 | |
| 8077 gfx::Transform scale_matrix; | |
| 8078 scale_matrix.Scale(1.f, 2.f); | |
| 8079 grand_parent->SetTransform(scale_matrix); | |
| 8080 parent_raw->SetTransform(scale_matrix); | |
| 8081 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); | |
| 8082 ExecuteCalculateDrawProperties(grand_parent.get()); | |
| 8083 | |
| 8084 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale | |
| 8085 // animation with maximum scale 5.f. | |
| 8086 EXPECT_EQ(0.f, | |
| 8087 grand_parent->draw_properties().maximum_animation_contents_scale); | |
| 8088 EXPECT_EQ(10.f, | |
| 8089 parent_raw->draw_properties().maximum_animation_contents_scale); | |
| 8090 EXPECT_EQ(10.f, | |
| 8091 child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8092 EXPECT_EQ( | |
| 8093 10.f, | |
| 8094 grand_child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8095 | |
| 8096 gfx::Transform perspective_matrix; | |
| 8097 perspective_matrix.ApplyPerspectiveDepth(2.f); | |
| 8098 child_raw->SetTransform(perspective_matrix); | |
| 8099 ExecuteCalculateDrawProperties(grand_parent.get()); | |
| 8100 | |
| 8101 // |child| has a transform that's neither a translation nor a scale. | |
| 8102 EXPECT_EQ(0.f, | |
| 8103 grand_parent->draw_properties().maximum_animation_contents_scale); | |
| 8104 EXPECT_EQ(10.f, | |
| 8105 parent_raw->draw_properties().maximum_animation_contents_scale); | |
| 8106 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8107 EXPECT_EQ( | |
| 8108 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8109 | |
| 8110 parent_raw->SetTransform(perspective_matrix); | |
| 8111 ExecuteCalculateDrawProperties(grand_parent.get()); | |
| 8112 | |
| 8113 // |parent| and |child| have transforms that are neither translations nor | |
| 8114 // scales. | |
| 8115 EXPECT_EQ(0.f, | |
| 8116 grand_parent->draw_properties().maximum_animation_contents_scale); | |
| 8117 EXPECT_EQ(0.f, | |
| 8118 parent_raw->draw_properties().maximum_animation_contents_scale); | |
| 8119 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8120 EXPECT_EQ( | |
| 8121 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8122 | |
| 8123 parent_raw->SetTransform(identity_matrix); | |
| 8124 child_raw->SetTransform(identity_matrix); | |
| 8125 grand_parent->SetTransform(perspective_matrix); | |
| 8126 | |
| 8127 ExecuteCalculateDrawProperties(grand_parent.get()); | |
| 8128 | |
| 8129 // |grand_parent| has a transform that's neither a translation nor a scale. | |
| 8130 EXPECT_EQ(0.f, | |
| 8131 grand_parent->draw_properties().maximum_animation_contents_scale); | |
| 8132 EXPECT_EQ(0.f, | |
| 8133 parent_raw->draw_properties().maximum_animation_contents_scale); | |
| 8134 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8135 EXPECT_EQ( | |
| 8136 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); | |
| 8137 } | |
| 8138 | |
| 8139 static int membership_id(LayerImpl* layer) { | |
| 8140 return layer->draw_properties().last_drawn_render_surface_layer_list_id; | |
| 8141 } | |
| 8142 | |
| 8143 static void GatherDrawnLayers(LayerImplList* rsll, | |
| 8144 std::set<LayerImpl*>* drawn_layers) { | |
| 8145 for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll), | |
| 8146 end = LayerIterator<LayerImpl>::End(rsll); | |
| 8147 it != end; | |
| 8148 ++it) { | |
| 8149 LayerImpl* layer = *it; | |
| 8150 if (it.represents_itself()) | |
| 8151 drawn_layers->insert(layer); | |
| 8152 | |
| 8153 if (!it.represents_contributing_render_surface()) | |
| 8154 continue; | |
| 8155 | |
| 8156 if (layer->mask_layer()) | |
| 8157 drawn_layers->insert(layer->mask_layer()); | |
| 8158 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) | |
| 8159 drawn_layers->insert(layer->replica_layer()->mask_layer()); | |
| 8160 } | |
| 8161 } | |
| 8162 | |
| 8163 TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { | |
| 8164 FakeImplProxy proxy; | |
| 8165 TestSharedBitmapManager shared_bitmap_manager; | |
| 8166 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 8167 gfx::Transform identity_matrix; | |
| 8168 | |
| 8169 scoped_ptr<LayerImpl> grand_parent = | |
| 8170 LayerImpl::Create(host_impl.active_tree(), 1); | |
| 8171 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3); | |
| 8172 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5); | |
| 8173 scoped_ptr<LayerImpl> grand_child1 = | |
| 8174 LayerImpl::Create(host_impl.active_tree(), 7); | |
| 8175 scoped_ptr<LayerImpl> grand_child2 = | |
| 8176 LayerImpl::Create(host_impl.active_tree(), 9); | |
| 8177 | |
| 8178 LayerImpl* grand_parent_raw = grand_parent.get(); | |
| 8179 LayerImpl* parent_raw = parent.get(); | |
| 8180 LayerImpl* child_raw = child.get(); | |
| 8181 LayerImpl* grand_child1_raw = grand_child1.get(); | |
| 8182 LayerImpl* grand_child2_raw = grand_child2.get(); | |
| 8183 | |
| 8184 child->AddChild(grand_child1.Pass()); | |
| 8185 child->AddChild(grand_child2.Pass()); | |
| 8186 parent->AddChild(child.Pass()); | |
| 8187 grand_parent->AddChild(parent.Pass()); | |
| 8188 | |
| 8189 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix, | |
| 8190 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), | |
| 8191 true, false, true); | |
| 8192 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), | |
| 8193 gfx::PointF(), gfx::Size(1, 2), true, false, | |
| 8194 false); | |
| 8195 | |
| 8196 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), | |
| 8197 gfx::PointF(), gfx::Size(1, 2), true, false, | |
| 8198 false); | |
| 8199 | |
| 8200 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix, | |
| 8201 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), | |
| 8202 true, false, false); | |
| 8203 | |
| 8204 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix, | |
| 8205 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), | |
| 8206 true, false, false); | |
| 8207 | |
| 8208 // Start with nothing being drawn. | |
| 8209 ExecuteCalculateDrawProperties(grand_parent_raw); | |
| 8210 int member_id = render_surface_layer_list_count(); | |
| 8211 | |
| 8212 EXPECT_NE(member_id, membership_id(grand_parent_raw)); | |
| 8213 EXPECT_NE(member_id, membership_id(parent_raw)); | |
| 8214 EXPECT_NE(member_id, membership_id(child_raw)); | |
| 8215 EXPECT_NE(member_id, membership_id(grand_child1_raw)); | |
| 8216 EXPECT_NE(member_id, membership_id(grand_child2_raw)); | |
| 8217 | |
| 8218 std::set<LayerImpl*> expected; | |
| 8219 std::set<LayerImpl*> actual; | |
| 8220 GatherDrawnLayers(render_surface_layer_list_impl(), &actual); | |
| 8221 EXPECT_EQ(expected, actual); | |
| 8222 | |
| 8223 // If we force render surface, but none of the layers are in the layer list, | |
| 8224 // then this layer should not appear in RSLL. | |
| 8225 grand_child1_raw->SetHasRenderSurface(true); | |
| 8226 | |
| 8227 ExecuteCalculateDrawProperties(grand_parent_raw); | |
| 8228 member_id = render_surface_layer_list_count(); | |
| 8229 | |
| 8230 EXPECT_NE(member_id, membership_id(grand_parent_raw)); | |
| 8231 EXPECT_NE(member_id, membership_id(parent_raw)); | |
| 8232 EXPECT_NE(member_id, membership_id(child_raw)); | |
| 8233 EXPECT_NE(member_id, membership_id(grand_child1_raw)); | |
| 8234 EXPECT_NE(member_id, membership_id(grand_child2_raw)); | |
| 8235 | |
| 8236 expected.clear(); | |
| 8237 actual.clear(); | |
| 8238 GatherDrawnLayers(render_surface_layer_list_impl(), &actual); | |
| 8239 EXPECT_EQ(expected, actual); | |
| 8240 | |
| 8241 // However, if we say that this layer also draws content, it will appear in | |
| 8242 // RSLL. | |
| 8243 grand_child1_raw->SetDrawsContent(true); | |
| 8244 | |
| 8245 ExecuteCalculateDrawProperties(grand_parent_raw); | |
| 8246 member_id = render_surface_layer_list_count(); | |
| 8247 | |
| 8248 EXPECT_NE(member_id, membership_id(grand_parent_raw)); | |
| 8249 EXPECT_NE(member_id, membership_id(parent_raw)); | |
| 8250 EXPECT_NE(member_id, membership_id(child_raw)); | |
| 8251 EXPECT_EQ(member_id, membership_id(grand_child1_raw)); | |
| 8252 EXPECT_NE(member_id, membership_id(grand_child2_raw)); | |
| 8253 | |
| 8254 expected.clear(); | |
| 8255 expected.insert(grand_child1_raw); | |
| 8256 | |
| 8257 actual.clear(); | |
| 8258 GatherDrawnLayers(render_surface_layer_list_impl(), &actual); | |
| 8259 EXPECT_EQ(expected, actual); | |
| 8260 | |
| 8261 // Now child is forced to have a render surface, and one if its children draws | |
| 8262 // content. | |
| 8263 grand_child1_raw->SetDrawsContent(false); | |
| 8264 grand_child1_raw->SetHasRenderSurface(false); | |
| 8265 child_raw->SetHasRenderSurface(true); | |
| 8266 grand_child2_raw->SetDrawsContent(true); | |
| 8267 | |
| 8268 ExecuteCalculateDrawProperties(grand_parent_raw); | |
| 8269 member_id = render_surface_layer_list_count(); | |
| 8270 | |
| 8271 EXPECT_NE(member_id, membership_id(grand_parent_raw)); | |
| 8272 EXPECT_NE(member_id, membership_id(parent_raw)); | |
| 8273 EXPECT_NE(member_id, membership_id(child_raw)); | |
| 8274 EXPECT_NE(member_id, membership_id(grand_child1_raw)); | |
| 8275 EXPECT_EQ(member_id, membership_id(grand_child2_raw)); | |
| 8276 | |
| 8277 expected.clear(); | |
| 8278 expected.insert(grand_child2_raw); | |
| 8279 | |
| 8280 actual.clear(); | |
| 8281 GatherDrawnLayers(render_surface_layer_list_impl(), &actual); | |
| 8282 EXPECT_EQ(expected, actual); | |
| 8283 | |
| 8284 // Add a mask layer to child. | |
| 8285 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass()); | |
| 8286 | |
| 8287 ExecuteCalculateDrawProperties(grand_parent_raw); | |
| 8288 member_id = render_surface_layer_list_count(); | |
| 8289 | |
| 8290 EXPECT_NE(member_id, membership_id(grand_parent_raw)); | |
| 8291 EXPECT_NE(member_id, membership_id(parent_raw)); | |
| 8292 EXPECT_NE(member_id, membership_id(child_raw)); | |
| 8293 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); | |
| 8294 EXPECT_NE(member_id, membership_id(grand_child1_raw)); | |
| 8295 EXPECT_EQ(member_id, membership_id(grand_child2_raw)); | |
| 8296 | |
| 8297 expected.clear(); | |
| 8298 expected.insert(grand_child2_raw); | |
| 8299 expected.insert(child_raw->mask_layer()); | |
| 8300 | |
| 8301 expected.clear(); | |
| 8302 expected.insert(grand_child2_raw); | |
| 8303 expected.insert(child_raw->mask_layer()); | |
| 8304 | |
| 8305 actual.clear(); | |
| 8306 GatherDrawnLayers(render_surface_layer_list_impl(), &actual); | |
| 8307 EXPECT_EQ(expected, actual); | |
| 8308 | |
| 8309 // Add replica mask layer. | |
| 8310 scoped_ptr<LayerImpl> replica_layer = | |
| 8311 LayerImpl::Create(host_impl.active_tree(), 20); | |
| 8312 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21)); | |
| 8313 child_raw->SetReplicaLayer(replica_layer.Pass()); | |
| 8314 | |
| 8315 ExecuteCalculateDrawProperties(grand_parent_raw); | |
| 8316 member_id = render_surface_layer_list_count(); | |
| 8317 | |
| 8318 EXPECT_NE(member_id, membership_id(grand_parent_raw)); | |
| 8319 EXPECT_NE(member_id, membership_id(parent_raw)); | |
| 8320 EXPECT_NE(member_id, membership_id(child_raw)); | |
| 8321 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); | |
| 8322 EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer())); | |
| 8323 EXPECT_NE(member_id, membership_id(grand_child1_raw)); | |
| 8324 EXPECT_EQ(member_id, membership_id(grand_child2_raw)); | |
| 8325 | |
| 8326 expected.clear(); | |
| 8327 expected.insert(grand_child2_raw); | |
| 8328 expected.insert(child_raw->mask_layer()); | |
| 8329 expected.insert(child_raw->replica_layer()->mask_layer()); | |
| 8330 | |
| 8331 actual.clear(); | |
| 8332 GatherDrawnLayers(render_surface_layer_list_impl(), &actual); | |
| 8333 EXPECT_EQ(expected, actual); | |
| 8334 | |
| 8335 child_raw->TakeReplicaLayer(); | |
| 8336 | |
| 8337 // With nothing drawing, we should have no layers. | |
| 8338 grand_child2_raw->SetDrawsContent(false); | |
| 8339 | |
| 8340 ExecuteCalculateDrawProperties(grand_parent_raw); | |
| 8341 member_id = render_surface_layer_list_count(); | |
| 8342 | |
| 8343 EXPECT_NE(member_id, membership_id(grand_parent_raw)); | |
| 8344 EXPECT_NE(member_id, membership_id(parent_raw)); | |
| 8345 EXPECT_NE(member_id, membership_id(child_raw)); | |
| 8346 EXPECT_NE(member_id, membership_id(child_raw->mask_layer())); | |
| 8347 EXPECT_NE(member_id, membership_id(grand_child1_raw)); | |
| 8348 EXPECT_NE(member_id, membership_id(grand_child2_raw)); | |
| 8349 | |
| 8350 expected.clear(); | |
| 8351 actual.clear(); | |
| 8352 GatherDrawnLayers(render_surface_layer_list_impl(), &actual); | |
| 8353 EXPECT_EQ(expected, actual); | |
| 8354 | |
| 8355 // Child itself draws means that we should have the child and the mask in the | |
| 8356 // list. | |
| 8357 child_raw->SetDrawsContent(true); | |
| 8358 | |
| 8359 ExecuteCalculateDrawProperties(grand_parent_raw); | |
| 8360 member_id = render_surface_layer_list_count(); | |
| 8361 | |
| 8362 EXPECT_NE(member_id, membership_id(grand_parent_raw)); | |
| 8363 EXPECT_NE(member_id, membership_id(parent_raw)); | |
| 8364 EXPECT_EQ(member_id, membership_id(child_raw)); | |
| 8365 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); | |
| 8366 EXPECT_NE(member_id, membership_id(grand_child1_raw)); | |
| 8367 EXPECT_NE(member_id, membership_id(grand_child2_raw)); | |
| 8368 | |
| 8369 expected.clear(); | |
| 8370 expected.insert(child_raw); | |
| 8371 expected.insert(child_raw->mask_layer()); | |
| 8372 actual.clear(); | |
| 8373 GatherDrawnLayers(render_surface_layer_list_impl(), &actual); | |
| 8374 EXPECT_EQ(expected, actual); | |
| 8375 | |
| 8376 child_raw->TakeMaskLayer(); | |
| 8377 | |
| 8378 // Now everyone's a member! | |
| 8379 grand_parent_raw->SetDrawsContent(true); | |
| 8380 parent_raw->SetDrawsContent(true); | |
| 8381 child_raw->SetDrawsContent(true); | |
| 8382 grand_child1_raw->SetDrawsContent(true); | |
| 8383 grand_child2_raw->SetDrawsContent(true); | |
| 8384 | |
| 8385 ExecuteCalculateDrawProperties(grand_parent_raw); | |
| 8386 member_id = render_surface_layer_list_count(); | |
| 8387 | |
| 8388 EXPECT_EQ(member_id, membership_id(grand_parent_raw)); | |
| 8389 EXPECT_EQ(member_id, membership_id(parent_raw)); | |
| 8390 EXPECT_EQ(member_id, membership_id(child_raw)); | |
| 8391 EXPECT_EQ(member_id, membership_id(grand_child1_raw)); | |
| 8392 EXPECT_EQ(member_id, membership_id(grand_child2_raw)); | |
| 8393 | |
| 8394 expected.clear(); | |
| 8395 expected.insert(grand_parent_raw); | |
| 8396 expected.insert(parent_raw); | |
| 8397 expected.insert(child_raw); | |
| 8398 expected.insert(grand_child1_raw); | |
| 8399 expected.insert(grand_child2_raw); | |
| 8400 | |
| 8401 actual.clear(); | |
| 8402 GatherDrawnLayers(render_surface_layer_list_impl(), &actual); | |
| 8403 EXPECT_EQ(expected, actual); | |
| 8404 } | |
| 8405 | |
| 8406 TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { | |
| 8407 FakeImplProxy proxy; | |
| 8408 TestSharedBitmapManager shared_bitmap_manager; | |
| 8409 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 8410 | |
| 8411 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); | |
| 8412 LayerImpl* root_layer = root.get(); | |
| 8413 scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2); | |
| 8414 LayerImpl* child1_layer = child1.get(); | |
| 8415 scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3); | |
| 8416 LayerImpl* child2_layer = child2.get(); | |
| 8417 | |
| 8418 root->AddChild(child1.Pass()); | |
| 8419 root->AddChild(child2.Pass()); | |
| 8420 root->SetHasRenderSurface(true); | |
| 8421 | |
| 8422 gfx::Transform identity_matrix, scale_transform_child1, | |
| 8423 scale_transform_child2; | |
| 8424 scale_transform_child1.Scale(2, 3); | |
| 8425 scale_transform_child2.Scale(4, 5); | |
| 8426 | |
| 8427 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(), | |
| 8428 gfx::PointF(), gfx::Size(1, 1), true, false, | |
| 8429 true); | |
| 8430 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1, | |
| 8431 gfx::Point3F(), gfx::PointF(), gfx::Size(), true, | |
| 8432 false, false); | |
| 8433 | |
| 8434 child1_layer->SetMaskLayer( | |
| 8435 LayerImpl::Create(host_impl.active_tree(), 4).Pass()); | |
| 8436 | |
| 8437 scoped_ptr<LayerImpl> replica_layer = | |
| 8438 LayerImpl::Create(host_impl.active_tree(), 5); | |
| 8439 replica_layer->SetHasRenderSurface(true); | |
| 8440 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); | |
| 8441 child1_layer->SetReplicaLayer(replica_layer.Pass()); | |
| 8442 child1_layer->SetHasRenderSurface(true); | |
| 8443 | |
| 8444 ExecuteCalculateDrawProperties(root_layer); | |
| 8445 | |
| 8446 TransformOperations scale; | |
| 8447 scale.AppendScale(5.f, 8.f, 3.f); | |
| 8448 | |
| 8449 AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale); | |
| 8450 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2, | |
| 8451 gfx::Point3F(), gfx::PointF(), gfx::Size(), true, | |
| 8452 false, false); | |
| 8453 | |
| 8454 ExecuteCalculateDrawProperties(root_layer); | |
| 8455 | |
| 8456 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale); | |
| 8457 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().ideal_contents_scale); | |
| 8458 EXPECT_FLOAT_EQ( | |
| 8459 3.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); | |
| 8460 EXPECT_FLOAT_EQ(3.f, | |
| 8461 child1_layer->replica_layer() | |
| 8462 ->mask_layer() | |
| 8463 ->draw_properties() | |
| 8464 .ideal_contents_scale); | |
| 8465 EXPECT_FLOAT_EQ(5.f, child2_layer->draw_properties().ideal_contents_scale); | |
| 8466 | |
| 8467 EXPECT_FLOAT_EQ( | |
| 8468 0.f, root_layer->draw_properties().maximum_animation_contents_scale); | |
| 8469 EXPECT_FLOAT_EQ( | |
| 8470 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); | |
| 8471 EXPECT_FLOAT_EQ(0.f, | |
| 8472 child1_layer->mask_layer() | |
| 8473 ->draw_properties() | |
| 8474 .maximum_animation_contents_scale); | |
| 8475 EXPECT_FLOAT_EQ(0.f, | |
| 8476 child1_layer->replica_layer() | |
| 8477 ->mask_layer() | |
| 8478 ->draw_properties() | |
| 8479 .maximum_animation_contents_scale); | |
| 8480 EXPECT_FLOAT_EQ( | |
| 8481 8.f, child2_layer->draw_properties().maximum_animation_contents_scale); | |
| 8482 | |
| 8483 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); | |
| 8484 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().page_scale_factor); | |
| 8485 EXPECT_FLOAT_EQ( | |
| 8486 1.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); | |
| 8487 EXPECT_FLOAT_EQ(1.f, | |
| 8488 child1_layer->replica_layer() | |
| 8489 ->mask_layer() | |
| 8490 ->draw_properties() | |
| 8491 .page_scale_factor); | |
| 8492 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().page_scale_factor); | |
| 8493 | |
| 8494 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor); | |
| 8495 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor); | |
| 8496 EXPECT_FLOAT_EQ( | |
| 8497 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); | |
| 8498 EXPECT_FLOAT_EQ(1.f, | |
| 8499 child1_layer->replica_layer() | |
| 8500 ->mask_layer() | |
| 8501 ->draw_properties() | |
| 8502 .device_scale_factor); | |
| 8503 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor); | |
| 8504 | |
| 8505 // Changing page-scale would affect ideal_contents_scale and | |
| 8506 // maximum_animation_contents_scale. | |
| 8507 | |
| 8508 float page_scale_factor = 3.f; | |
| 8509 float device_scale_factor = 1.0f; | |
| 8510 std::vector<LayerImpl*> render_surface_layer_list; | |
| 8511 gfx::Size device_viewport_size = | |
| 8512 gfx::Size(root_layer->bounds().width() * device_scale_factor, | |
| 8513 root_layer->bounds().height() * device_scale_factor); | |
| 8514 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 8515 root_layer, device_viewport_size, &render_surface_layer_list); | |
| 8516 | |
| 8517 inputs.page_scale_factor = page_scale_factor; | |
| 8518 inputs.can_adjust_raster_scales = true; | |
| 8519 inputs.page_scale_application_layer = root_layer; | |
| 8520 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 8521 | |
| 8522 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale); | |
| 8523 EXPECT_FLOAT_EQ(9.f, child1_layer->draw_properties().ideal_contents_scale); | |
| 8524 EXPECT_FLOAT_EQ( | |
| 8525 9.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); | |
| 8526 EXPECT_FLOAT_EQ(9.f, | |
| 8527 child1_layer->replica_layer() | |
| 8528 ->mask_layer() | |
| 8529 ->draw_properties() | |
| 8530 .ideal_contents_scale); | |
| 8531 EXPECT_FLOAT_EQ(15.f, child2_layer->draw_properties().ideal_contents_scale); | |
| 8532 | |
| 8533 EXPECT_FLOAT_EQ( | |
| 8534 0.f, root_layer->draw_properties().maximum_animation_contents_scale); | |
| 8535 EXPECT_FLOAT_EQ( | |
| 8536 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); | |
| 8537 EXPECT_FLOAT_EQ(0.f, | |
| 8538 child1_layer->mask_layer() | |
| 8539 ->draw_properties() | |
| 8540 .maximum_animation_contents_scale); | |
| 8541 EXPECT_FLOAT_EQ(0.f, | |
| 8542 child1_layer->replica_layer() | |
| 8543 ->mask_layer() | |
| 8544 ->draw_properties() | |
| 8545 .maximum_animation_contents_scale); | |
| 8546 EXPECT_FLOAT_EQ( | |
| 8547 24.f, child2_layer->draw_properties().maximum_animation_contents_scale); | |
| 8548 | |
| 8549 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); | |
| 8550 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor); | |
| 8551 EXPECT_FLOAT_EQ( | |
| 8552 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); | |
| 8553 EXPECT_FLOAT_EQ(3.f, | |
| 8554 child1_layer->replica_layer() | |
| 8555 ->mask_layer() | |
| 8556 ->draw_properties() | |
| 8557 .page_scale_factor); | |
| 8558 EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor); | |
| 8559 | |
| 8560 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor); | |
| 8561 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor); | |
| 8562 EXPECT_FLOAT_EQ( | |
| 8563 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); | |
| 8564 EXPECT_FLOAT_EQ(1.f, | |
| 8565 child1_layer->replica_layer() | |
| 8566 ->mask_layer() | |
| 8567 ->draw_properties() | |
| 8568 .device_scale_factor); | |
| 8569 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor); | |
| 8570 | |
| 8571 // Changing device-scale would affect ideal_contents_scale and | |
| 8572 // maximum_animation_contents_scale. | |
| 8573 | |
| 8574 device_scale_factor = 4.0f; | |
| 8575 inputs.device_scale_factor = device_scale_factor; | |
| 8576 inputs.can_adjust_raster_scales = true; | |
| 8577 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 8578 | |
| 8579 EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().ideal_contents_scale); | |
| 8580 EXPECT_FLOAT_EQ(36.f, child1_layer->draw_properties().ideal_contents_scale); | |
| 8581 EXPECT_FLOAT_EQ( | |
| 8582 36.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); | |
| 8583 EXPECT_FLOAT_EQ(36.f, | |
| 8584 child1_layer->replica_layer() | |
| 8585 ->mask_layer() | |
| 8586 ->draw_properties() | |
| 8587 .ideal_contents_scale); | |
| 8588 EXPECT_FLOAT_EQ(60.f, child2_layer->draw_properties().ideal_contents_scale); | |
| 8589 | |
| 8590 EXPECT_FLOAT_EQ( | |
| 8591 0.f, root_layer->draw_properties().maximum_animation_contents_scale); | |
| 8592 EXPECT_FLOAT_EQ( | |
| 8593 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); | |
| 8594 EXPECT_FLOAT_EQ(0.f, | |
| 8595 child1_layer->mask_layer() | |
| 8596 ->draw_properties() | |
| 8597 .maximum_animation_contents_scale); | |
| 8598 EXPECT_FLOAT_EQ(0.f, | |
| 8599 child1_layer->replica_layer() | |
| 8600 ->mask_layer() | |
| 8601 ->draw_properties() | |
| 8602 .maximum_animation_contents_scale); | |
| 8603 EXPECT_FLOAT_EQ( | |
| 8604 96.f, child2_layer->draw_properties().maximum_animation_contents_scale); | |
| 8605 | |
| 8606 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); | |
| 8607 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor); | |
| 8608 EXPECT_FLOAT_EQ( | |
| 8609 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); | |
| 8610 EXPECT_FLOAT_EQ(3.f, | |
| 8611 child1_layer->replica_layer() | |
| 8612 ->mask_layer() | |
| 8613 ->draw_properties() | |
| 8614 .page_scale_factor); | |
| 8615 EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor); | |
| 8616 | |
| 8617 EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().device_scale_factor); | |
| 8618 EXPECT_FLOAT_EQ(4.f, child1_layer->draw_properties().device_scale_factor); | |
| 8619 EXPECT_FLOAT_EQ( | |
| 8620 4.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); | |
| 8621 EXPECT_FLOAT_EQ(4.f, | |
| 8622 child1_layer->replica_layer() | |
| 8623 ->mask_layer() | |
| 8624 ->draw_properties() | |
| 8625 .device_scale_factor); | |
| 8626 EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor); | |
| 8627 } | |
| 8628 | |
| 8629 TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { | |
| 8630 scoped_refptr<Layer> root = Layer::Create(); | |
| 8631 SetLayerPropertiesForTesting(root.get(), | |
| 8632 gfx::Transform(), | |
| 8633 gfx::Point3F(), | |
| 8634 gfx::PointF(), | |
| 8635 gfx::Size(768 / 2, 3000), | |
| 8636 true, | |
| 8637 false); | |
| 8638 root->SetIsDrawable(true); | |
| 8639 | |
| 8640 scoped_refptr<Layer> clip = Layer::Create(); | |
| 8641 SetLayerPropertiesForTesting(clip.get(), | |
| 8642 gfx::Transform(), | |
| 8643 gfx::Point3F(), | |
| 8644 gfx::PointF(), | |
| 8645 gfx::Size(768 / 2, 10000), | |
| 8646 true, | |
| 8647 false); | |
| 8648 clip->SetMasksToBounds(true); | |
| 8649 | |
| 8650 scoped_refptr<Layer> content = Layer::Create(); | |
| 8651 SetLayerPropertiesForTesting(content.get(), | |
| 8652 gfx::Transform(), | |
| 8653 gfx::Point3F(), | |
| 8654 gfx::PointF(), | |
| 8655 gfx::Size(768 / 2, 10000), | |
| 8656 true, | |
| 8657 false); | |
| 8658 content->SetIsDrawable(true); | |
| 8659 content->SetForceRenderSurface(true); | |
| 8660 | |
| 8661 root->AddChild(clip); | |
| 8662 clip->AddChild(content); | |
| 8663 | |
| 8664 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | |
| 8665 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); | |
| 8666 host->SetRootLayer(root); | |
| 8667 | |
| 8668 gfx::Size device_viewport_size(768, 582); | |
| 8669 RenderSurfaceLayerList render_surface_layer_list; | |
| 8670 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 8671 host->root_layer(), device_viewport_size, &render_surface_layer_list); | |
| 8672 inputs.device_scale_factor = 2.f; | |
| 8673 inputs.page_scale_factor = 1.f; | |
| 8674 inputs.page_scale_application_layer = NULL; | |
| 8675 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 8676 | |
| 8677 // Layers in the root render surface have their visible content rect clipped | |
| 8678 // by the viewport. | |
| 8679 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect()); | |
| 8680 | |
| 8681 // Layers drawing to a child render surface should still have their visible | |
| 8682 // content rect clipped by the viewport. | |
| 8683 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect()); | |
| 8684 } | |
| 8685 | |
| 8686 TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { | |
| 8687 FakeImplProxy proxy; | |
| 8688 TestSharedBitmapManager shared_bitmap_manager; | |
| 8689 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); | |
| 8690 | |
| 8691 // Set two layers: the root layer clips it's child, | |
| 8692 // the child draws its content. | |
| 8693 | |
| 8694 gfx::Size root_size = gfx::Size(300, 500); | |
| 8695 | |
| 8696 // Sublayer should be bigger than the root enlarged by bounds_delta. | |
| 8697 gfx::Size sublayer_size = gfx::Size(300, 1000); | |
| 8698 | |
| 8699 // Device viewport accomidated the root and the top controls. | |
| 8700 gfx::Size device_viewport_size = gfx::Size(300, 600); | |
| 8701 gfx::Transform identity_matrix; | |
| 8702 | |
| 8703 host_impl.active_tree()->SetRootLayer( | |
| 8704 LayerImpl::Create(host_impl.active_tree(), 1)); | |
| 8705 | |
| 8706 LayerImpl* root = host_impl.active_tree()->root_layer(); | |
| 8707 SetLayerPropertiesForTesting(root, | |
| 8708 identity_matrix, | |
| 8709 gfx::Point3F(), | |
| 8710 gfx::PointF(), | |
| 8711 root_size, | |
| 8712 false, | |
| 8713 false, | |
| 8714 true); | |
| 8715 | |
| 8716 root->SetContentBounds(root_size); | |
| 8717 root->SetMasksToBounds(true); | |
| 8718 | |
| 8719 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2)); | |
| 8720 | |
| 8721 LayerImpl* sublayer = root->child_at(0); | |
| 8722 SetLayerPropertiesForTesting(sublayer, | |
| 8723 identity_matrix, | |
| 8724 gfx::Point3F(), | |
| 8725 gfx::PointF(), | |
| 8726 sublayer_size, | |
| 8727 false, | |
| 8728 false, | |
| 8729 false); | |
| 8730 | |
| 8731 sublayer->SetContentBounds(sublayer_size); | |
| 8732 sublayer->SetDrawsContent(true); | |
| 8733 | |
| 8734 LayerImplList layer_impl_list; | |
| 8735 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 8736 root, device_viewport_size, &layer_impl_list); | |
| 8737 | |
| 8738 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 8739 | |
| 8740 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_content_rect()); | |
| 8741 | |
| 8742 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); | |
| 8743 | |
| 8744 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 8745 | |
| 8746 gfx::Rect affected_by_delta(0, 0, root_size.width(), | |
| 8747 root_size.height() + 50); | |
| 8748 EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect()); | |
| 8749 } | |
| 8750 | |
| 8751 TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { | |
| 8752 const gfx::Transform identity_matrix; | |
| 8753 scoped_refptr<Layer> root = Layer::Create(); | |
| 8754 scoped_refptr<LayerWithForcedDrawsContent> animated = | |
| 8755 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 8756 | |
| 8757 root->AddChild(animated); | |
| 8758 | |
| 8759 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 8760 host->SetRootLayer(root); | |
| 8761 | |
| 8762 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), | |
| 8763 gfx::PointF(), gfx::Size(100, 100), true, false); | |
| 8764 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(), | |
| 8765 gfx::PointF(), gfx::Size(20, 20), true, false); | |
| 8766 | |
| 8767 root->SetMasksToBounds(true); | |
| 8768 root->SetForceRenderSurface(true); | |
| 8769 animated->SetOpacity(0.f); | |
| 8770 | |
| 8771 AddOpacityTransitionToController(animated->layer_animation_controller(), 10.0, | |
| 8772 0.f, 1.f, false); | |
| 8773 | |
| 8774 ExecuteCalculateDrawProperties(root.get()); | |
| 8775 | |
| 8776 EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty()); | |
| 8777 } | |
| 8778 | |
| 8779 // Verify that having an animated filter (but no current filter, as these | |
| 8780 // are mutually exclusive) correctly creates a render surface. | |
| 8781 TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { | |
| 8782 scoped_refptr<Layer> root = Layer::Create(); | |
| 8783 scoped_refptr<Layer> child = Layer::Create(); | |
| 8784 scoped_refptr<Layer> grandchild = Layer::Create(); | |
| 8785 root->AddChild(child); | |
| 8786 child->AddChild(grandchild); | |
| 8787 | |
| 8788 gfx::Transform identity_transform; | |
| 8789 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), | |
| 8790 gfx::PointF(), gfx::Size(50, 50), true, false); | |
| 8791 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), | |
| 8792 gfx::PointF(), gfx::Size(50, 50), true, false); | |
| 8793 SetLayerPropertiesForTesting(grandchild.get(), identity_transform, | |
| 8794 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), | |
| 8795 true, false); | |
| 8796 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 8797 host->SetRootLayer(root); | |
| 8798 | |
| 8799 AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f); | |
| 8800 | |
| 8801 ExecuteCalculateDrawProperties(root.get()); | |
| 8802 | |
| 8803 EXPECT_TRUE(root->render_surface()); | |
| 8804 EXPECT_TRUE(child->render_surface()); | |
| 8805 EXPECT_FALSE(grandchild->render_surface()); | |
| 8806 | |
| 8807 EXPECT_TRUE(root->filters().IsEmpty()); | |
| 8808 EXPECT_TRUE(child->filters().IsEmpty()); | |
| 8809 EXPECT_TRUE(grandchild->filters().IsEmpty()); | |
| 8810 | |
| 8811 EXPECT_FALSE(root->FilterIsAnimating()); | |
| 8812 EXPECT_TRUE(child->FilterIsAnimating()); | |
| 8813 EXPECT_FALSE(grandchild->FilterIsAnimating()); | |
| 8814 } | |
| 8815 | |
| 8816 // Ensures that the property tree code accounts for offsets between fixed | |
| 8817 // position layers and their respective containers. | |
| 8818 TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { | |
| 8819 scoped_refptr<Layer> root = Layer::Create(); | |
| 8820 scoped_refptr<Layer> child = Layer::Create(); | |
| 8821 scoped_refptr<LayerWithForcedDrawsContent> grandchild = | |
| 8822 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 8823 | |
| 8824 root->AddChild(child); | |
| 8825 child->AddChild(grandchild); | |
| 8826 | |
| 8827 gfx::Transform identity_transform; | |
| 8828 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), | |
| 8829 gfx::PointF(), gfx::Size(50, 50), true, false); | |
| 8830 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), | |
| 8831 gfx::PointF(1000, 1000), gfx::Size(50, 50), true, | |
| 8832 false); | |
| 8833 SetLayerPropertiesForTesting(grandchild.get(), identity_transform, | |
| 8834 gfx::Point3F(), gfx::PointF(-1000, -1000), | |
| 8835 gfx::Size(50, 50), true, false); | |
| 8836 | |
| 8837 root->SetMasksToBounds(true); | |
| 8838 root->SetIsContainerForFixedPositionLayers(true); | |
| 8839 LayerPositionConstraint constraint; | |
| 8840 constraint.set_is_fixed_position(true); | |
| 8841 grandchild->SetPositionConstraint(constraint); | |
| 8842 | |
| 8843 root->SetIsContainerForFixedPositionLayers(true); | |
| 8844 | |
| 8845 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 8846 host->SetRootLayer(root); | |
| 8847 | |
| 8848 ExecuteCalculateDrawProperties(root.get()); | |
| 8849 | |
| 8850 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), | |
| 8851 grandchild->visible_rect_from_property_trees()); | |
| 8852 } | |
| 8853 | |
| 8854 TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) { | |
| 8855 // In the following layer tree, the layer |box|'s render target is |surface|. | |
| 8856 // |surface| also creates a transform node. We want to combine clips for |box| | |
| 8857 // in the space of its target (i.e., |surface|), not its target's target. This | |
| 8858 // test ensures that happens. | |
| 8859 | |
| 8860 gfx::Transform rotate; | |
| 8861 rotate.Rotate(5); | |
| 8862 gfx::Transform identity; | |
| 8863 | |
| 8864 scoped_refptr<Layer> root = Layer::Create(); | |
| 8865 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), | |
| 8866 gfx::PointF(), gfx::Size(2500, 1500), true, | |
| 8867 false); | |
| 8868 | |
| 8869 scoped_refptr<Layer> frame_clip = Layer::Create(); | |
| 8870 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(), | |
| 8871 gfx::PointF(), gfx::Size(2500, 1500), true, | |
| 8872 false); | |
| 8873 frame_clip->SetMasksToBounds(true); | |
| 8874 | |
| 8875 scoped_refptr<Layer> rotated = Layer::Create(); | |
| 8876 SetLayerPropertiesForTesting(rotated.get(), rotate, | |
| 8877 gfx::Point3F(1250, 250, 0), gfx::PointF(), | |
| 8878 gfx::Size(2500, 500), true, false); | |
| 8879 | |
| 8880 scoped_refptr<Layer> surface = Layer::Create(); | |
| 8881 SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(), | |
| 8882 gfx::PointF(), gfx::Size(2500, 500), true, | |
| 8883 false); | |
| 8884 surface->SetOpacity(0.5); | |
| 8885 | |
| 8886 scoped_refptr<LayerWithForcedDrawsContent> container = | |
| 8887 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 8888 SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(), | |
| 8889 gfx::PointF(), gfx::Size(300, 300), true, false); | |
| 8890 | |
| 8891 scoped_refptr<LayerWithForcedDrawsContent> box = | |
| 8892 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 8893 SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(), | |
| 8894 gfx::PointF(), gfx::Size(100, 100), true, false); | |
| 8895 | |
| 8896 root->AddChild(frame_clip); | |
| 8897 frame_clip->AddChild(rotated); | |
| 8898 rotated->AddChild(surface); | |
| 8899 surface->AddChild(container); | |
| 8900 surface->AddChild(box); | |
| 8901 | |
| 8902 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 8903 host->SetRootLayer(root); | |
| 8904 | |
| 8905 ExecuteCalculateDrawProperties(root.get()); | |
| 8906 } | |
| 8907 | |
| 8908 TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) { | |
| 8909 gfx::Transform identity; | |
| 8910 gfx::Transform translate_z; | |
| 8911 translate_z.Translate3d(0, 0, 10); | |
| 8912 | |
| 8913 scoped_refptr<Layer> root = Layer::Create(); | |
| 8914 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), | |
| 8915 gfx::PointF(), gfx::Size(800, 800), true, false); | |
| 8916 root->SetIsContainerForFixedPositionLayers(true); | |
| 8917 | |
| 8918 scoped_refptr<Layer> frame_clip = Layer::Create(); | |
| 8919 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(), | |
| 8920 gfx::PointF(500, 100), gfx::Size(100, 100), true, | |
| 8921 false); | |
| 8922 frame_clip->SetMasksToBounds(true); | |
| 8923 | |
| 8924 scoped_refptr<LayerWithForcedDrawsContent> fixed = | |
| 8925 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 8926 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(), | |
| 8927 gfx::PointF(), gfx::Size(1000, 1000), true, | |
| 8928 false); | |
| 8929 | |
| 8930 LayerPositionConstraint constraint; | |
| 8931 constraint.set_is_fixed_position(true); | |
| 8932 fixed->SetPositionConstraint(constraint); | |
| 8933 | |
| 8934 root->AddChild(frame_clip); | |
| 8935 frame_clip->AddChild(fixed); | |
| 8936 | |
| 8937 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | |
| 8938 host->SetRootLayer(root); | |
| 8939 | |
| 8940 ExecuteCalculateDrawProperties(root.get()); | |
| 8941 | |
| 8942 gfx::Rect expected(0, 0, 100, 100); | |
| 8943 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees()); | |
| 8944 } | |
| 8945 | |
| 8946 } // namespace | |
| 8947 } // namespace cc | |
| OLD | NEW |