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_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "cc/animation/layer_animation_controller.h" | 10 #include "cc/animation/layer_animation_controller.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "cc/test/fake_picture_layer.h" | 27 #include "cc/test/fake_picture_layer.h" |
28 #include "cc/test/fake_picture_layer_impl.h" | 28 #include "cc/test/fake_picture_layer_impl.h" |
29 #include "cc/test/geometry_test_utils.h" | 29 #include "cc/test/geometry_test_utils.h" |
30 #include "cc/test/layer_tree_host_common_test.h" | 30 #include "cc/test/layer_tree_host_common_test.h" |
31 #include "cc/trees/layer_tree_impl.h" | 31 #include "cc/trees/layer_tree_impl.h" |
32 #include "cc/trees/proxy.h" | 32 #include "cc/trees/proxy.h" |
33 #include "cc/trees/single_thread_proxy.h" | 33 #include "cc/trees/single_thread_proxy.h" |
34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
36 #include "ui/gfx/geometry/quad_f.h" | 36 #include "ui/gfx/geometry/quad_f.h" |
| 37 #include "ui/gfx/geometry/vector2d_conversions.h" |
37 #include "ui/gfx/transform.h" | 38 #include "ui/gfx/transform.h" |
38 | 39 |
39 namespace cc { | 40 namespace cc { |
40 namespace { | 41 namespace { |
41 | 42 |
42 class LayerWithForcedDrawsContent : public Layer { | 43 class LayerWithForcedDrawsContent : public Layer { |
43 public: | 44 public: |
44 LayerWithForcedDrawsContent() {} | 45 LayerWithForcedDrawsContent() {} |
45 | 46 |
46 bool DrawsContent() const override; | 47 bool DrawsContent() const override; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 scroll_layer->SetScrollClipLayer(clip_layer->id()); | 341 scroll_layer->SetScrollClipLayer(clip_layer->id()); |
341 clip_layer->SetBounds( | 342 clip_layer->SetBounds( |
342 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), | 343 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
343 scroll_layer->bounds().height() + kMaxScrollOffset.y())); | 344 scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
344 scroll_layer->SetScrollClipLayer(clip_layer->id()); | 345 scroll_layer->SetScrollClipLayer(clip_layer->id()); |
345 scroll_layer->SetScrollDelta(kScrollDelta); | 346 scroll_layer->SetScrollDelta(kScrollDelta); |
346 gfx::Transform impl_transform; | 347 gfx::Transform impl_transform; |
347 scroll_layer->AddChild(sublayer_scoped_ptr.Pass()); | 348 scroll_layer->AddChild(sublayer_scoped_ptr.Pass()); |
348 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); | 349 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
349 clip_layer->AddChild(scroll_layer_scoped_ptr.Pass()); | 350 clip_layer->AddChild(scroll_layer_scoped_ptr.Pass()); |
350 scroll_layer_raw_ptr->SetScrollOffset(kScrollOffset); | 351 scroll_layer_raw_ptr->PushScrollOffsetFromMainThread(kScrollOffset); |
351 | 352 |
352 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3)); | 353 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3)); |
353 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), | 354 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
354 gfx::PointF(), gfx::Size(3, 4), true, false, | 355 gfx::PointF(), gfx::Size(3, 4), true, false, |
355 false); | 356 false); |
356 root->AddChild(clip_layer_scoped_ptr.Pass()); | 357 root->AddChild(clip_layer_scoped_ptr.Pass()); |
357 root->SetHasRenderSurface(true); | 358 root->SetHasRenderSurface(true); |
358 | 359 |
359 ExecuteCalculateDrawProperties( | 360 ExecuteCalculateDrawProperties( |
360 root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); | 361 root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
(...skipping 7395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7756 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 7757 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
7757 | 7758 |
7758 EXPECT_VECTOR_EQ( | 7759 EXPECT_VECTOR_EQ( |
7759 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), | 7760 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
7760 container_offset); | 7761 container_offset); |
7761 | 7762 |
7762 scroll_layer->SetTransform(identity_transform); | 7763 scroll_layer->SetTransform(identity_transform); |
7763 } | 7764 } |
7764 } | 7765 } |
7765 | 7766 |
| 7767 TEST_F(LayerTreeHostCommonTest, |
| 7768 ScrollCompensationMainScrollOffsetFractionalPart) { |
| 7769 // This test verifies that a scrolling layer that has fractional scroll offset |
| 7770 // from main doesn't move a fixed position child. |
| 7771 // |
| 7772 // + root |
| 7773 // + container |
| 7774 // + scroller |
| 7775 // + fixed |
| 7776 // |
| 7777 FakeImplProxy proxy; |
| 7778 TestSharedBitmapManager shared_bitmap_manager; |
| 7779 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 7780 host_impl.CreatePendingTree(); |
| 7781 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7782 scoped_ptr<LayerImpl> container = |
| 7783 LayerImpl::Create(host_impl.active_tree(), 2); |
| 7784 LayerImpl* container_layer = container.get(); |
| 7785 scoped_ptr<LayerImpl> scroller = |
| 7786 LayerImpl::Create(host_impl.active_tree(), 3); |
| 7787 LayerImpl* scroll_layer = scroller.get(); |
| 7788 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 7789 LayerImpl* fixed_layer = fixed.get(); |
| 7790 |
| 7791 container->SetIsContainerForFixedPositionLayers(true); |
| 7792 |
| 7793 LayerPositionConstraint constraint; |
| 7794 constraint.set_is_fixed_position(true); |
| 7795 fixed->SetPositionConstraint(constraint); |
| 7796 |
| 7797 scroller->SetScrollClipLayer(container->id()); |
| 7798 |
| 7799 gfx::Transform identity_transform; |
| 7800 gfx::Transform container_transform; |
| 7801 container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7802 gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7803 |
| 7804 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 7805 gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7806 true); |
| 7807 SetLayerPropertiesForTesting(container.get(), container_transform, |
| 7808 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7809 true, false, false); |
| 7810 SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 7811 gfx::Point3F(), gfx::PointF(0.0, 0.0), |
| 7812 gfx::Size(30, 30), true, false, false); |
| 7813 |
| 7814 gfx::ScrollOffset scroll_offset(3.3, 4.2); |
| 7815 gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f); |
| 7816 gfx::Vector2dF scroll_delta(0.1f, 0.4f); |
| 7817 // Blink only uses the integer part of the scroll_offset for fixed |
| 7818 // position layer. |
| 7819 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 7820 gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true, |
| 7821 false, false); |
| 7822 scroll_layer->PushScrollOffsetFromMainThread(scroll_offset); |
| 7823 scroll_layer->SetScrollDelta(scroll_delta); |
| 7824 scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part); |
| 7825 |
| 7826 scroller->AddChild(fixed.Pass()); |
| 7827 container->AddChild(scroller.Pass()); |
| 7828 root->AddChild(container.Pass()); |
| 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_TRANSFORMATION_MATRIX_EQ( |
| 7836 container_layer->draw_properties().screen_space_transform, |
| 7837 fixed_layer->draw_properties().screen_space_transform); |
| 7838 EXPECT_VECTOR_EQ( |
| 7839 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7840 container_offset); |
| 7841 |
| 7842 gfx::ScrollOffset effective_scroll_offset = |
| 7843 ScrollOffsetWithDelta(scroll_offset, scroll_delta); |
| 7844 gfx::Vector2d rounded_effective_scroll_offset = |
| 7845 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset)); |
| 7846 EXPECT_VECTOR_EQ( |
| 7847 scroll_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7848 container_offset - rounded_effective_scroll_offset); |
| 7849 } |
| 7850 |
7766 class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { | 7851 class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
7767 public: | 7852 public: |
7768 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( | 7853 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
7769 LayerTreeImpl* tree_impl, | 7854 LayerTreeImpl* tree_impl, |
7770 int id) { | 7855 int id) { |
7771 return make_scoped_ptr( | 7856 return make_scoped_ptr( |
7772 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); | 7857 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
7773 } | 7858 } |
7774 | 7859 |
7775 ~AnimationScaleFactorTrackingLayerImpl() override {} | 7860 ~AnimationScaleFactorTrackingLayerImpl() override {} |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8582 | 8667 |
8583 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 8668 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
8584 | 8669 |
8585 gfx::Rect affected_by_delta(0, 0, root_size.width(), | 8670 gfx::Rect affected_by_delta(0, 0, root_size.width(), |
8586 root_size.height() + 50); | 8671 root_size.height() + 50); |
8587 EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect()); | 8672 EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect()); |
8588 } | 8673 } |
8589 | 8674 |
8590 } // namespace | 8675 } // namespace |
8591 } // namespace cc | 8676 } // namespace cc |
OLD | NEW |