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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/trees/layer_tree_host_common_unittest.cc
diff --git a/cc/trees/layer_tree_host_common_unittest.cc b/cc/trees/layer_tree_host_common_unittest.cc
index d7bd2169d2ed444240f4228abceec5423c79cd83..8a0d4a5efadcac07ce59e5b1923a9342eb120255 100644
--- a/cc/trees/layer_tree_host_common_unittest.cc
+++ b/cc/trees/layer_tree_host_common_unittest.cc
@@ -49,7 +49,9 @@
#include "cc/trees/task_runner_provider.h"
#include "cc/trees/transform_node.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkImageFilter.h"
#include "third_party/skia/include/effects/SkOffsetImageFilter.h"
+#include "third_party/skia/include/effects/SkXfermodeImageFilter.h"
#include "ui/gfx/geometry/quad_f.h"
#include "ui/gfx/geometry/vector2d_conversions.h"
#include "ui/gfx/transform.h"
@@ -3119,6 +3121,180 @@ TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect());
}
+TEST_F(LayerTreeHostCommonTest, VisibleRectWithClippingAndFilters) {
+ LayerImpl* root = root_layer_for_testing();
+ LayerImpl* clip = AddChild<LayerImpl>(root);
+ LayerImpl* filter = AddChild<LayerImpl>(clip);
+ LayerImpl* filter_child = AddChild<LayerImpl>(filter);
+
+ root->SetBounds(gfx::Size(100, 100));
+ clip->SetBounds(gfx::Size(10, 10));
+ filter->test_properties()->force_render_surface = true;
+ filter_child->SetBounds(gfx::Size(2000, 2000));
+ filter_child->SetPosition(gfx::PointF(-50, -50));
+ filter_child->SetDrawsContent(true);
+
+ clip->SetMasksToBounds(true);
+
+ ExecuteCalculateDrawProperties(root);
+ EXPECT_EQ(gfx::Rect(50, 50, 10, 10), filter_child->visible_layer_rect());
+ EXPECT_EQ(gfx::Rect(10, 10), filter->render_surface()->content_rect());
+
+ FilterOperations blur_filter;
+ blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
+ filter->test_properties()->filters = blur_filter;
+ host_impl()->active_tree()->property_trees()->needs_rebuild = true;
+
+ ExecuteCalculateDrawProperties(root);
+
+ EXPECT_EQ(gfx::Rect(38, 38, 34, 34), filter_child->visible_layer_rect());
+ EXPECT_EQ(gfx::Rect(-12, -12, 34, 34),
+ filter->render_surface()->content_rect());
+
+ gfx::Transform vertical_flip;
+ vertical_flip.Scale(1, -1);
+ sk_sp<SkImageFilter> flip_filter = SkImageFilter::MakeMatrixFilter(
+ vertical_flip.matrix(), kLow_SkFilterQuality, nullptr);
+ FilterOperations reflection_filter;
+ reflection_filter.Append(
+ FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make(
+ SkBlendMode::kSrcOver, std::move(flip_filter))));
+ filter->test_properties()->filters = reflection_filter;
+ host_impl()->active_tree()->property_trees()->needs_rebuild = true;
+
+ ExecuteCalculateDrawProperties(root);
+
+ EXPECT_EQ(gfx::Rect(50, 40, 10, 20), filter_child->visible_layer_rect());
+ EXPECT_EQ(gfx::Rect(0, -10, 10, 20),
+ filter->render_surface()->content_rect());
+}
+
+TEST_F(LayerTreeHostCommonTest, VisibleRectWithScalingClippingAndFilters) {
+ LayerImpl* root = root_layer_for_testing();
+ LayerImpl* scale = AddChild<LayerImpl>(root);
+ LayerImpl* clip = AddChild<LayerImpl>(scale);
+ LayerImpl* filter = AddChild<LayerImpl>(clip);
+ LayerImpl* filter_child = AddChild<LayerImpl>(filter);
+
+ root->SetBounds(gfx::Size(100, 100));
+ clip->SetBounds(gfx::Size(10, 10));
+ filter->test_properties()->force_render_surface = true;
+ filter_child->SetBounds(gfx::Size(2000, 2000));
+ filter_child->SetPosition(gfx::PointF(-50, -50));
+ filter_child->SetDrawsContent(true);
+
+ clip->SetMasksToBounds(true);
+
+ gfx::Transform scale_transform;
+ scale_transform.Scale(3, 3);
+ scale->test_properties()->transform = scale_transform;
+
+ ExecuteCalculateDrawProperties(root);
+ EXPECT_EQ(gfx::Rect(50, 50, 10, 10), filter_child->visible_layer_rect());
+ EXPECT_EQ(gfx::Rect(30, 30), filter->render_surface()->content_rect());
+
+ FilterOperations blur_filter;
+ blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
+ filter->test_properties()->filters = blur_filter;
+ host_impl()->active_tree()->property_trees()->needs_rebuild = true;
+
+ ExecuteCalculateDrawProperties(root);
+
+ EXPECT_EQ(gfx::Rect(38, 38, 34, 34), filter_child->visible_layer_rect());
+ EXPECT_EQ(gfx::Rect(-36, -36, 102, 102),
+ filter->render_surface()->content_rect());
+
+ gfx::Transform vertical_flip;
+ vertical_flip.Scale(1, -1);
+ sk_sp<SkImageFilter> flip_filter = SkImageFilter::MakeMatrixFilter(
+ vertical_flip.matrix(), kLow_SkFilterQuality, nullptr);
+ FilterOperations reflection_filter;
+ reflection_filter.Append(
+ FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make(
+ SkBlendMode::kSrcOver, std::move(flip_filter))));
+ filter->test_properties()->filters = reflection_filter;
+ host_impl()->active_tree()->property_trees()->needs_rebuild = true;
+
+ ExecuteCalculateDrawProperties(root);
+
+ EXPECT_EQ(gfx::Rect(50, 40, 10, 20), filter_child->visible_layer_rect());
+ EXPECT_EQ(gfx::Rect(0, -30, 30, 60),
+ filter->render_surface()->content_rect());
+}
+
+TEST_F(LayerTreeHostCommonTest, ClipRectWithClipParentAndFilters) {
+ LayerImpl* root = root_layer_for_testing();
+ LayerImpl* clip = AddChild<LayerImpl>(root);
+ LayerImpl* filter = AddChild<LayerImpl>(clip);
+ LayerImpl* filter_child_1 = AddChild<LayerImpl>(filter);
+ LayerImpl* filter_child_2 = AddChild<LayerImpl>(filter);
+
+ root->SetBounds(gfx::Size(100, 100));
+ clip->SetBounds(gfx::Size(10, 10));
+ filter->test_properties()->force_render_surface = true;
+
+ filter_child_1->SetBounds(gfx::Size(20, 20));
+ filter_child_1->SetDrawsContent(true);
+ filter_child_2->SetBounds(gfx::Size(20, 20));
+ filter_child_2->SetDrawsContent(true);
+
+ root->SetMasksToBounds(true);
+ clip->SetMasksToBounds(true);
+
+ root->test_properties()->clip_children =
+ base::MakeUnique<std::set<LayerImpl*>>();
+ root->test_properties()->clip_children->insert(filter_child_1);
+ filter_child_1->test_properties()->clip_parent = root;
+
+ ExecuteCalculateDrawProperties(root);
+ EXPECT_TRUE(filter_child_1->is_clipped());
+ EXPECT_TRUE(filter_child_2->is_clipped());
+ EXPECT_EQ(gfx::Rect(100, 100), filter_child_1->clip_rect());
+ EXPECT_EQ(gfx::Rect(10, 10), filter_child_2->clip_rect());
+
+ FilterOperations blur_filter;
+ blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
+ filter->test_properties()->filters = blur_filter;
+ host_impl()->active_tree()->property_trees()->needs_rebuild = true;
+
+ ExecuteCalculateDrawProperties(root);
+
+ EXPECT_TRUE(filter_child_1->is_clipped());
+ EXPECT_TRUE(filter_child_2->is_clipped());
+ EXPECT_EQ(gfx::Rect(100, 100), filter_child_1->clip_rect());
+ EXPECT_EQ(gfx::Rect(10, 10), filter_child_2->clip_rect());
+}
+
+TEST_F(LayerTreeHostCommonTest, ClipRectWithClippedDescendantOfFilter) {
+ LayerImpl* root = root_layer_for_testing();
+ LayerImpl* filter = AddChild<LayerImpl>(root);
+ LayerImpl* clip = AddChild<LayerImpl>(filter);
+ LayerImpl* filter_grand_child = AddChild<LayerImpl>(clip);
+
+ root->SetBounds(gfx::Size(100, 100));
+ filter->test_properties()->force_render_surface = true;
+
+ clip->SetBounds(gfx::Size(10, 10));
+ clip->SetMasksToBounds(true);
+
+ filter_grand_child->SetBounds(gfx::Size(20, 20));
+ filter_grand_child->SetDrawsContent(true);
+
+ ExecuteCalculateDrawProperties(root);
+ EXPECT_TRUE(filter_grand_child->is_clipped());
+ EXPECT_EQ(gfx::Rect(10, 10), filter_grand_child->clip_rect());
+
+ FilterOperations blur_filter;
+ blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
+ filter->test_properties()->filters = blur_filter;
+ host_impl()->active_tree()->property_trees()->needs_rebuild = true;
+
+ ExecuteCalculateDrawProperties(root);
+
+ EXPECT_TRUE(filter_grand_child->is_clipped());
+ EXPECT_EQ(gfx::Rect(10, 10), filter_grand_child->clip_rect());
+}
+
TEST_F(LayerTreeHostCommonTest,
DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
LayerImpl* root = root_layer_for_testing();
« 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