| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <unordered_map> | 7 #include <unordered_map> |
| 8 | 8 |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "cc/animation/animation_host.h" | 10 #include "cc/animation/animation_host.h" |
| 11 #include "cc/input/scrollbar_animation_controller.h" | 11 #include "cc/input/scrollbar_animation_controller.h" |
| 12 #include "cc/layers/append_quads_data.h" | 12 #include "cc/layers/append_quads_data.h" |
| 13 #include "cc/layers/painted_scrollbar_layer.h" | 13 #include "cc/layers/painted_scrollbar_layer.h" |
| 14 #include "cc/layers/painted_scrollbar_layer_impl.h" | 14 #include "cc/layers/painted_scrollbar_layer_impl.h" |
| 15 #include "cc/layers/scrollbar_layer_interface.h" | 15 #include "cc/layers/scrollbar_layer_interface.h" |
| 16 #include "cc/layers/solid_color_scrollbar_layer.h" | 16 #include "cc/layers/solid_color_scrollbar_layer.h" |
| 17 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | 17 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
| 18 #include "cc/quads/solid_color_draw_quad.h" | 18 #include "cc/quads/solid_color_draw_quad.h" |
| 19 #include "cc/test/fake_impl_task_runner_provider.h" | 19 #include "cc/test/fake_impl_task_runner_provider.h" |
| 20 #include "cc/test/fake_layer_tree_host.h" | 20 #include "cc/test/fake_layer_tree_host.h" |
| 21 #include "cc/test/fake_layer_tree_host_client.h" | 21 #include "cc/test/fake_layer_tree_host_client.h" |
| 22 #include "cc/test/fake_layer_tree_host_impl.h" | 22 #include "cc/test/fake_layer_tree_host_impl.h" |
| 23 #include "cc/test/fake_painted_scrollbar_layer.h" | 23 #include "cc/test/fake_painted_scrollbar_layer.h" |
| 24 #include "cc/test/fake_scrollbar.h" | 24 #include "cc/test/fake_scrollbar.h" |
| 25 #include "cc/test/geometry_test_utils.h" | 25 #include "cc/test/geometry_test_utils.h" |
| 26 #include "cc/test/layer_tree_test.h" | 26 #include "cc/test/layer_tree_test.h" |
| 27 #include "cc/test/mock_occlusion_tracker.h" | 27 #include "cc/test/mock_occlusion_tracker.h" |
| 28 #include "cc/test/test_task_graph_runner.h" | 28 #include "cc/test/test_task_graph_runner.h" |
| 29 #include "cc/test/test_web_graphics_context_3d.h" | 29 #include "cc/test/test_web_graphics_context_3d.h" |
| 30 #include "cc/trees/effect_node.h" |
| 30 #include "cc/trees/layer_tree_host.h" | 31 #include "cc/trees/layer_tree_host.h" |
| 31 #include "cc/trees/layer_tree_impl.h" | 32 #include "cc/trees/layer_tree_impl.h" |
| 32 #include "cc/trees/occlusion_tracker.h" | 33 #include "cc/trees/occlusion_tracker.h" |
| 34 #include "cc/trees/scroll_node.h" |
| 33 #include "cc/trees/single_thread_proxy.h" | 35 #include "cc/trees/single_thread_proxy.h" |
| 34 #include "cc/trees/tree_synchronizer.h" | 36 #include "cc/trees/tree_synchronizer.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 37 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 37 | 39 |
| 38 namespace cc { | 40 namespace cc { |
| 39 namespace { | 41 namespace { |
| 40 | 42 |
| 41 class FakeResourceTrackingLayerTreeHost : public FakeLayerTreeHost { | 43 class FakeResourceTrackingLayerTreeHost : public FakeLayerTreeHost { |
| 42 public: | 44 public: |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 layer_tree_host_->property_trees()->needs_rebuild = true; | 538 layer_tree_host_->property_trees()->needs_rebuild = true; |
| 537 layer_tree_host_->BuildPropertyTreesForTesting(); | 539 layer_tree_host_->BuildPropertyTreesForTesting(); |
| 538 EXPECT_EQ(layer_tree_host_->property_trees() | 540 EXPECT_EQ(layer_tree_host_->property_trees() |
| 539 ->always_use_active_tree_opacity_effect_ids.size(), | 541 ->always_use_active_tree_opacity_effect_ids.size(), |
| 540 1u); | 542 1u); |
| 541 | 543 |
| 542 // A solid color scrollbar layer's opacity is initialized to 0 on main thread | 544 // A solid color scrollbar layer's opacity is initialized to 0 on main thread |
| 543 layer_tree_host_->UpdateLayers(); | 545 layer_tree_host_->UpdateLayers(); |
| 544 EffectNode* node = layer_tree_host_->property_trees()->effect_tree.Node( | 546 EffectNode* node = layer_tree_host_->property_trees()->effect_tree.Node( |
| 545 scrollbar_layer->effect_tree_index()); | 547 scrollbar_layer->effect_tree_index()); |
| 546 EXPECT_EQ(node->data.opacity, 0.f); | 548 EXPECT_EQ(node->opacity, 0.f); |
| 547 | 549 |
| 548 // This tests that the initial opacity(0) of the scrollbar gets pushed onto | 550 // This tests that the initial opacity(0) of the scrollbar gets pushed onto |
| 549 // the pending tree and then onto the active tree. | 551 // the pending tree and then onto the active tree. |
| 550 LayerTreeHostImpl* host_impl = layer_tree_host_->host_impl(); | 552 LayerTreeHostImpl* host_impl = layer_tree_host_->host_impl(); |
| 551 host_impl->CreatePendingTree(); | 553 host_impl->CreatePendingTree(); |
| 552 LayerImpl* layer_impl_tree_root = | 554 LayerImpl* layer_impl_tree_root = |
| 553 layer_tree_host_->CommitAndCreatePendingTree(); | 555 layer_tree_host_->CommitAndCreatePendingTree(); |
| 554 LayerTreeImpl* layer_tree_impl = layer_impl_tree_root->layer_tree_impl(); | 556 LayerTreeImpl* layer_tree_impl = layer_impl_tree_root->layer_tree_impl(); |
| 555 EXPECT_TRUE(layer_tree_impl->IsPendingTree()); | 557 EXPECT_TRUE(layer_tree_impl->IsPendingTree()); |
| 556 node = layer_tree_impl->property_trees()->effect_tree.Node( | 558 node = layer_tree_impl->property_trees()->effect_tree.Node( |
| 557 scrollbar_layer->effect_tree_index()); | 559 scrollbar_layer->effect_tree_index()); |
| 558 EXPECT_EQ(node->data.opacity, 0.f); | 560 EXPECT_EQ(node->opacity, 0.f); |
| 559 host_impl->ActivateSyncTree(); | 561 host_impl->ActivateSyncTree(); |
| 560 layer_tree_impl = host_impl->active_tree(); | 562 layer_tree_impl = host_impl->active_tree(); |
| 561 node = layer_tree_impl->property_trees()->effect_tree.Node( | 563 node = layer_tree_impl->property_trees()->effect_tree.Node( |
| 562 scrollbar_layer->effect_tree_index()); | 564 scrollbar_layer->effect_tree_index()); |
| 563 EXPECT_EQ(node->data.opacity, 0.f); | 565 EXPECT_EQ(node->opacity, 0.f); |
| 564 | 566 |
| 565 // This tests that activation does not change the opacity of scrollbar layer. | 567 // This tests that activation does not change the opacity of scrollbar layer. |
| 566 LayerImpl* scrollbar_layer_impl = | 568 LayerImpl* scrollbar_layer_impl = |
| 567 layer_tree_impl->LayerById(scrollbar_layer->id()); | 569 layer_tree_impl->LayerById(scrollbar_layer->id()); |
| 568 scrollbar_layer_impl->OnOpacityAnimated(0.25f); | 570 scrollbar_layer_impl->OnOpacityAnimated(0.25f); |
| 569 host_impl->CreatePendingTree(); | 571 host_impl->CreatePendingTree(); |
| 570 layer_impl_tree_root = layer_tree_host_->CommitAndCreatePendingTree(); | 572 layer_impl_tree_root = layer_tree_host_->CommitAndCreatePendingTree(); |
| 571 layer_tree_impl = layer_impl_tree_root->layer_tree_impl(); | 573 layer_tree_impl = layer_impl_tree_root->layer_tree_impl(); |
| 572 EXPECT_TRUE(layer_tree_impl->IsPendingTree()); | 574 EXPECT_TRUE(layer_tree_impl->IsPendingTree()); |
| 573 node = layer_tree_impl->property_trees()->effect_tree.Node( | 575 node = layer_tree_impl->property_trees()->effect_tree.Node( |
| 574 scrollbar_layer->effect_tree_index()); | 576 scrollbar_layer->effect_tree_index()); |
| 575 EXPECT_EQ(node->data.opacity, 0.f); | 577 EXPECT_EQ(node->opacity, 0.f); |
| 576 host_impl->ActivateSyncTree(); | 578 host_impl->ActivateSyncTree(); |
| 577 layer_tree_impl = host_impl->active_tree(); | 579 layer_tree_impl = host_impl->active_tree(); |
| 578 node = layer_tree_impl->property_trees()->effect_tree.Node( | 580 node = layer_tree_impl->property_trees()->effect_tree.Node( |
| 579 scrollbar_layer->effect_tree_index()); | 581 scrollbar_layer->effect_tree_index()); |
| 580 EXPECT_EQ(node->data.opacity, 0.25f); | 582 EXPECT_EQ(node->opacity, 0.25f); |
| 581 } | 583 } |
| 582 | 584 |
| 583 TEST_F(ScrollbarLayerTest, ScrollbarLayerPushProperties) { | 585 TEST_F(ScrollbarLayerTest, ScrollbarLayerPushProperties) { |
| 584 // Pushing changed bounds of scroll layer can lead to calling | 586 // Pushing changed bounds of scroll layer can lead to calling |
| 585 // OnOpacityAnimated on scrollbar layer which means OnOpacityAnimated should | 587 // OnOpacityAnimated on scrollbar layer which means OnOpacityAnimated should |
| 586 // be independent of scrollbar layer's properties as scrollbar layer can push | 588 // be independent of scrollbar layer's properties as scrollbar layer can push |
| 587 // its properties after scroll layer. | 589 // its properties after scroll layer. |
| 588 const int kThumbThickness = 3; | 590 const int kThumbThickness = 3; |
| 589 const int kTrackStart = 0; | 591 const int kTrackStart = 0; |
| 590 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 592 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 614 | 616 |
| 615 scroll_layer->SetBounds(gfx::Size(20, 20)); | 617 scroll_layer->SetBounds(gfx::Size(20, 20)); |
| 616 scroll_layer->SetForceRenderSurfaceForTesting(true); | 618 scroll_layer->SetForceRenderSurfaceForTesting(true); |
| 617 layer_tree_host_->UpdateLayers(); | 619 layer_tree_host_->UpdateLayers(); |
| 618 host_impl->CreatePendingTree(); | 620 host_impl->CreatePendingTree(); |
| 619 layer_tree_host_->CommitAndCreatePendingTree(); | 621 layer_tree_host_->CommitAndCreatePendingTree(); |
| 620 host_impl->ActivateSyncTree(); | 622 host_impl->ActivateSyncTree(); |
| 621 EffectNode* node = | 623 EffectNode* node = |
| 622 host_impl->active_tree()->property_trees()->effect_tree.Node( | 624 host_impl->active_tree()->property_trees()->effect_tree.Node( |
| 623 scrollbar_layer->effect_tree_index()); | 625 scrollbar_layer->effect_tree_index()); |
| 624 EXPECT_EQ(node->data.opacity, 1.f); | 626 EXPECT_EQ(node->opacity, 1.f); |
| 625 } | 627 } |
| 626 | 628 |
| 627 class ScrollbarLayerSolidColorThumbTest : public testing::Test { | 629 class ScrollbarLayerSolidColorThumbTest : public testing::Test { |
| 628 public: | 630 public: |
| 629 ScrollbarLayerSolidColorThumbTest() { | 631 ScrollbarLayerSolidColorThumbTest() { |
| 630 LayerTreeSettings layer_tree_settings; | 632 LayerTreeSettings layer_tree_settings; |
| 631 host_impl_.reset(new FakeLayerTreeHostImpl( | 633 host_impl_.reset(new FakeLayerTreeHostImpl( |
| 632 layer_tree_settings, &task_runner_provider_, &shared_bitmap_manager_, | 634 layer_tree_settings, &task_runner_provider_, &shared_bitmap_manager_, |
| 633 &task_graph_runner_)); | 635 &task_graph_runner_)); |
| 634 | 636 |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1148 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
| 1147 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1149 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
| 1148 | 1150 |
| 1149 // Horizontal Scrollbars. | 1151 // Horizontal Scrollbars. |
| 1150 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1152 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
| 1151 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1153 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
| 1152 } | 1154 } |
| 1153 | 1155 |
| 1154 } // namespace | 1156 } // namespace |
| 1155 } // namespace cc | 1157 } // namespace cc |
| OLD | NEW |