OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layers/layer_impl.h" | 5 #include "cc/layers/layer_impl.h" |
6 | 6 |
7 #include "cc/layers/painted_scrollbar_layer_impl.h" | 7 #include "cc/layers/painted_scrollbar_layer_impl.h" |
8 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | 8 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
9 #include "cc/output/filter_operation.h" | 9 #include "cc/output/filter_operation.h" |
10 #include "cc/output/filter_operations.h" | 10 #include "cc/output/filter_operations.h" |
11 #include "cc/test/fake_impl_proxy.h" | 11 #include "cc/test/fake_impl_proxy.h" |
12 #include "cc/test/fake_layer_tree_host_impl.h" | 12 #include "cc/test/fake_layer_tree_host_impl.h" |
13 #include "cc/test/fake_output_surface.h" | 13 #include "cc/test/fake_output_surface.h" |
14 #include "cc/test/geometry_test_utils.h" | 14 #include "cc/test/geometry_test_utils.h" |
15 #include "cc/test/test_shared_bitmap_manager.h" | 15 #include "cc/test/test_shared_bitmap_manager.h" |
| 16 #include "cc/test/test_task_graph_runner.h" |
16 #include "cc/trees/layer_tree_impl.h" | 17 #include "cc/trees/layer_tree_impl.h" |
17 #include "cc/trees/single_thread_proxy.h" | 18 #include "cc/trees/single_thread_proxy.h" |
18 #include "cc/trees/tree_synchronizer.h" | 19 #include "cc/trees/tree_synchronizer.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 22 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
22 | 23 |
23 namespace cc { | 24 namespace cc { |
24 namespace { | 25 namespace { |
25 | 26 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 81 |
81 TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { | 82 TEST(LayerImplTest, VerifyLayerChangesAreTrackedProperly) { |
82 // | 83 // |
83 // This test checks that layerPropertyChanged() has the correct behavior. | 84 // This test checks that layerPropertyChanged() has the correct behavior. |
84 // | 85 // |
85 | 86 |
86 // The constructor on this will fake that we are on the correct thread. | 87 // The constructor on this will fake that we are on the correct thread. |
87 // Create a simple LayerImpl tree: | 88 // Create a simple LayerImpl tree: |
88 FakeImplProxy proxy; | 89 FakeImplProxy proxy; |
89 TestSharedBitmapManager shared_bitmap_manager; | 90 TestSharedBitmapManager shared_bitmap_manager; |
90 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); | 91 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
91 EXPECT_TRUE(host_impl.InitializeRenderer(FakeOutputSurface::Create3d())); | 92 EXPECT_TRUE(host_impl.InitializeRenderer(FakeOutputSurface::Create3d())); |
92 scoped_ptr<LayerImpl> root_clip = | 93 scoped_ptr<LayerImpl> root_clip = |
93 LayerImpl::Create(host_impl.active_tree(), 1); | 94 LayerImpl::Create(host_impl.active_tree(), 1); |
94 scoped_ptr<LayerImpl> root_ptr = | 95 scoped_ptr<LayerImpl> root_ptr = |
95 LayerImpl::Create(host_impl.active_tree(), 2); | 96 LayerImpl::Create(host_impl.active_tree(), 2); |
96 LayerImpl* root = root_ptr.get(); | 97 LayerImpl* root = root_ptr.get(); |
97 root_clip->AddChild(root_ptr.Pass()); | 98 root_clip->AddChild(root_ptr.Pass()); |
98 scoped_ptr<LayerImpl> scroll_parent = | 99 scoped_ptr<LayerImpl> scroll_parent = |
99 LayerImpl::Create(host_impl.active_tree(), 3); | 100 LayerImpl::Create(host_impl.active_tree(), 3); |
100 LayerImpl* scroll_child = LayerImpl::Create(host_impl.active_tree(), 4).get(); | 101 LayerImpl* scroll_child = LayerImpl::Create(host_impl.active_tree(), 4).get(); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 root->SetScrollChildren(scroll_children)); | 244 root->SetScrollChildren(scroll_children)); |
244 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( | 245 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( |
245 root->SetClipParent(clip_parent.get())); | 246 root->SetClipParent(clip_parent.get())); |
246 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( | 247 EXECUTE_AND_VERIFY_SUBTREE_DID_NOT_CHANGE( |
247 root->SetClipChildren(clip_children)); | 248 root->SetClipChildren(clip_children)); |
248 } | 249 } |
249 | 250 |
250 TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { | 251 TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { |
251 FakeImplProxy proxy; | 252 FakeImplProxy proxy; |
252 TestSharedBitmapManager shared_bitmap_manager; | 253 TestSharedBitmapManager shared_bitmap_manager; |
253 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); | 254 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
254 EXPECT_TRUE(host_impl.InitializeRenderer(FakeOutputSurface::Create3d())); | 255 EXPECT_TRUE(host_impl.InitializeRenderer(FakeOutputSurface::Create3d())); |
255 host_impl.active_tree()->SetRootLayer( | 256 host_impl.active_tree()->SetRootLayer( |
256 LayerImpl::Create(host_impl.active_tree(), 1)); | 257 LayerImpl::Create(host_impl.active_tree(), 1)); |
257 LayerImpl* root = host_impl.active_tree()->root_layer(); | 258 LayerImpl* root = host_impl.active_tree()->root_layer(); |
258 root->SetHasRenderSurface(true); | 259 root->SetHasRenderSurface(true); |
259 scoped_ptr<LayerImpl> layer_ptr = | 260 scoped_ptr<LayerImpl> layer_ptr = |
260 LayerImpl::Create(host_impl.active_tree(), 2); | 261 LayerImpl::Create(host_impl.active_tree(), 2); |
261 LayerImpl* layer = layer_ptr.get(); | 262 LayerImpl* layer = layer_ptr.get(); |
262 root->AddChild(layer_ptr.Pass()); | 263 root->AddChild(layer_ptr.Pass()); |
263 layer->SetScrollClipLayer(root->id()); | 264 layer->SetScrollClipLayer(root->id()); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( | 362 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( |
362 layer->SetIsRootForIsolatedGroup(true)); | 363 layer->SetIsRootForIsolatedGroup(true)); |
363 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( | 364 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES( |
364 layer->SetTransform(arbitrary_transform)); | 365 layer->SetTransform(arbitrary_transform)); |
365 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(arbitrary_size)); | 366 VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(arbitrary_size)); |
366 } | 367 } |
367 | 368 |
368 TEST(LayerImplTest, SafeOpaqueBackgroundColor) { | 369 TEST(LayerImplTest, SafeOpaqueBackgroundColor) { |
369 FakeImplProxy proxy; | 370 FakeImplProxy proxy; |
370 TestSharedBitmapManager shared_bitmap_manager; | 371 TestSharedBitmapManager shared_bitmap_manager; |
371 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); | 372 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
372 EXPECT_TRUE(host_impl.InitializeRenderer(FakeOutputSurface::Create3d())); | 373 EXPECT_TRUE(host_impl.InitializeRenderer(FakeOutputSurface::Create3d())); |
373 scoped_ptr<LayerImpl> layer = LayerImpl::Create(host_impl.active_tree(), 1); | 374 scoped_ptr<LayerImpl> layer = LayerImpl::Create(host_impl.active_tree(), 1); |
374 | 375 |
375 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { | 376 for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { |
376 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) { | 377 for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) { |
377 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) { | 378 for (int host_opaque = 0; host_opaque < 2; ++host_opaque) { |
378 layer->SetContentsOpaque(!!contents_opaque); | 379 layer->SetContentsOpaque(!!contents_opaque); |
379 layer->SetBackgroundColor(layer_opaque ? SK_ColorRED | 380 layer->SetBackgroundColor(layer_opaque ? SK_ColorRED |
380 : SK_ColorTRANSPARENT); | 381 : SK_ColorTRANSPARENT); |
381 host_impl.active_tree()->set_background_color( | 382 host_impl.active_tree()->set_background_color( |
(...skipping 10 matching lines...) Expand all Loading... |
392 << host_opaque << "\n"; | 393 << host_opaque << "\n"; |
393 } | 394 } |
394 } | 395 } |
395 } | 396 } |
396 } | 397 } |
397 } | 398 } |
398 | 399 |
399 TEST(LayerImplTest, TransformInvertibility) { | 400 TEST(LayerImplTest, TransformInvertibility) { |
400 FakeImplProxy proxy; | 401 FakeImplProxy proxy; |
401 TestSharedBitmapManager shared_bitmap_manager; | 402 TestSharedBitmapManager shared_bitmap_manager; |
402 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); | 403 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
403 | 404 |
404 scoped_ptr<LayerImpl> layer = LayerImpl::Create(host_impl.active_tree(), 1); | 405 scoped_ptr<LayerImpl> layer = LayerImpl::Create(host_impl.active_tree(), 1); |
405 EXPECT_TRUE(layer->transform().IsInvertible()); | 406 EXPECT_TRUE(layer->transform().IsInvertible()); |
406 EXPECT_TRUE(layer->transform_is_invertible()); | 407 EXPECT_TRUE(layer->transform_is_invertible()); |
407 | 408 |
408 gfx::Transform transform; | 409 gfx::Transform transform; |
409 transform.Scale3d( | 410 transform.Scale3d( |
410 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); | 411 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
411 layer->SetTransform(transform); | 412 layer->SetTransform(transform); |
412 EXPECT_FALSE(layer->transform().IsInvertible()); | 413 EXPECT_FALSE(layer->transform().IsInvertible()); |
413 EXPECT_FALSE(layer->transform_is_invertible()); | 414 EXPECT_FALSE(layer->transform_is_invertible()); |
414 | 415 |
415 transform.MakeIdentity(); | 416 transform.MakeIdentity(); |
416 transform.ApplyPerspectiveDepth(SkDoubleToMScalar(100.0)); | 417 transform.ApplyPerspectiveDepth(SkDoubleToMScalar(100.0)); |
417 transform.RotateAboutZAxis(75.0); | 418 transform.RotateAboutZAxis(75.0); |
418 transform.RotateAboutXAxis(32.2); | 419 transform.RotateAboutXAxis(32.2); |
419 transform.RotateAboutZAxis(-75.0); | 420 transform.RotateAboutZAxis(-75.0); |
420 transform.Translate3d(SkDoubleToMScalar(50.5), | 421 transform.Translate3d(SkDoubleToMScalar(50.5), |
421 SkDoubleToMScalar(42.42), | 422 SkDoubleToMScalar(42.42), |
422 SkDoubleToMScalar(-100.25)); | 423 SkDoubleToMScalar(-100.25)); |
423 | 424 |
424 layer->SetTransform(transform); | 425 layer->SetTransform(transform); |
425 EXPECT_TRUE(layer->transform().IsInvertible()); | 426 EXPECT_TRUE(layer->transform().IsInvertible()); |
426 EXPECT_TRUE(layer->transform_is_invertible()); | 427 EXPECT_TRUE(layer->transform_is_invertible()); |
427 } | 428 } |
428 | 429 |
429 class LayerImplScrollTest : public testing::Test { | 430 class LayerImplScrollTest : public testing::Test { |
430 public: | 431 public: |
431 LayerImplScrollTest() | 432 LayerImplScrollTest() |
432 : host_impl_(settings(), &proxy_, &shared_bitmap_manager_), root_id_(7) { | 433 : host_impl_(settings(), |
| 434 &proxy_, |
| 435 &shared_bitmap_manager_, |
| 436 &task_graph_runner_), |
| 437 root_id_(7) { |
433 host_impl_.active_tree()->SetRootLayer( | 438 host_impl_.active_tree()->SetRootLayer( |
434 LayerImpl::Create(host_impl_.active_tree(), root_id_)); | 439 LayerImpl::Create(host_impl_.active_tree(), root_id_)); |
435 host_impl_.active_tree()->root_layer()->AddChild( | 440 host_impl_.active_tree()->root_layer()->AddChild( |
436 LayerImpl::Create(host_impl_.active_tree(), root_id_ + 1)); | 441 LayerImpl::Create(host_impl_.active_tree(), root_id_ + 1)); |
437 layer()->SetScrollClipLayer(root_id_); | 442 layer()->SetScrollClipLayer(root_id_); |
438 // Set the max scroll offset by noting that the root layer has bounds (1,1), | 443 // Set the max scroll offset by noting that the root layer has bounds (1,1), |
439 // thus whatever bounds are set for the layer will be the max scroll | 444 // thus whatever bounds are set for the layer will be the max scroll |
440 // offset plus 1 in each direction. | 445 // offset plus 1 in each direction. |
441 host_impl_.active_tree()->root_layer()->SetBounds(gfx::Size(1, 1)); | 446 host_impl_.active_tree()->root_layer()->SetBounds(gfx::Size(1, 1)); |
442 gfx::Vector2d max_scroll_offset(51, 81); | 447 gfx::Vector2d max_scroll_offset(51, 81); |
(...skipping 10 matching lines...) Expand all Loading... |
453 | 458 |
454 LayerTreeSettings settings() { | 459 LayerTreeSettings settings() { |
455 LayerTreeSettings settings; | 460 LayerTreeSettings settings; |
456 settings.use_pinch_virtual_viewport = true; | 461 settings.use_pinch_virtual_viewport = true; |
457 return settings; | 462 return settings; |
458 } | 463 } |
459 | 464 |
460 private: | 465 private: |
461 FakeImplProxy proxy_; | 466 FakeImplProxy proxy_; |
462 TestSharedBitmapManager shared_bitmap_manager_; | 467 TestSharedBitmapManager shared_bitmap_manager_; |
| 468 TestTaskGraphRunner task_graph_runner_; |
463 FakeLayerTreeHostImpl host_impl_; | 469 FakeLayerTreeHostImpl host_impl_; |
464 int root_id_; | 470 int root_id_; |
465 }; | 471 }; |
466 | 472 |
467 TEST_F(LayerImplScrollTest, ScrollByWithZeroOffset) { | 473 TEST_F(LayerImplScrollTest, ScrollByWithZeroOffset) { |
468 // Test that LayerImpl::ScrollBy only affects ScrollDelta and total scroll | 474 // Test that LayerImpl::ScrollBy only affects ScrollDelta and total scroll |
469 // offset is bounded by the range [0, max scroll offset]. | 475 // offset is bounded by the range [0, max scroll offset]. |
470 | 476 |
471 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->CurrentScrollOffset()); | 477 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->CurrentScrollOffset()); |
472 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->BaseScrollOffset()); | 478 EXPECT_VECTOR_EQ(gfx::Vector2dF(), layer()->BaseScrollOffset()); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 OLD_ROOT = 6, | 770 OLD_ROOT = 6, |
765 OV_CLIP = 7, | 771 OV_CLIP = 7, |
766 OV_SCROLL = 8, | 772 OV_SCROLL = 8, |
767 }; | 773 }; |
768 enum TreeID { | 774 enum TreeID { |
769 PENDING, | 775 PENDING, |
770 ACTIVE | 776 ACTIVE |
771 }; | 777 }; |
772 | 778 |
773 LayerImplScrollbarSyncTest() | 779 LayerImplScrollbarSyncTest() |
774 : host_impl_(settings(), &proxy_, &shared_bitmap_manager_) { | 780 : host_impl_(settings(), |
| 781 &proxy_, |
| 782 &shared_bitmap_manager_, |
| 783 &task_graph_runner_) { |
775 host_impl_.CreatePendingTree(); | 784 host_impl_.CreatePendingTree(); |
776 | 785 |
777 CreateLayers(host_impl_.pending_tree()); | 786 CreateLayers(host_impl_.pending_tree()); |
778 CreateLayers(host_impl_.active_tree()); | 787 CreateLayers(host_impl_.active_tree()); |
779 } | 788 } |
780 | 789 |
781 void CreateLayers(LayerTreeImpl * tree) { | 790 void CreateLayers(LayerTreeImpl * tree) { |
782 tree->SetRootLayer(LayerImpl::Create(tree, ROOT)); | 791 tree->SetRootLayer(LayerImpl::Create(tree, ROOT)); |
783 LayerImpl * root = tree->root_layer(); | 792 LayerImpl * root = tree->root_layer(); |
784 ASSERT_TRUE(root != nullptr); | 793 ASSERT_TRUE(root != nullptr); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 | 838 |
830 LayerTreeSettings settings() { | 839 LayerTreeSettings settings() { |
831 LayerTreeSettings settings; | 840 LayerTreeSettings settings; |
832 settings.use_pinch_virtual_viewport = true; | 841 settings.use_pinch_virtual_viewport = true; |
833 return settings; | 842 return settings; |
834 } | 843 } |
835 | 844 |
836 private: | 845 private: |
837 FakeImplProxy proxy_; | 846 FakeImplProxy proxy_; |
838 TestSharedBitmapManager shared_bitmap_manager_; | 847 TestSharedBitmapManager shared_bitmap_manager_; |
| 848 TestTaskGraphRunner task_graph_runner_; |
839 FakeLayerTreeHostImpl host_impl_; | 849 FakeLayerTreeHostImpl host_impl_; |
840 }; | 850 }; |
841 | 851 |
842 TEST_F(LayerImplScrollbarSyncTest, LayerImplBecomesScrollable) { | 852 TEST_F(LayerImplScrollbarSyncTest, LayerImplBecomesScrollable) { |
843 // In the beginning IV_SCROLL layer is not scrollable. | 853 // In the beginning IV_SCROLL layer is not scrollable. |
844 ASSERT_FALSE(layer(IV_SCROLL, PENDING)->scrollable()); | 854 ASSERT_FALSE(layer(IV_SCROLL, PENDING)->scrollable()); |
845 | 855 |
846 // For pinch virtual viewport the clip layer is the inner viewport | 856 // For pinch virtual viewport the clip layer is the inner viewport |
847 // clip layer (IV_CLIP) and the scroll one is the outer viewport | 857 // clip layer (IV_CLIP) and the scroll one is the outer viewport |
848 // scroll layer (OV_SCROLL). | 858 // scroll layer (OV_SCROLL). |
(...skipping 25 matching lines...) Expand all Loading... |
874 | 884 |
875 ASSERT_TRUE(layer(IV_SCROLL, ACTIVE)->scrollable()); | 885 ASSERT_TRUE(layer(IV_SCROLL, ACTIVE)->scrollable()); |
876 | 886 |
877 ASSERT_TRUE(LayerHasScrollbar(OV_SCROLL, ACTIVE)); | 887 ASSERT_TRUE(LayerHasScrollbar(OV_SCROLL, ACTIVE)); |
878 ASSERT_TRUE(LayerHasScrollbar(IV_CLIP, ACTIVE)); | 888 ASSERT_TRUE(LayerHasScrollbar(IV_CLIP, ACTIVE)); |
879 ASSERT_TRUE(LayerHasScrollbar(IV_SCROLL, ACTIVE)); | 889 ASSERT_TRUE(LayerHasScrollbar(IV_SCROLL, ACTIVE)); |
880 } | 890 } |
881 | 891 |
882 } // namespace | 892 } // namespace |
883 } // namespace cc | 893 } // namespace cc |
OLD | NEW |