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 "cc/trees/occlusion_tracker.h" | 5 #include "cc/trees/occlusion_tracker.h" |
6 | 6 |
7 #include "cc/animation/layer_animation_controller.h" | 7 #include "cc/animation/layer_animation_controller.h" |
8 #include "cc/base/math_util.h" | 8 #include "cc/base/math_util.h" |
9 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
10 #include "cc/layers/layer_impl.h" | 10 #include "cc/layers/layer_impl.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 gfx::Rect UnoccludedLayerContentRect(const LayerType* layer, | 94 gfx::Rect UnoccludedLayerContentRect(const LayerType* layer, |
95 const gfx::Rect& content_rect) const { | 95 const gfx::Rect& content_rect) const { |
96 DCHECK(layer->visible_content_rect().Contains(content_rect)); | 96 DCHECK(layer->visible_content_rect().Contains(content_rect)); |
97 return this->GetCurrentOcclusionForLayer(layer->draw_transform()) | 97 return this->GetCurrentOcclusionForLayer(layer->draw_transform()) |
98 .GetUnoccludedContentRect(content_rect); | 98 .GetUnoccludedContentRect(content_rect); |
99 } | 99 } |
100 | 100 |
101 gfx::Rect UnoccludedSurfaceContentRect(const LayerType* layer, | 101 gfx::Rect UnoccludedSurfaceContentRect(const LayerType* layer, |
102 const gfx::Rect& content_rect) const { | 102 const gfx::Rect& content_rect) const { |
103 typename LayerType::RenderSurfaceType* surface = layer->render_surface(); | 103 typename LayerType::RenderSurfaceType* surface = layer->render_surface(); |
104 return this->UnoccludedContributingSurfaceContentRect( | 104 return this->GetCurrentOcclusionForContributingSurface( |
105 content_rect, surface->draw_transform()); | 105 surface->draw_transform()) |
| 106 .GetUnoccludedContentRect(content_rect); |
106 } | 107 } |
107 }; | 108 }; |
108 | 109 |
109 struct OcclusionTrackerTestMainThreadTypes { | 110 struct OcclusionTrackerTestMainThreadTypes { |
110 typedef Layer LayerType; | 111 typedef Layer LayerType; |
111 typedef FakeLayerTreeHost HostType; | 112 typedef FakeLayerTreeHost HostType; |
112 typedef RenderSurface RenderSurfaceType; | 113 typedef RenderSurface RenderSurfaceType; |
113 typedef TestContentLayer ContentLayerType; | 114 typedef TestContentLayer ContentLayerType; |
114 typedef scoped_refptr<Layer> LayerPtrType; | 115 typedef scoped_refptr<Layer> LayerPtrType; |
115 typedef scoped_refptr<ContentLayerType> ContentLayerPtrType; | 116 typedef scoped_refptr<ContentLayerType> ContentLayerPtrType; |
(...skipping 2548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2664 ASSERT_LT(i, actual_occlusion.GetRegionComplexity()); | 2665 ASSERT_LT(i, actual_occlusion.GetRegionComplexity()); |
2665 EXPECT_EQ(expected_occlusion.GetRect(i), actual_occlusion.GetRect(i)); | 2666 EXPECT_EQ(expected_occlusion.GetRect(i), actual_occlusion.GetRect(i)); |
2666 } | 2667 } |
2667 } | 2668 } |
2668 }; | 2669 }; |
2669 | 2670 |
2670 ALL_OCCLUSIONTRACKER_TEST( | 2671 ALL_OCCLUSIONTRACKER_TEST( |
2671 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded); | 2672 OcclusionTrackerTestReduceOcclusionWhenBackgroundFilterIsPartiallyOccluded); |
2672 | 2673 |
2673 template <class Types> | 2674 template <class Types> |
| 2675 class OcclusionTrackerTestBlendModeDoesNotOcclude |
| 2676 : public OcclusionTrackerTest<Types> { |
| 2677 protected: |
| 2678 explicit OcclusionTrackerTestBlendModeDoesNotOcclude(bool opaque_layers) |
| 2679 : OcclusionTrackerTest<Types>(opaque_layers) {} |
| 2680 void RunMyTest() override { |
| 2681 typename Types::ContentLayerType* parent = this->CreateRoot( |
| 2682 this->identity_matrix, gfx::PointF(), gfx::Size(100, 100)); |
| 2683 typename Types::LayerType* blend_mode_layer = this->CreateDrawingLayer( |
| 2684 parent, this->identity_matrix, gfx::PointF(0.f, 0.f), |
| 2685 gfx::Size(100, 100), true); |
| 2686 typename Types::LayerType* top_layer = this->CreateDrawingLayer( |
| 2687 parent, this->identity_matrix, gfx::PointF(10.f, 12.f), |
| 2688 gfx::Size(20, 22), true); |
| 2689 |
| 2690 // Blend mode makes the layer own a surface. |
| 2691 Types::SetForceRenderSurface(blend_mode_layer, true); |
| 2692 blend_mode_layer->SetBlendMode(SkXfermode::kMultiply_Mode); |
| 2693 |
| 2694 this->CalcDrawEtc(parent); |
| 2695 |
| 2696 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion( |
| 2697 gfx::Rect(0, 0, 1000, 1000)); |
| 2698 |
| 2699 this->VisitLayer(top_layer, &occlusion); |
| 2700 // |top_layer| occludes. |
| 2701 EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(), |
| 2702 occlusion.occlusion_from_inside_target().ToString()); |
| 2703 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 2704 |
| 2705 this->VisitLayer(blend_mode_layer, &occlusion); |
| 2706 // |top_layer| occludes but not |blend_mode_layer|. |
| 2707 EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(), |
| 2708 occlusion.occlusion_from_outside_target().ToString()); |
| 2709 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); |
| 2710 |
| 2711 this->VisitContributingSurface(blend_mode_layer, &occlusion); |
| 2712 // |top_layer| occludes but not |blend_mode_layer|. |
| 2713 EXPECT_EQ(gfx::Rect(10, 12, 20, 22).ToString(), |
| 2714 occlusion.occlusion_from_inside_target().ToString()); |
| 2715 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 2716 } |
| 2717 }; |
| 2718 |
| 2719 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestBlendModeDoesNotOcclude); |
| 2720 |
| 2721 template <class Types> |
2674 class OcclusionTrackerTestMinimumTrackingSize | 2722 class OcclusionTrackerTestMinimumTrackingSize |
2675 : public OcclusionTrackerTest<Types> { | 2723 : public OcclusionTrackerTest<Types> { |
2676 protected: | 2724 protected: |
2677 explicit OcclusionTrackerTestMinimumTrackingSize(bool opaque_layers) | 2725 explicit OcclusionTrackerTestMinimumTrackingSize(bool opaque_layers) |
2678 : OcclusionTrackerTest<Types>(opaque_layers) {} | 2726 : OcclusionTrackerTest<Types>(opaque_layers) {} |
2679 void RunMyTest() override { | 2727 void RunMyTest() override { |
2680 gfx::Size tracking_size(100, 100); | 2728 gfx::Size tracking_size(100, 100); |
2681 gfx::Size below_tracking_size(99, 99); | 2729 gfx::Size below_tracking_size(99, 99); |
2682 | 2730 |
2683 typename Types::ContentLayerType* parent = this->CreateRoot( | 2731 typename Types::ContentLayerType* parent = this->CreateRoot( |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2809 this->identity_matrix, | 2857 this->identity_matrix, |
2810 gfx::Point(100, 0), | 2858 gfx::Point(100, 0), |
2811 gfx::Size(200, 400)); | 2859 gfx::Size(200, 400)); |
2812 this->AddCopyRequest(copy); | 2860 this->AddCopyRequest(copy); |
2813 typename Types::LayerType* copy_child = this->CreateDrawingLayer( | 2861 typename Types::LayerType* copy_child = this->CreateDrawingLayer( |
2814 copy, | 2862 copy, |
2815 this->identity_matrix, | 2863 this->identity_matrix, |
2816 gfx::PointF(), | 2864 gfx::PointF(), |
2817 gfx::Size(200, 400), | 2865 gfx::Size(200, 400), |
2818 true); | 2866 true); |
| 2867 typename Types::LayerType* top_layer = |
| 2868 this->CreateDrawingLayer(root, this->identity_matrix, |
| 2869 gfx::PointF(50, 0), gfx::Size(50, 400), true); |
2819 this->CalcDrawEtc(root); | 2870 this->CalcDrawEtc(root); |
2820 | 2871 |
2821 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion( | 2872 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion( |
2822 gfx::Rect(0, 0, 1000, 1000)); | 2873 gfx::Rect(0, 0, 1000, 1000)); |
2823 | 2874 |
| 2875 this->VisitLayer(top_layer, &occlusion); |
| 2876 EXPECT_EQ(gfx::Rect().ToString(), |
| 2877 occlusion.occlusion_from_outside_target().ToString()); |
| 2878 EXPECT_EQ(gfx::Rect(50, 0, 50, 400).ToString(), |
| 2879 occlusion.occlusion_from_inside_target().ToString()); |
| 2880 |
2824 this->VisitLayer(copy_child, &occlusion); | 2881 this->VisitLayer(copy_child, &occlusion); |
| 2882 // Layers outside the copy request do not occlude. |
2825 EXPECT_EQ(gfx::Rect().ToString(), | 2883 EXPECT_EQ(gfx::Rect().ToString(), |
2826 occlusion.occlusion_from_outside_target().ToString()); | 2884 occlusion.occlusion_from_outside_target().ToString()); |
2827 EXPECT_EQ(gfx::Rect(200, 400).ToString(), | 2885 EXPECT_EQ(gfx::Rect(200, 400).ToString(), |
2828 occlusion.occlusion_from_inside_target().ToString()); | 2886 occlusion.occlusion_from_inside_target().ToString()); |
2829 | 2887 |
2830 // CopyRequests cause the layer to own a surface. | 2888 // CopyRequests cause the layer to own a surface. |
2831 this->VisitContributingSurface(copy, &occlusion); | 2889 this->VisitContributingSurface(copy, &occlusion); |
2832 | 2890 |
2833 // The occlusion from the copy should be kept. | 2891 // The occlusion from the copy should be kept. |
2834 EXPECT_EQ(gfx::Rect().ToString(), | 2892 EXPECT_EQ(gfx::Rect().ToString(), |
2835 occlusion.occlusion_from_outside_target().ToString()); | 2893 occlusion.occlusion_from_outside_target().ToString()); |
2836 EXPECT_EQ(gfx::Rect(100, 0, 200, 400).ToString(), | 2894 EXPECT_EQ(gfx::Rect(50, 0, 250, 400).ToString(), |
2837 occlusion.occlusion_from_inside_target().ToString()); | 2895 occlusion.occlusion_from_inside_target().ToString()); |
2838 } | 2896 } |
2839 }; | 2897 }; |
2840 | 2898 |
2841 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestCopyRequestDoesOcclude) | 2899 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestCopyRequestDoesOcclude) |
2842 | 2900 |
2843 template <class Types> | 2901 template <class Types> |
2844 class OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude | 2902 class OcclusionTrackerTestHiddenCopyRequestDoesNotOcclude |
2845 : public OcclusionTrackerTest<Types> { | 2903 : public OcclusionTrackerTest<Types> { |
2846 protected: | 2904 protected: |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3315 EXPECT_EQ(gfx::Rect(), | 3373 EXPECT_EQ(gfx::Rect(), |
3316 occlusion.UnoccludedSurfaceContentRect( | 3374 occlusion.UnoccludedSurfaceContentRect( |
3317 surface, gfx::Rect(80, 70, 50, 50))); | 3375 surface, gfx::Rect(80, 70, 50, 50))); |
3318 } | 3376 } |
3319 }; | 3377 }; |
3320 | 3378 |
3321 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedSurfaceQuery) | 3379 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedSurfaceQuery) |
3322 | 3380 |
3323 } // namespace | 3381 } // namespace |
3324 } // namespace cc | 3382 } // namespace cc |
OLD | NEW |