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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "cc/trees/clip_node.h" | 44 #include "cc/trees/clip_node.h" |
45 #include "cc/trees/draw_property_utils.h" | 45 #include "cc/trees/draw_property_utils.h" |
46 #include "cc/trees/effect_node.h" | 46 #include "cc/trees/effect_node.h" |
47 #include "cc/trees/layer_tree_impl.h" | 47 #include "cc/trees/layer_tree_impl.h" |
48 #include "cc/trees/property_tree_builder.h" | 48 #include "cc/trees/property_tree_builder.h" |
49 #include "cc/trees/scroll_node.h" | 49 #include "cc/trees/scroll_node.h" |
50 #include "cc/trees/single_thread_proxy.h" | 50 #include "cc/trees/single_thread_proxy.h" |
51 #include "cc/trees/task_runner_provider.h" | 51 #include "cc/trees/task_runner_provider.h" |
52 #include "cc/trees/transform_node.h" | 52 #include "cc/trees/transform_node.h" |
53 #include "testing/gtest/include/gtest/gtest.h" | 53 #include "testing/gtest/include/gtest/gtest.h" |
54 #include "third_party/skia/include/core/SkImageFilter.h" | |
55 #include "third_party/skia/include/effects/SkOffsetImageFilter.h" | 54 #include "third_party/skia/include/effects/SkOffsetImageFilter.h" |
56 #include "third_party/skia/include/effects/SkXfermodeImageFilter.h" | |
57 #include "ui/gfx/geometry/quad_f.h" | 55 #include "ui/gfx/geometry/quad_f.h" |
58 #include "ui/gfx/geometry/vector2d_conversions.h" | 56 #include "ui/gfx/geometry/vector2d_conversions.h" |
59 #include "ui/gfx/transform.h" | 57 #include "ui/gfx/transform.h" |
60 | 58 |
61 namespace cc { | 59 namespace cc { |
62 namespace { | 60 namespace { |
63 | 61 |
64 class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings { | 62 class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings { |
65 public: | 63 public: |
66 VerifyTreeCalcsLayerTreeSettings() { | 64 VerifyTreeCalcsLayerTreeSettings() { |
(...skipping 3031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3098 child->SetMasksToBounds(true); | 3096 child->SetMasksToBounds(true); |
3099 grand_child->test_properties()->transform = grand_child_scale_matrix; | 3097 grand_child->test_properties()->transform = grand_child_scale_matrix; |
3100 grand_child->SetBounds(gfx::Size(100, 100)); | 3098 grand_child->SetBounds(gfx::Size(100, 100)); |
3101 grand_child->SetDrawsContent(true); | 3099 grand_child->SetDrawsContent(true); |
3102 ExecuteCalculateDrawProperties(root); | 3100 ExecuteCalculateDrawProperties(root); |
3103 | 3101 |
3104 // The visible rect is expanded to integer coordinates. | 3102 // The visible rect is expanded to integer coordinates. |
3105 EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect()); | 3103 EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect()); |
3106 } | 3104 } |
3107 | 3105 |
3108 TEST_F(LayerTreeHostCommonTest, VisibleRectWithClippingAndFilters) { | |
3109 LayerImpl* root = root_layer_for_testing(); | |
3110 LayerImpl* clip = AddChild<LayerImpl>(root); | |
3111 LayerImpl* filter = AddChild<LayerImpl>(clip); | |
3112 LayerImpl* filter_child = AddChild<LayerImpl>(filter); | |
3113 | |
3114 root->SetBounds(gfx::Size(100, 100)); | |
3115 clip->SetBounds(gfx::Size(10, 10)); | |
3116 filter->test_properties()->force_render_surface = true; | |
3117 filter_child->SetBounds(gfx::Size(2000, 2000)); | |
3118 filter_child->SetPosition(gfx::PointF(-50, -50)); | |
3119 filter_child->SetDrawsContent(true); | |
3120 | |
3121 clip->SetMasksToBounds(true); | |
3122 | |
3123 ExecuteCalculateDrawProperties(root); | |
3124 EXPECT_EQ(gfx::Rect(50, 50, 10, 10), filter_child->visible_layer_rect()); | |
3125 EXPECT_EQ(gfx::Rect(10, 10), filter->render_surface()->content_rect()); | |
3126 | |
3127 FilterOperations blur_filter; | |
3128 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f)); | |
3129 filter->test_properties()->filters = blur_filter; | |
3130 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
3131 | |
3132 ExecuteCalculateDrawProperties(root); | |
3133 | |
3134 EXPECT_EQ(gfx::Rect(38, 38, 34, 34), filter_child->visible_layer_rect()); | |
3135 EXPECT_EQ(gfx::Rect(-12, -12, 34, 34), | |
3136 filter->render_surface()->content_rect()); | |
3137 | |
3138 gfx::Transform vertical_flip; | |
3139 vertical_flip.Scale(1, -1); | |
3140 sk_sp<SkImageFilter> flip_filter = SkImageFilter::MakeMatrixFilter( | |
3141 vertical_flip.matrix(), kLow_SkFilterQuality, nullptr); | |
3142 FilterOperations reflection_filter; | |
3143 reflection_filter.Append( | |
3144 FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make( | |
3145 SkBlendMode::kSrcOver, std::move(flip_filter)))); | |
3146 filter->test_properties()->filters = reflection_filter; | |
3147 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
3148 | |
3149 ExecuteCalculateDrawProperties(root); | |
3150 | |
3151 EXPECT_EQ(gfx::Rect(50, 40, 10, 20), filter_child->visible_layer_rect()); | |
3152 EXPECT_EQ(gfx::Rect(0, -10, 10, 20), | |
3153 filter->render_surface()->content_rect()); | |
3154 } | |
3155 | |
3156 TEST_F(LayerTreeHostCommonTest, VisibleRectWithScalingClippingAndFilters) { | |
3157 LayerImpl* root = root_layer_for_testing(); | |
3158 LayerImpl* scale = AddChild<LayerImpl>(root); | |
3159 LayerImpl* clip = AddChild<LayerImpl>(scale); | |
3160 LayerImpl* filter = AddChild<LayerImpl>(clip); | |
3161 LayerImpl* filter_child = AddChild<LayerImpl>(filter); | |
3162 | |
3163 root->SetBounds(gfx::Size(100, 100)); | |
3164 clip->SetBounds(gfx::Size(10, 10)); | |
3165 filter->test_properties()->force_render_surface = true; | |
3166 filter_child->SetBounds(gfx::Size(2000, 2000)); | |
3167 filter_child->SetPosition(gfx::PointF(-50, -50)); | |
3168 filter_child->SetDrawsContent(true); | |
3169 | |
3170 clip->SetMasksToBounds(true); | |
3171 | |
3172 gfx::Transform scale_transform; | |
3173 scale_transform.Scale(3, 3); | |
3174 scale->test_properties()->transform = scale_transform; | |
3175 | |
3176 ExecuteCalculateDrawProperties(root); | |
3177 EXPECT_EQ(gfx::Rect(50, 50, 10, 10), filter_child->visible_layer_rect()); | |
3178 EXPECT_EQ(gfx::Rect(30, 30), filter->render_surface()->content_rect()); | |
3179 | |
3180 FilterOperations blur_filter; | |
3181 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f)); | |
3182 filter->test_properties()->filters = blur_filter; | |
3183 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
3184 | |
3185 ExecuteCalculateDrawProperties(root); | |
3186 | |
3187 EXPECT_EQ(gfx::Rect(38, 38, 34, 34), filter_child->visible_layer_rect()); | |
3188 EXPECT_EQ(gfx::Rect(-36, -36, 102, 102), | |
3189 filter->render_surface()->content_rect()); | |
3190 | |
3191 gfx::Transform vertical_flip; | |
3192 vertical_flip.Scale(1, -1); | |
3193 sk_sp<SkImageFilter> flip_filter = SkImageFilter::MakeMatrixFilter( | |
3194 vertical_flip.matrix(), kLow_SkFilterQuality, nullptr); | |
3195 FilterOperations reflection_filter; | |
3196 reflection_filter.Append( | |
3197 FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make( | |
3198 SkBlendMode::kSrcOver, std::move(flip_filter)))); | |
3199 filter->test_properties()->filters = reflection_filter; | |
3200 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
3201 | |
3202 ExecuteCalculateDrawProperties(root); | |
3203 | |
3204 EXPECT_EQ(gfx::Rect(50, 40, 10, 20), filter_child->visible_layer_rect()); | |
3205 EXPECT_EQ(gfx::Rect(0, -30, 30, 60), | |
3206 filter->render_surface()->content_rect()); | |
3207 } | |
3208 | |
3209 TEST_F(LayerTreeHostCommonTest, ClipRectWithClipParentAndFilters) { | |
3210 LayerImpl* root = root_layer_for_testing(); | |
3211 LayerImpl* clip = AddChild<LayerImpl>(root); | |
3212 LayerImpl* filter = AddChild<LayerImpl>(clip); | |
3213 LayerImpl* filter_child_1 = AddChild<LayerImpl>(filter); | |
3214 LayerImpl* filter_child_2 = AddChild<LayerImpl>(filter); | |
3215 | |
3216 root->SetBounds(gfx::Size(100, 100)); | |
3217 clip->SetBounds(gfx::Size(10, 10)); | |
3218 filter->test_properties()->force_render_surface = true; | |
3219 | |
3220 filter_child_1->SetBounds(gfx::Size(20, 20)); | |
3221 filter_child_1->SetDrawsContent(true); | |
3222 filter_child_2->SetBounds(gfx::Size(20, 20)); | |
3223 filter_child_2->SetDrawsContent(true); | |
3224 | |
3225 root->SetMasksToBounds(true); | |
3226 clip->SetMasksToBounds(true); | |
3227 | |
3228 root->test_properties()->clip_children = | |
3229 base::MakeUnique<std::set<LayerImpl*>>(); | |
3230 root->test_properties()->clip_children->insert(filter_child_1); | |
3231 filter_child_1->test_properties()->clip_parent = root; | |
3232 | |
3233 ExecuteCalculateDrawProperties(root); | |
3234 EXPECT_TRUE(filter_child_1->is_clipped()); | |
3235 EXPECT_TRUE(filter_child_2->is_clipped()); | |
3236 EXPECT_EQ(gfx::Rect(100, 100), filter_child_1->clip_rect()); | |
3237 EXPECT_EQ(gfx::Rect(10, 10), filter_child_2->clip_rect()); | |
3238 | |
3239 FilterOperations blur_filter; | |
3240 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f)); | |
3241 filter->test_properties()->filters = blur_filter; | |
3242 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
3243 | |
3244 ExecuteCalculateDrawProperties(root); | |
3245 | |
3246 EXPECT_TRUE(filter_child_1->is_clipped()); | |
3247 EXPECT_TRUE(filter_child_2->is_clipped()); | |
3248 EXPECT_EQ(gfx::Rect(100, 100), filter_child_1->clip_rect()); | |
3249 EXPECT_EQ(gfx::Rect(10, 10), filter_child_2->clip_rect()); | |
3250 } | |
3251 | |
3252 TEST_F(LayerTreeHostCommonTest, ClipRectWithClippedDescendantOfFilter) { | |
3253 LayerImpl* root = root_layer_for_testing(); | |
3254 LayerImpl* filter = AddChild<LayerImpl>(root); | |
3255 LayerImpl* clip = AddChild<LayerImpl>(filter); | |
3256 LayerImpl* filter_grand_child = AddChild<LayerImpl>(clip); | |
3257 | |
3258 root->SetBounds(gfx::Size(100, 100)); | |
3259 filter->test_properties()->force_render_surface = true; | |
3260 | |
3261 clip->SetBounds(gfx::Size(10, 10)); | |
3262 clip->SetMasksToBounds(true); | |
3263 | |
3264 filter_grand_child->SetBounds(gfx::Size(20, 20)); | |
3265 filter_grand_child->SetDrawsContent(true); | |
3266 | |
3267 ExecuteCalculateDrawProperties(root); | |
3268 EXPECT_TRUE(filter_grand_child->is_clipped()); | |
3269 EXPECT_EQ(gfx::Rect(10, 10), filter_grand_child->clip_rect()); | |
3270 | |
3271 FilterOperations blur_filter; | |
3272 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f)); | |
3273 filter->test_properties()->filters = blur_filter; | |
3274 host_impl()->active_tree()->property_trees()->needs_rebuild = true; | |
3275 | |
3276 ExecuteCalculateDrawProperties(root); | |
3277 | |
3278 EXPECT_TRUE(filter_grand_child->is_clipped()); | |
3279 EXPECT_EQ(gfx::Rect(10, 10), filter_grand_child->clip_rect()); | |
3280 } | |
3281 | |
3282 TEST_F(LayerTreeHostCommonTest, | 3106 TEST_F(LayerTreeHostCommonTest, |
3283 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { | 3107 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
3284 LayerImpl* root = root_layer_for_testing(); | 3108 LayerImpl* root = root_layer_for_testing(); |
3285 LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); | 3109 LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
3286 LayerImpl* child1 = AddChild<LayerImpl>(render_surface); | 3110 LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
3287 LayerImpl* child2 = AddChild<LayerImpl>(render_surface); | 3111 LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
3288 LayerImpl* child3 = AddChild<LayerImpl>(render_surface); | 3112 LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
3289 | 3113 |
3290 root->SetBounds(gfx::Size(100, 100)); | 3114 root->SetBounds(gfx::Size(100, 100)); |
3291 render_surface->SetBounds(gfx::Size(3, 4)); | 3115 render_surface->SetBounds(gfx::Size(3, 4)); |
(...skipping 7336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10628 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); | 10452 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
10629 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); | 10453 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
10630 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); | 10454 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
10631 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); | 10455 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
10632 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); | 10456 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
10633 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); | 10457 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
10634 } | 10458 } |
10635 | 10459 |
10636 } // namespace | 10460 } // namespace |
10637 } // namespace cc | 10461 } // namespace cc |
OLD | NEW |