Commit d5fdc8c2 authored by Md. Hasanur Rashid's avatar Md. Hasanur Rashid Committed by Commit Bot

Enable MapRectReverse() for a blur filter to map backward

Current implementation of FilterOperation::MapRectReverse() for a blur
filter actually does a forward (outset) map of the rect. This patch
fixes the erroneous behavior by supporting MapRectReverse() to map
backward for a blur filter.

Bug: 916583
Change-Id: I43bf4498b89e18ba9c2d1eb341e977944e2226c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1986646Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Md. Hasanur Rashid <hasanur.r@samsung.com>
Cr-Commit-Position: refs/heads/master@{#732570}
parent 23947828
...@@ -211,7 +211,7 @@ gfx::Rect RenderSurfaceImpl::CalculateExpandedClipForFilters( ...@@ -211,7 +211,7 @@ gfx::Rect RenderSurfaceImpl::CalculateExpandedClipForFilters(
gfx::Rect clip_in_surface_space = gfx::Rect clip_in_surface_space =
MathUtil::ProjectEnclosingClippedRect(target_to_surface, clip_rect()); MathUtil::ProjectEnclosingClippedRect(target_to_surface, clip_rect());
gfx::Rect expanded_clip_in_surface_space = gfx::Rect expanded_clip_in_surface_space =
Filters().MapRectReverse(clip_in_surface_space, SurfaceScale().matrix()); Filters().MapRect(clip_in_surface_space, SurfaceScale().matrix());
gfx::Rect expanded_clip_in_target_space = MathUtil::MapEnclosingClippedRect( gfx::Rect expanded_clip_in_target_space = MathUtil::MapEnclosingClippedRect(
draw_transform(), expanded_clip_in_surface_space); draw_transform(), expanded_clip_in_surface_space);
return expanded_clip_in_target_space; return expanded_clip_in_target_space;
......
...@@ -353,10 +353,8 @@ gfx::Rect MapRectInternal(const FilterOperation& op, ...@@ -353,10 +353,8 @@ gfx::Rect MapRectInternal(const FilterOperation& op,
// Mapping a blur forward requires an outset (negative inset) because a // Mapping a blur forward requires an outset (negative inset) because a
// smaller source rectangle gets blurred to a larger destination // smaller source rectangle gets blurred to a larger destination
// rectangle. // rectangle.
// TODO(916583): Fix this function for reverse mapping: float sign =
// float sign = (direction == SkImageFilter::kForward_MapDirection) ? -1.0 (direction == SkImageFilter::kForward_MapDirection) ? -1.0 : 1.0;
// : 1.0;
float sign = -1.0;
float spread_x = std::abs(spread.x()) * sign; float spread_x = std::abs(spread.x()) * sign;
float spread_y = std::abs(spread.y()) * sign; float spread_y = std::abs(spread.y()) * sign;
gfx::RectF result(rect); gfx::RectF result(rect);
......
...@@ -39,13 +39,13 @@ TEST(FilterOperationsTest, MapRectBlurOverflow) { ...@@ -39,13 +39,13 @@ TEST(FilterOperationsTest, MapRectBlurOverflow) {
TEST(FilterOperationsTest, MapRectReverseBlur) { TEST(FilterOperationsTest, MapRectReverseBlur) {
FilterOperations ops; FilterOperations ops;
ops.Append(FilterOperation::CreateBlurFilter(20)); ops.Append(FilterOperation::CreateBlurFilter(20));
EXPECT_EQ(gfx::Rect(-60, -60, 130, 130), EXPECT_EQ(gfx::Rect(60, 60, 30, 30),
ops.MapRectReverse(gfx::Rect(0, 0, 10, 10), SkMatrix::I())); ops.MapRectReverse(gfx::Rect(0, 0, 150, 150), SkMatrix::I()));
EXPECT_EQ( EXPECT_EQ(
gfx::Rect(-120, -120, 260, 260), gfx::Rect(120, 120, 60, 60),
ops.MapRectReverse(gfx::Rect(0, 0, 20, 20), SkMatrix::MakeScale(2, 2))); ops.MapRectReverse(gfx::Rect(0, 0, 300, 300), SkMatrix::MakeScale(2, 2)));
EXPECT_EQ(gfx::Rect(-60, -70, 130, 130), EXPECT_EQ(gfx::Rect(60, 50, 30, 30),
ops.MapRectReverse(gfx::Rect(0, -10, 10, 10), ops.MapRectReverse(gfx::Rect(0, -10, 150, 150),
SkMatrix::MakeScale(1, -1))); SkMatrix::MakeScale(1, -1)));
} }
......
...@@ -191,7 +191,7 @@ bool ApplyClipNodeToAccumulatedClip(const PropertyTrees* property_trees, ...@@ -191,7 +191,7 @@ bool ApplyClipNodeToAccumulatedClip(const PropertyTrees* property_trees,
// Do the expansion. // Do the expansion.
gfx::RectF expanded_clip_in_expanding_space = gfx::RectF expanded_clip_in_expanding_space =
gfx::RectF(clip_node->clip_expander->MapRectReverse( gfx::RectF(clip_node->clip_expander->MapRect(
ToEnclosingClipRect(accumulated_clip_rect_in_expanding_space), ToEnclosingClipRect(accumulated_clip_rect_in_expanding_space),
property_trees)); property_trees));
......
...@@ -20,8 +20,7 @@ ...@@ -20,8 +20,7 @@
namespace cc { namespace cc {
OcclusionTracker::OcclusionTracker(const gfx::Rect& screen_space_clip_rect) OcclusionTracker::OcclusionTracker(const gfx::Rect& screen_space_clip_rect)
: screen_space_clip_rect_(screen_space_clip_rect) { : screen_space_clip_rect_(screen_space_clip_rect) {}
}
OcclusionTracker::~OcclusionTracker() = default; OcclusionTracker::~OcclusionTracker() = default;
...@@ -29,8 +28,7 @@ Occlusion OcclusionTracker::GetCurrentOcclusionForLayer( ...@@ -29,8 +28,7 @@ Occlusion OcclusionTracker::GetCurrentOcclusionForLayer(
const gfx::Transform& draw_transform) const { const gfx::Transform& draw_transform) const {
DCHECK(!stack_.empty()); DCHECK(!stack_.empty());
const StackObject& back = stack_.back(); const StackObject& back = stack_.back();
return Occlusion(draw_transform, return Occlusion(draw_transform, back.occlusion_from_outside_target,
back.occlusion_from_outside_target,
back.occlusion_from_inside_target); back.occlusion_from_inside_target);
} }
...@@ -160,10 +158,8 @@ void OcclusionTracker::EnterRenderTarget( ...@@ -160,10 +158,8 @@ void OcclusionTracker::EnterRenderTarget(
new_target_surface->render_target() == new_target_surface; new_target_surface->render_target() == new_target_surface;
bool copy_outside_occlusion_forward = bool copy_outside_occlusion_forward =
stack_.size() > 1 && stack_.size() > 1 && !entering_unoccluded_subtree &&
!entering_unoccluded_subtree && have_transform_from_screen_to_new_target && !entering_root_target;
have_transform_from_screen_to_new_target &&
!entering_root_target;
if (!copy_outside_occlusion_forward) { if (!copy_outside_occlusion_forward) {
stack_.back().ignores_parent_occlusion = true; stack_.back().ignores_parent_occlusion = true;
return; return;
...@@ -227,8 +223,12 @@ static void ReduceOcclusionBelowSurface( ...@@ -227,8 +223,12 @@ static void ReduceOcclusionBelowSurface(
return; return;
gfx::Rect affected_area_in_target = gfx::Rect affected_area_in_target =
contributing_surface->BackdropFilters().MapRectReverse(target_rect, contributing_surface->BackdropFilters().HasFilterOfType(
SkMatrix::I()); FilterOperation::FilterType::BLUR)
? contributing_surface->BackdropFilters().MapRect(target_rect,
SkMatrix::I())
: contributing_surface->BackdropFilters().MapRectReverse(
target_rect, SkMatrix::I());
// Unite target_rect because we only care about positive outsets. // Unite target_rect because we only care about positive outsets.
affected_area_in_target.Union(target_rect); affected_area_in_target.Union(target_rect);
......
...@@ -362,9 +362,9 @@ TEST_F(PropertyTreeBuilderTest, VisibleRectWithClippingAndFilters) { ...@@ -362,9 +362,9 @@ TEST_F(PropertyTreeBuilderTest, VisibleRectWithClippingAndFilters) {
CommitAndActivate(); CommitAndActivate();
EXPECT_EQ(gfx::Rect(49, 39, 12, 21), EXPECT_EQ(gfx::Rect(50, 40, 10, 20),
ImplOf(filter_child)->visible_layer_rect()); ImplOf(filter_child)->visible_layer_rect());
EXPECT_EQ(gfx::Rect(-1, -11, 12, 21), EXPECT_EQ(gfx::Rect(0, -10, 10, 20),
GetRenderSurfaceImpl(filter)->content_rect()); GetRenderSurfaceImpl(filter)->content_rect());
} }
...@@ -422,9 +422,9 @@ TEST_F(PropertyTreeBuilderTest, VisibleRectWithScalingClippingAndFilters) { ...@@ -422,9 +422,9 @@ TEST_F(PropertyTreeBuilderTest, VisibleRectWithScalingClippingAndFilters) {
CommitAndActivate(); CommitAndActivate();
EXPECT_EQ(gfx::Rect(49, 39, 12, 21), EXPECT_EQ(gfx::Rect(50, 40, 10, 20),
ImplOf(filter_child)->visible_layer_rect()); ImplOf(filter_child)->visible_layer_rect());
EXPECT_EQ(gfx::Rect(-1, -31, 32, 61), EXPECT_EQ(gfx::Rect(0, -30, 30, 60),
GetRenderSurfaceImpl(filter)->content_rect()); GetRenderSurfaceImpl(filter)->content_rect());
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment