| 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/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 1756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1767 PostSetNeedsCommitToMainThread(); | 1767 PostSetNeedsCommitToMainThread(); |
| 1768 client_.set_bounds(root_layer_->bounds()); | 1768 client_.set_bounds(root_layer_->bounds()); |
| 1769 } | 1769 } |
| 1770 | 1770 |
| 1771 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 1771 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| 1772 // Should only do one commit. | 1772 // Should only do one commit. |
| 1773 EXPECT_EQ(0, impl->active_tree()->source_frame_number()); | 1773 EXPECT_EQ(0, impl->active_tree()->source_frame_number()); |
| 1774 // Device scale factor should come over to impl. | 1774 // Device scale factor should come over to impl. |
| 1775 EXPECT_NEAR(impl->active_tree()->device_scale_factor(), 1.5f, 0.00001f); | 1775 EXPECT_NEAR(impl->active_tree()->device_scale_factor(), 1.5f, 0.00001f); |
| 1776 | 1776 |
| 1777 // Both layers are on impl. | |
| 1778 ASSERT_EQ(1u, impl->active_tree()->root_layer()->children().size()); | |
| 1779 | |
| 1780 // Device viewport is scaled. | 1777 // Device viewport is scaled. |
| 1781 EXPECT_EQ(gfx::Size(60, 60), impl->DrawViewportSize()); | 1778 EXPECT_EQ(gfx::Size(60, 60), impl->DrawViewportSize()); |
| 1782 | 1779 |
| 1783 FakePictureLayerImpl* root = | 1780 FakePictureLayerImpl* root = |
| 1784 static_cast<FakePictureLayerImpl*>(impl->active_tree()->root_layer()); | 1781 static_cast<FakePictureLayerImpl*>(impl->active_tree()->root_layer()); |
| 1785 FakePictureLayerImpl* child = static_cast<FakePictureLayerImpl*>( | 1782 FakePictureLayerImpl* child = static_cast<FakePictureLayerImpl*>( |
| 1786 impl->active_tree()->root_layer()->children()[0]); | 1783 impl->active_tree()->LayerById(child_layer_->id())); |
| 1787 | 1784 |
| 1788 // Positions remain in layout pixels. | 1785 // Positions remain in layout pixels. |
| 1789 EXPECT_EQ(gfx::PointF(), root->position()); | 1786 EXPECT_EQ(gfx::PointF(), root->position()); |
| 1790 EXPECT_EQ(gfx::PointF(2.f, 2.f), child->position()); | 1787 EXPECT_EQ(gfx::PointF(2.f, 2.f), child->position()); |
| 1791 | 1788 |
| 1792 // Compute all the layer transforms for the frame. | 1789 // Compute all the layer transforms for the frame. |
| 1793 LayerTreeHostImpl::FrameData frame_data; | 1790 LayerTreeHostImpl::FrameData frame_data; |
| 1794 impl->PrepareToDraw(&frame_data); | 1791 impl->PrepareToDraw(&frame_data); |
| 1795 impl->DidDrawAllLayers(frame_data); | 1792 impl->DidDrawAllLayers(frame_data); |
| 1796 | 1793 |
| (...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2864 ++expected_push_properties_child_impl_; | 2861 ++expected_push_properties_child_impl_; |
| 2865 ++expected_push_properties_grandchild_impl_; | 2862 ++expected_push_properties_grandchild_impl_; |
| 2866 ++expected_push_properties_child2_impl_; | 2863 ++expected_push_properties_child2_impl_; |
| 2867 ++expected_push_properties_grandchild2_impl_; | 2864 ++expected_push_properties_grandchild2_impl_; |
| 2868 break; | 2865 break; |
| 2869 case 5: | 2866 case 5: |
| 2870 // Tree doesn't change but the one leaf that always pushes is pushed. | 2867 // Tree doesn't change but the one leaf that always pushes is pushed. |
| 2871 ++expected_push_properties_grandchild2_impl_; | 2868 ++expected_push_properties_grandchild2_impl_; |
| 2872 break; | 2869 break; |
| 2873 case 6: | 2870 case 6: |
| 2874 // First child is removed. Structure of the tree changes here so swap | 2871 // First child is removed. Structure of the tree changes. |
| 2875 // some of the values. child_impl becomes child2_impl. | 2872 expected_push_properties_child_impl_ = 0; |
| 2876 expected_push_properties_child_impl_ = | 2873 expected_push_properties_grandchild_impl_ = 0; |
| 2877 expected_push_properties_child2_impl_; | |
| 2878 expected_push_properties_child2_impl_ = 0; | |
| 2879 // grandchild_impl becomes grandchild2_impl. | |
| 2880 expected_push_properties_grandchild_impl_ = | |
| 2881 expected_push_properties_grandchild2_impl_; | |
| 2882 expected_push_properties_grandchild2_impl_ = 0; | |
| 2883 | 2874 |
| 2884 // grandchild_impl is now the leaf that always pushes. It is pushed. | 2875 // The leaf that always pushes is pushed. |
| 2885 ++expected_push_properties_grandchild_impl_; | 2876 ++expected_push_properties_grandchild2_impl_; |
| 2886 break; | 2877 break; |
| 2887 case 7: | 2878 case 7: |
| 2888 // The leaf that always pushes is pushed. | 2879 // The leaf that always pushes is pushed. |
| 2889 ++expected_push_properties_grandchild_impl_; | 2880 ++expected_push_properties_grandchild2_impl_; |
| 2890 | 2881 |
| 2891 // Child is added back. New layers are initialized. | 2882 // Child is added back. New layers are initialized. |
| 2892 ++expected_push_properties_grandchild2_impl_; | 2883 ++expected_push_properties_grandchild_impl_; |
| 2893 ++expected_push_properties_child2_impl_; | 2884 ++expected_push_properties_child_impl_; |
| 2894 break; | 2885 break; |
| 2895 case 8: | 2886 case 8: |
| 2896 // Leaf is removed. | 2887 // Leaf is removed. |
| 2897 expected_push_properties_grandchild2_impl_ = 0; | 2888 expected_push_properties_grandchild_impl_ = 0; |
| 2898 | 2889 |
| 2899 // Always pushing. | 2890 // Always pushing. |
| 2900 ++expected_push_properties_grandchild_impl_; | 2891 ++expected_push_properties_grandchild2_impl_; |
| 2901 break; | 2892 break; |
| 2902 case 9: | 2893 case 9: |
| 2903 // Leaf is added back | 2894 // Leaf is added back |
| 2904 ++expected_push_properties_grandchild2_impl_; | 2895 ++expected_push_properties_grandchild_impl_; |
| 2905 | 2896 |
| 2906 // The leaf that always pushes is pushed. | 2897 // The leaf that always pushes is pushed. |
| 2907 ++expected_push_properties_grandchild_impl_; | 2898 ++expected_push_properties_grandchild2_impl_; |
| 2908 break; | 2899 break; |
| 2909 case 10: | 2900 case 10: |
| 2910 // The leaf that always pushes is pushed. | 2901 // The leaf that always pushes is pushed. |
| 2911 ++expected_push_properties_grandchild_impl_; | 2902 ++expected_push_properties_grandchild2_impl_; |
| 2912 break; | 2903 break; |
| 2913 case 11: | 2904 case 11: |
| 2914 // The leaf that always pushes is pushed. | 2905 // The leaf that always pushes is pushed. |
| 2915 ++expected_push_properties_grandchild_impl_; | 2906 ++expected_push_properties_grandchild2_impl_; |
| 2916 break; | 2907 break; |
| 2917 case 12: | 2908 case 12: |
| 2918 // The leaf that always pushes is pushed. | 2909 // The leaf that always pushes is pushed. |
| 2919 ++expected_push_properties_grandchild_impl_; | 2910 ++expected_push_properties_grandchild2_impl_; |
| 2920 | 2911 |
| 2921 // This child position was changed. So the subtree needs to push | 2912 // This child position was changed. So the subtree needs to push |
| 2922 // properties. | 2913 // properties. |
| 2923 ++expected_push_properties_child2_impl_; | 2914 ++expected_push_properties_child_impl_; |
| 2924 ++expected_push_properties_grandchild2_impl_; | 2915 ++expected_push_properties_grandchild_impl_; |
| 2925 break; | 2916 break; |
| 2926 case 13: | 2917 case 13: |
| 2927 // The position of this child was changed. | 2918 // The position of this child was changed. |
| 2928 ++expected_push_properties_child_impl_; | 2919 ++expected_push_properties_child2_impl_; |
| 2929 | 2920 |
| 2930 // The leaf that always pushes is pushed. | 2921 // The leaf that always pushes is pushed. |
| 2931 ++expected_push_properties_grandchild_impl_; | 2922 ++expected_push_properties_grandchild2_impl_; |
| 2932 break; | 2923 break; |
| 2933 case 14: | 2924 case 14: |
| 2934 // Second child is removed from tree. Don't discard counts because | 2925 // Second child is removed from tree. Don't discard counts because |
| 2935 // they are added back before commit. | 2926 // they are added back before commit. |
| 2936 | 2927 |
| 2937 // The leaf that always pushes is pushed. | 2928 // The leaf that always pushes is pushed. |
| 2938 ++expected_push_properties_grandchild_impl_; | 2929 ++expected_push_properties_grandchild2_impl_; |
| 2939 | 2930 |
| 2940 // Second child added back. | 2931 // Second child added back. |
| 2941 ++expected_push_properties_child2_impl_; | 2932 ++expected_push_properties_child_impl_; |
| 2942 ++expected_push_properties_grandchild2_impl_; | 2933 ++expected_push_properties_grandchild_impl_; |
| 2943 | 2934 |
| 2944 break; | 2935 break; |
| 2945 case 15: | 2936 case 15: |
| 2946 // The position of this child was changed. | 2937 // The position of this child was changed. |
| 2947 ++expected_push_properties_grandchild2_impl_; | 2938 ++expected_push_properties_grandchild_impl_; |
| 2948 | 2939 |
| 2949 // The leaf that always pushes is pushed. | 2940 // The leaf that always pushes is pushed. |
| 2950 ++expected_push_properties_grandchild_impl_; | 2941 ++expected_push_properties_grandchild2_impl_; |
| 2951 break; | 2942 break; |
| 2952 case 16: | 2943 case 16: |
| 2953 // Second child is invalidated with SetNeedsDisplay | 2944 // Second child is invalidated with SetNeedsDisplay |
| 2954 ++expected_push_properties_child2_impl_; | 2945 ++expected_push_properties_child_impl_; |
| 2955 | 2946 |
| 2956 // The leaf that always pushed is pushed. | 2947 // The leaf that always pushed is pushed. |
| 2957 ++expected_push_properties_grandchild_impl_; | 2948 ++expected_push_properties_grandchild2_impl_; |
| 2958 break; | 2949 break; |
| 2959 } | 2950 } |
| 2960 | 2951 |
| 2961 PushPropertiesCountingLayerImpl* root_impl_ = NULL; | 2952 PushPropertiesCountingLayerImpl* root_impl_ = NULL; |
| 2962 PushPropertiesCountingLayerImpl* child_impl_ = NULL; | 2953 PushPropertiesCountingLayerImpl* child_impl_ = NULL; |
| 2963 PushPropertiesCountingLayerImpl* child2_impl_ = NULL; | 2954 PushPropertiesCountingLayerImpl* child2_impl_ = NULL; |
| 2964 PushPropertiesCountingLayerImpl* grandchild_impl_ = NULL; | 2955 PushPropertiesCountingLayerImpl* grandchild_impl_ = NULL; |
| 2965 PushPropertiesCountingLayerImpl* leaf_always_pushing_layer_impl_ = NULL; | 2956 PushPropertiesCountingLayerImpl* leaf_always_pushing_layer_impl_ = NULL; |
| 2966 | 2957 |
| 2967 // Pull the layers that we need from the tree assuming the same structure | 2958 // Pull the layers that we need from the tree assuming the same structure |
| 2968 // as LayerTreeHostTestLayersPushProperties | 2959 // as LayerTreeHostTestLayersPushProperties |
| 2969 root_impl_ = static_cast<PushPropertiesCountingLayerImpl*>( | 2960 root_impl_ = static_cast<PushPropertiesCountingLayerImpl*>( |
| 2970 host_impl->RootLayer()); | 2961 host_impl->RootLayer()); |
| 2971 | 2962 |
| 2972 if (root_impl_ && root_impl_->children().size() > 0) { | 2963 LayerTreeImpl* impl = root_impl_->layer_tree_impl(); |
| 2964 if (impl->LayerById(child_->id())) { |
| 2973 child_impl_ = static_cast<PushPropertiesCountingLayerImpl*>( | 2965 child_impl_ = static_cast<PushPropertiesCountingLayerImpl*>( |
| 2974 root_impl_->children()[0]); | 2966 impl->LayerById(child_->id())); |
| 2975 | 2967 |
| 2976 if (child_impl_ && child_impl_->children().size() > 0) | 2968 if (impl->LayerById(grandchild_->id())) |
| 2977 grandchild_impl_ = static_cast<PushPropertiesCountingLayerImpl*>( | 2969 grandchild_impl_ = static_cast<PushPropertiesCountingLayerImpl*>( |
| 2978 child_impl_->children()[0]); | 2970 impl->LayerById(grandchild_->id())); |
| 2979 } | 2971 } |
| 2980 | 2972 |
| 2981 if (root_impl_ && root_impl_->children().size() > 1) { | 2973 if (impl->LayerById(child2_->id())) { |
| 2982 child2_impl_ = static_cast<PushPropertiesCountingLayerImpl*>( | 2974 child2_impl_ = static_cast<PushPropertiesCountingLayerImpl*>( |
| 2983 root_impl_->children()[1]); | 2975 impl->LayerById(child2_->id())); |
| 2984 | 2976 |
| 2985 if (child2_impl_ && child2_impl_->children().size() > 0) | 2977 if (impl->LayerById(leaf_always_pushing_layer_->id())) |
| 2986 leaf_always_pushing_layer_impl_ = | 2978 leaf_always_pushing_layer_impl_ = |
| 2987 static_cast<PushPropertiesCountingLayerImpl*>( | 2979 static_cast<PushPropertiesCountingLayerImpl*>( |
| 2988 child2_impl_->children()[0]); | 2980 impl->LayerById(leaf_always_pushing_layer_->id())); |
| 2989 } | 2981 } |
| 2990 | 2982 |
| 2991 if (root_impl_) | 2983 if (root_impl_) |
| 2992 EXPECT_EQ(expected_push_properties_root_impl_, | 2984 EXPECT_EQ(expected_push_properties_root_impl_, |
| 2993 root_impl_->push_properties_count()); | 2985 root_impl_->push_properties_count()); |
| 2994 if (child_impl_) | 2986 if (child_impl_) |
| 2995 EXPECT_EQ(expected_push_properties_child_impl_, | 2987 EXPECT_EQ(expected_push_properties_child_impl_, |
| 2996 child_impl_->push_properties_count()); | 2988 child_impl_->push_properties_count()); |
| 2997 if (grandchild_impl_) | 2989 if (grandchild_impl_) |
| 2998 EXPECT_EQ(expected_push_properties_grandchild_impl_, | 2990 EXPECT_EQ(expected_push_properties_grandchild_impl_, |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3695 // The bounds of the child layer were pushed to the impl side. | 3687 // The bounds of the child layer were pushed to the impl side. |
| 3696 EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( | 3688 EXPECT_FALSE(layer_tree_host()->LayerNeedsPushPropertiesForTesting( |
| 3697 child_layer_.get())); | 3689 child_layer_.get())); |
| 3698 | 3690 |
| 3699 EndTest(); | 3691 EndTest(); |
| 3700 break; | 3692 break; |
| 3701 } | 3693 } |
| 3702 } | 3694 } |
| 3703 | 3695 |
| 3704 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 3696 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| 3705 LayerImpl* root = impl->active_tree()->root_layer(); | 3697 LayerImpl* child = impl->active_tree()->LayerById(child_layer_->id()); |
| 3706 LayerImpl* parent = root->children()[0]; | |
| 3707 LayerImpl* child = parent->children()[0]; | |
| 3708 | 3698 |
| 3709 switch (impl->active_tree()->source_frame_number()) { | 3699 switch (impl->active_tree()->source_frame_number()) { |
| 3710 case 1: | 3700 case 1: |
| 3711 EXPECT_EQ(gfx::Size(5, 5).ToString(), child->bounds().ToString()); | 3701 EXPECT_EQ(gfx::Size(5, 5).ToString(), child->bounds().ToString()); |
| 3712 break; | 3702 break; |
| 3713 } | 3703 } |
| 3714 } | 3704 } |
| 3715 | 3705 |
| 3716 void AfterTest() override {} | 3706 void AfterTest() override {} |
| 3717 | 3707 |
| (...skipping 2590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6308 EndTest(); | 6298 EndTest(); |
| 6309 } | 6299 } |
| 6310 | 6300 |
| 6311 void AfterTest() override {} | 6301 void AfterTest() override {} |
| 6312 }; | 6302 }; |
| 6313 | 6303 |
| 6314 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPaintedDeviceScaleFactor); | 6304 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPaintedDeviceScaleFactor); |
| 6315 | 6305 |
| 6316 } // namespace | 6306 } // namespace |
| 6317 } // namespace cc | 6307 } // namespace cc |
| OLD | NEW |