| 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/trees/tree_synchronizer.h" | 5 #include "cc/trees/tree_synchronizer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 LayerTreeSettingsForTreeSynchronizerTest())) { | 212 LayerTreeSettingsForTreeSynchronizerTest())) { |
| 213 layer_settings_.use_compositor_animation_timelines = | 213 layer_settings_.use_compositor_animation_timelines = |
| 214 host_->settings().use_compositor_animation_timelines; | 214 host_->settings().use_compositor_animation_timelines; |
| 215 } | 215 } |
| 216 | 216 |
| 217 protected: | 217 protected: |
| 218 FakeLayerTreeHostClient client_; | 218 FakeLayerTreeHostClient client_; |
| 219 TestTaskGraphRunner task_graph_runner_; | 219 TestTaskGraphRunner task_graph_runner_; |
| 220 scoped_ptr<FakeLayerTreeHost> host_; | 220 scoped_ptr<FakeLayerTreeHost> host_; |
| 221 LayerSettings layer_settings_; | 221 LayerSettings layer_settings_; |
| 222 |
| 223 bool is_equal(ScrollTree::ScrollOffsetMap map, |
| 224 ScrollTree::ScrollOffsetMap other) { |
| 225 if (map.size() != other.size()) |
| 226 return false; |
| 227 for (auto& map_entry : map) { |
| 228 if (other.find(map_entry.first) == other.end()) |
| 229 return false; |
| 230 SyncedScrollOffset& from_map = *map_entry.second.get(); |
| 231 SyncedScrollOffset& from_other = *other[map_entry.first].get(); |
| 232 if (from_map.PendingBase() != from_other.PendingBase() || |
| 233 from_map.ActiveBase() != from_other.ActiveBase() || |
| 234 from_map.Delta() != from_other.Delta() || |
| 235 from_map.PendingDelta().get() != from_other.PendingDelta().get()) |
| 236 return false; |
| 237 } |
| 238 return true; |
| 239 } |
| 222 }; | 240 }; |
| 223 | 241 |
| 224 // Attempts to synchronizes a null tree. This should not crash, and should | 242 // Attempts to synchronizes a null tree. This should not crash, and should |
| 225 // return a null tree. | 243 // return a null tree. |
| 226 TEST_F(TreeSynchronizerTest, SyncNullTree) { | 244 TEST_F(TreeSynchronizerTest, SyncNullTree) { |
| 227 scoped_ptr<LayerImpl> layer_impl_tree_root = | 245 scoped_ptr<LayerImpl> layer_impl_tree_root = |
| 228 TreeSynchronizer::SynchronizeTrees( | 246 TreeSynchronizer::SynchronizeTrees( |
| 229 static_cast<Layer*>(NULL), nullptr, host_->active_tree()); | 247 static_cast<Layer*>(NULL), nullptr, host_->active_tree()); |
| 230 | 248 |
| 231 EXPECT_TRUE(!layer_impl_tree_root.get()); | 249 EXPECT_TRUE(!layer_impl_tree_root.get()); |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 host_->BuildPropertyTreesForTesting(); | 811 host_->BuildPropertyTreesForTesting(); |
| 794 | 812 |
| 795 host_impl->CreatePendingTree(); | 813 host_impl->CreatePendingTree(); |
| 796 host_->CommitAndCreatePendingTree(); | 814 host_->CommitAndCreatePendingTree(); |
| 797 host_impl->ActivateSyncTree(); | 815 host_impl->ActivateSyncTree(); |
| 798 | 816 |
| 799 EXPECT_EQ(scroll_layer->id(), | 817 EXPECT_EQ(scroll_layer->id(), |
| 800 host_impl->active_tree()->CurrentlyScrollingLayer()->id()); | 818 host_impl->active_tree()->CurrentlyScrollingLayer()->id()); |
| 801 } | 819 } |
| 802 | 820 |
| 821 TEST_F(TreeSynchronizerTest, SynchronizeScrollTreeScrollOffsetMap) { |
| 822 host_->InitializeSingleThreaded(&client_, base::ThreadTaskRunnerHandle::Get(), |
| 823 nullptr); |
| 824 LayerTreeSettings settings; |
| 825 FakeLayerTreeHostImplClient client; |
| 826 FakeImplTaskRunnerProvider task_runner_provider; |
| 827 FakeRenderingStatsInstrumentation stats_instrumentation; |
| 828 TestSharedBitmapManager shared_bitmap_manager; |
| 829 TestTaskGraphRunner task_graph_runner; |
| 830 FakeLayerTreeHostImpl* host_impl = host_->host_impl(); |
| 831 host_impl->CreatePendingTree(); |
| 832 |
| 833 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings_); |
| 834 scoped_refptr<Layer> scroll_clip_layer = Layer::Create(layer_settings_); |
| 835 scoped_refptr<Layer> scroll_layer = Layer::Create(layer_settings_); |
| 836 scoped_refptr<Layer> transient_scroll_clip_layer = |
| 837 Layer::Create(layer_settings_); |
| 838 scoped_refptr<Layer> transient_scroll_layer = Layer::Create(layer_settings_); |
| 839 |
| 840 layer_tree_root->AddChild(transient_scroll_clip_layer); |
| 841 transient_scroll_clip_layer->AddChild(transient_scroll_layer); |
| 842 transient_scroll_layer->AddChild(scroll_clip_layer); |
| 843 scroll_clip_layer->AddChild(scroll_layer); |
| 844 |
| 845 transient_scroll_layer->SetScrollClipLayerId( |
| 846 transient_scroll_clip_layer->id()); |
| 847 scroll_layer->SetScrollClipLayerId(scroll_clip_layer->id()); |
| 848 transient_scroll_layer->SetScrollOffset(gfx::ScrollOffset(1, 2)); |
| 849 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
| 850 |
| 851 host_->SetRootLayer(layer_tree_root); |
| 852 host_->BuildPropertyTreesForTesting(); |
| 853 host_->CommitAndCreatePendingTree(); |
| 854 host_impl->ActivateSyncTree(); |
| 855 |
| 856 ExpectTreesAreIdentical(layer_tree_root.get(), |
| 857 host_impl->active_tree()->root_layer(), |
| 858 host_impl->active_tree()); |
| 859 |
| 860 // After the initial commit, scroll_offset_map in scroll_tree is expected to |
| 861 // have one entry for scroll_layer and one entry for transient_scroll_layer, |
| 862 // the pending base and active base must be the same at this stage. |
| 863 ScrollTree::ScrollOffsetMap scroll_offset_map; |
| 864 scroll_offset_map[scroll_layer->id()] = new SyncedScrollOffset; |
| 865 scroll_offset_map[transient_scroll_layer->id()] = new SyncedScrollOffset; |
| 866 scroll_offset_map[scroll_layer->id()]->PushFromMainThread( |
| 867 scroll_layer->scroll_offset()); |
| 868 scroll_offset_map[scroll_layer->id()]->PushPendingToActive(); |
| 869 scroll_offset_map[transient_scroll_layer->id()]->PushFromMainThread( |
| 870 transient_scroll_layer->scroll_offset()); |
| 871 scroll_offset_map[transient_scroll_layer->id()]->PushPendingToActive(); |
| 872 EXPECT_TRUE( |
| 873 is_equal(scroll_offset_map, host_impl->active_tree() |
| 874 ->property_trees() |
| 875 ->scroll_tree.scroll_offset_map())); |
| 876 |
| 877 // Set ScrollOffset active delta: gfx::ScrollOffset(10, 10) |
| 878 LayerImpl* scroll_layer_impl = |
| 879 host_impl->active_tree()->LayerById(scroll_layer->id()); |
| 880 ScrollTree& scroll_tree = |
| 881 host_impl->active_tree()->property_trees()->scroll_tree; |
| 882 scroll_tree.synced_scroll_offset(scroll_layer_impl->id()) |
| 883 ->SetCurrent(gfx::ScrollOffset(20, 30)); |
| 884 |
| 885 // Pull ScrollOffset delta for main thread, and change offset on main thread |
| 886 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); |
| 887 scroll_tree.CollectScrollDeltas(scroll_info.get()); |
| 888 host_->proxy()->SetNeedsCommit(); |
| 889 host_->ApplyScrollAndScale(scroll_info.get()); |
| 890 EXPECT_EQ(gfx::ScrollOffset(20, 30), scroll_layer->scroll_offset()); |
| 891 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 100)); |
| 892 |
| 893 // More update to ScrollOffset active delta: gfx::ScrollOffset(20, 20) |
| 894 scroll_tree.synced_scroll_offset(scroll_layer_impl->id()) |
| 895 ->SetCurrent(gfx::ScrollOffset(40, 50)); |
| 896 host_impl->active_tree()->SetCurrentlyScrollingLayer(scroll_layer_impl); |
| 897 |
| 898 // Make one layer unscrollable so that scroll tree topology changes |
| 899 transient_scroll_layer->SetScrollClipLayerId(Layer::INVALID_ID); |
| 900 host_->BuildPropertyTreesForTesting(); |
| 901 |
| 902 host_impl->CreatePendingTree(); |
| 903 host_->CommitAndCreatePendingTree(); |
| 904 host_impl->ActivateSyncTree(); |
| 905 |
| 906 EXPECT_EQ(scroll_layer->id(), |
| 907 host_impl->active_tree()->CurrentlyScrollingLayer()->id()); |
| 908 scroll_offset_map.erase(transient_scroll_layer->id()); |
| 909 scroll_offset_map[scroll_layer->id()]->SetCurrent(gfx::ScrollOffset(20, 30)); |
| 910 scroll_offset_map[scroll_layer->id()]->PullDeltaForMainThread(); |
| 911 scroll_offset_map[scroll_layer->id()]->SetCurrent(gfx::ScrollOffset(40, 50)); |
| 912 scroll_offset_map[scroll_layer->id()]->PushFromMainThread( |
| 913 gfx::ScrollOffset(100, 100)); |
| 914 scroll_offset_map[scroll_layer->id()]->PushPendingToActive(); |
| 915 EXPECT_TRUE(is_equal(scroll_offset_map, scroll_tree.scroll_offset_map())); |
| 916 } |
| 917 |
| 803 } // namespace | 918 } // namespace |
| 804 } // namespace cc | 919 } // namespace cc |
| OLD | NEW |