Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1102)

Side by Side Diff: cc/trees/layer_tree_host_common_unittest.cc

Issue 2423483003: cc: Make visible rect computation aware of pixel-moving filters (Closed)
Patch Set: It's 2017 -- update copyright for new files Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/draw_property_utils.cc ('k') | cc/trees/property_tree_builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "cc/trees/clip_node.h" 42 #include "cc/trees/clip_node.h"
43 #include "cc/trees/draw_property_utils.h" 43 #include "cc/trees/draw_property_utils.h"
44 #include "cc/trees/effect_node.h" 44 #include "cc/trees/effect_node.h"
45 #include "cc/trees/layer_tree_impl.h" 45 #include "cc/trees/layer_tree_impl.h"
46 #include "cc/trees/property_tree_builder.h" 46 #include "cc/trees/property_tree_builder.h"
47 #include "cc/trees/scroll_node.h" 47 #include "cc/trees/scroll_node.h"
48 #include "cc/trees/single_thread_proxy.h" 48 #include "cc/trees/single_thread_proxy.h"
49 #include "cc/trees/task_runner_provider.h" 49 #include "cc/trees/task_runner_provider.h"
50 #include "cc/trees/transform_node.h" 50 #include "cc/trees/transform_node.h"
51 #include "testing/gtest/include/gtest/gtest.h" 51 #include "testing/gtest/include/gtest/gtest.h"
52 #include "third_party/skia/include/core/SkImageFilter.h"
52 #include "third_party/skia/include/effects/SkOffsetImageFilter.h" 53 #include "third_party/skia/include/effects/SkOffsetImageFilter.h"
54 #include "third_party/skia/include/effects/SkXfermodeImageFilter.h"
53 #include "ui/gfx/geometry/quad_f.h" 55 #include "ui/gfx/geometry/quad_f.h"
54 #include "ui/gfx/geometry/vector2d_conversions.h" 56 #include "ui/gfx/geometry/vector2d_conversions.h"
55 #include "ui/gfx/transform.h" 57 #include "ui/gfx/transform.h"
56 58
57 namespace cc { 59 namespace cc {
58 namespace { 60 namespace {
59 61
60 class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings { 62 class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings {
61 public: 63 public:
62 VerifyTreeCalcsLayerTreeSettings() { 64 VerifyTreeCalcsLayerTreeSettings() {
(...skipping 3049 matching lines...) Expand 10 before | Expand all | Expand 10 after
3112 child->SetMasksToBounds(true); 3114 child->SetMasksToBounds(true);
3113 grand_child->test_properties()->transform = grand_child_scale_matrix; 3115 grand_child->test_properties()->transform = grand_child_scale_matrix;
3114 grand_child->SetBounds(gfx::Size(100, 100)); 3116 grand_child->SetBounds(gfx::Size(100, 100));
3115 grand_child->SetDrawsContent(true); 3117 grand_child->SetDrawsContent(true);
3116 ExecuteCalculateDrawProperties(root); 3118 ExecuteCalculateDrawProperties(root);
3117 3119
3118 // The visible rect is expanded to integer coordinates. 3120 // The visible rect is expanded to integer coordinates.
3119 EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect()); 3121 EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect());
3120 } 3122 }
3121 3123
3124 TEST_F(LayerTreeHostCommonTest, VisibleRectWithClippingAndFilters) {
3125 LayerImpl* root = root_layer_for_testing();
3126 LayerImpl* clip = AddChild<LayerImpl>(root);
3127 LayerImpl* filter = AddChild<LayerImpl>(clip);
3128 LayerImpl* filter_child = AddChild<LayerImpl>(filter);
3129
3130 root->SetBounds(gfx::Size(100, 100));
3131 clip->SetBounds(gfx::Size(10, 10));
3132 filter->test_properties()->force_render_surface = true;
3133 filter_child->SetBounds(gfx::Size(2000, 2000));
3134 filter_child->SetPosition(gfx::PointF(-50, -50));
3135 filter_child->SetDrawsContent(true);
3136
3137 clip->SetMasksToBounds(true);
3138
3139 ExecuteCalculateDrawProperties(root);
3140 EXPECT_EQ(gfx::Rect(50, 50, 10, 10), filter_child->visible_layer_rect());
3141 EXPECT_EQ(gfx::Rect(10, 10), filter->render_surface()->content_rect());
3142
3143 FilterOperations blur_filter;
3144 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
3145 filter->test_properties()->filters = blur_filter;
3146 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3147
3148 ExecuteCalculateDrawProperties(root);
3149
3150 EXPECT_EQ(gfx::Rect(38, 38, 34, 34), filter_child->visible_layer_rect());
3151 EXPECT_EQ(gfx::Rect(-12, -12, 34, 34),
3152 filter->render_surface()->content_rect());
3153
3154 gfx::Transform vertical_flip;
3155 vertical_flip.Scale(1, -1);
3156 sk_sp<SkImageFilter> flip_filter = SkImageFilter::MakeMatrixFilter(
3157 vertical_flip.matrix(), kLow_SkFilterQuality, nullptr);
3158 FilterOperations reflection_filter;
3159 reflection_filter.Append(
3160 FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make(
3161 SkBlendMode::kSrcOver, std::move(flip_filter))));
3162 filter->test_properties()->filters = reflection_filter;
3163 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3164
3165 ExecuteCalculateDrawProperties(root);
3166
3167 EXPECT_EQ(gfx::Rect(50, 40, 10, 20), filter_child->visible_layer_rect());
3168 EXPECT_EQ(gfx::Rect(0, -10, 10, 20),
3169 filter->render_surface()->content_rect());
3170 }
3171
3172 TEST_F(LayerTreeHostCommonTest, VisibleRectWithScalingClippingAndFilters) {
3173 LayerImpl* root = root_layer_for_testing();
3174 LayerImpl* scale = AddChild<LayerImpl>(root);
3175 LayerImpl* clip = AddChild<LayerImpl>(scale);
3176 LayerImpl* filter = AddChild<LayerImpl>(clip);
3177 LayerImpl* filter_child = AddChild<LayerImpl>(filter);
3178
3179 root->SetBounds(gfx::Size(100, 100));
3180 clip->SetBounds(gfx::Size(10, 10));
3181 filter->test_properties()->force_render_surface = true;
3182 filter_child->SetBounds(gfx::Size(2000, 2000));
3183 filter_child->SetPosition(gfx::PointF(-50, -50));
3184 filter_child->SetDrawsContent(true);
3185
3186 clip->SetMasksToBounds(true);
3187
3188 gfx::Transform scale_transform;
3189 scale_transform.Scale(3, 3);
3190 scale->test_properties()->transform = scale_transform;
3191
3192 ExecuteCalculateDrawProperties(root);
3193 EXPECT_EQ(gfx::Rect(50, 50, 10, 10), filter_child->visible_layer_rect());
3194 EXPECT_EQ(gfx::Rect(30, 30), filter->render_surface()->content_rect());
3195
3196 FilterOperations blur_filter;
3197 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
3198 filter->test_properties()->filters = blur_filter;
3199 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3200
3201 ExecuteCalculateDrawProperties(root);
3202
3203 EXPECT_EQ(gfx::Rect(38, 38, 34, 34), filter_child->visible_layer_rect());
3204 EXPECT_EQ(gfx::Rect(-36, -36, 102, 102),
3205 filter->render_surface()->content_rect());
3206
3207 gfx::Transform vertical_flip;
3208 vertical_flip.Scale(1, -1);
3209 sk_sp<SkImageFilter> flip_filter = SkImageFilter::MakeMatrixFilter(
3210 vertical_flip.matrix(), kLow_SkFilterQuality, nullptr);
3211 FilterOperations reflection_filter;
3212 reflection_filter.Append(
3213 FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make(
3214 SkBlendMode::kSrcOver, std::move(flip_filter))));
3215 filter->test_properties()->filters = reflection_filter;
3216 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3217
3218 ExecuteCalculateDrawProperties(root);
3219
3220 EXPECT_EQ(gfx::Rect(50, 40, 10, 20), filter_child->visible_layer_rect());
3221 EXPECT_EQ(gfx::Rect(0, -30, 30, 60),
3222 filter->render_surface()->content_rect());
3223 }
3224
3225 TEST_F(LayerTreeHostCommonTest, ClipRectWithClipParentAndFilters) {
3226 LayerImpl* root = root_layer_for_testing();
3227 LayerImpl* clip = AddChild<LayerImpl>(root);
3228 LayerImpl* filter = AddChild<LayerImpl>(clip);
3229 LayerImpl* filter_child_1 = AddChild<LayerImpl>(filter);
3230 LayerImpl* filter_child_2 = AddChild<LayerImpl>(filter);
3231
3232 root->SetBounds(gfx::Size(100, 100));
3233 clip->SetBounds(gfx::Size(10, 10));
3234 filter->test_properties()->force_render_surface = true;
3235
3236 filter_child_1->SetBounds(gfx::Size(20, 20));
3237 filter_child_1->SetDrawsContent(true);
3238 filter_child_2->SetBounds(gfx::Size(20, 20));
3239 filter_child_2->SetDrawsContent(true);
3240
3241 root->SetMasksToBounds(true);
3242 clip->SetMasksToBounds(true);
3243
3244 root->test_properties()->clip_children =
3245 base::MakeUnique<std::set<LayerImpl*>>();
3246 root->test_properties()->clip_children->insert(filter_child_1);
3247 filter_child_1->test_properties()->clip_parent = root;
3248
3249 ExecuteCalculateDrawProperties(root);
3250 EXPECT_TRUE(filter_child_1->is_clipped());
3251 EXPECT_TRUE(filter_child_2->is_clipped());
3252 EXPECT_EQ(gfx::Rect(100, 100), filter_child_1->clip_rect());
3253 EXPECT_EQ(gfx::Rect(10, 10), filter_child_2->clip_rect());
3254
3255 FilterOperations blur_filter;
3256 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
3257 filter->test_properties()->filters = blur_filter;
3258 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3259
3260 ExecuteCalculateDrawProperties(root);
3261
3262 EXPECT_TRUE(filter_child_1->is_clipped());
3263 EXPECT_TRUE(filter_child_2->is_clipped());
3264 EXPECT_EQ(gfx::Rect(100, 100), filter_child_1->clip_rect());
3265 EXPECT_EQ(gfx::Rect(10, 10), filter_child_2->clip_rect());
3266 }
3267
3268 TEST_F(LayerTreeHostCommonTest, ClipRectWithClippedDescendantOfFilter) {
3269 LayerImpl* root = root_layer_for_testing();
3270 LayerImpl* filter = AddChild<LayerImpl>(root);
3271 LayerImpl* clip = AddChild<LayerImpl>(filter);
3272 LayerImpl* filter_grand_child = AddChild<LayerImpl>(clip);
3273
3274 root->SetBounds(gfx::Size(100, 100));
3275 filter->test_properties()->force_render_surface = true;
3276
3277 clip->SetBounds(gfx::Size(10, 10));
3278 clip->SetMasksToBounds(true);
3279
3280 filter_grand_child->SetBounds(gfx::Size(20, 20));
3281 filter_grand_child->SetDrawsContent(true);
3282
3283 ExecuteCalculateDrawProperties(root);
3284 EXPECT_TRUE(filter_grand_child->is_clipped());
3285 EXPECT_EQ(gfx::Rect(10, 10), filter_grand_child->clip_rect());
3286
3287 FilterOperations blur_filter;
3288 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
3289 filter->test_properties()->filters = blur_filter;
3290 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3291
3292 ExecuteCalculateDrawProperties(root);
3293
3294 EXPECT_TRUE(filter_grand_child->is_clipped());
3295 EXPECT_EQ(gfx::Rect(10, 10), filter_grand_child->clip_rect());
3296 }
3297
3122 TEST_F(LayerTreeHostCommonTest, 3298 TEST_F(LayerTreeHostCommonTest,
3123 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { 3299 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
3124 LayerImpl* root = root_layer_for_testing(); 3300 LayerImpl* root = root_layer_for_testing();
3125 LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); 3301 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3126 LayerImpl* child1 = AddChild<LayerImpl>(render_surface); 3302 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3127 LayerImpl* child2 = AddChild<LayerImpl>(render_surface); 3303 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
3128 LayerImpl* child3 = AddChild<LayerImpl>(render_surface); 3304 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
3129 3305
3130 root->SetBounds(gfx::Size(100, 100)); 3306 root->SetBounds(gfx::Size(100, 100));
3131 render_surface->SetBounds(gfx::Size(3, 4)); 3307 render_surface->SetBounds(gfx::Size(3, 4));
(...skipping 7451 matching lines...) Expand 10 before | Expand all | Expand 10 after
10583 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); 10759 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10584 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); 10760 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10585 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); 10761 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10586 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); 10762 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10587 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); 10763 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10588 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); 10764 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10589 } 10765 }
10590 10766
10591 } // namespace 10767 } // namespace
10592 } // namespace cc 10768 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/draw_property_utils.cc ('k') | cc/trees/property_tree_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698