Commit ce8cb7d8 authored by Michael Ludwig's avatar Michael Ludwig Committed by Commit Bot

SkiaRenderer: Improve backdrop filter quality for non-pixel-moving filters

Bug: 1044032
Change-Id: I4f577ce9f2cf2d45fdf1abcb5cf36973a5285495
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2068034Reviewed-by: default avatarweiliangc <weiliangc@chromium.org>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Cr-Commit-Position: refs/heads/master@{#744125}
parent 8517d120
......@@ -1103,18 +1103,32 @@ void SkiaRenderer::PrepareCanvasForRPDQ(const DrawRPDQParams& rpdq_params,
gfx::Rect crop_rect =
gfx::ToEnclosingRect(rpdq_params.backdrop_filter_bounds->rect());
SkIRect sk_crop_rect = gfx::RectToSkIRect(crop_rect);
// Offsetting (0,0) does nothing to the actual image, but is the most
// convenient way to embed the crop rect into the filter DAG.
// TODO(michaelludwig) - Remove this once Skia doesn't always auto-expand
sk_sp<SkImageFilter> crop =
SkImageFilters::Offset(0.0f, 0.0f, nullptr, &sk_crop_rect);
backdrop_filter = SkImageFilters::Compose(
crop, SkImageFilters::Compose(std::move(backdrop_filter), crop));
// Update whether or not a post-filter clear is needed (crop didn't
// completely match bounds)
post_backdrop_filter_clear_needed |=
backdrop_bounds_type != gfx::RRectF::Type::kRect ||
gfx::RectF(crop_rect) != rpdq_params.backdrop_filter_bounds->rect();
SkIRect sk_src_rect = backdrop_filter->filterBounds(
sk_crop_rect, SkMatrix::I(), SkImageFilter::kReverse_MapDirection,
&sk_crop_rect);
if (sk_crop_rect == sk_src_rect) {
// The backdrop filter does not "move" pixels, i.e. a pixel's value only
// depends on its (x,y) and prior color. Avoid cropping the input in this
// case since composing a crop rect into the filter DAG forces Skia to
// map the backdrop content into the local space, which can introduce
// filtering artifacts: crbug.com/1044032. Instead just post-filter
// clearing will achieve the same cropping of the output at higher quality
post_backdrop_filter_clear_needed = true;
} else {
// Offsetting (0,0) does nothing to the actual image, but is the most
// convenient way to embed the crop rect into the filter DAG.
// TODO(michaelludwig) - Remove this once Skia doesn't always auto-expand
sk_sp<SkImageFilter> crop =
SkImageFilters::Offset(0.0f, 0.0f, nullptr, &sk_crop_rect);
backdrop_filter = SkImageFilters::Compose(
crop, SkImageFilters::Compose(std::move(backdrop_filter), crop));
// Update whether or not a post-filter clear is needed (crop didn't
// completely match bounds)
post_backdrop_filter_clear_needed |=
backdrop_bounds_type != gfx::RRectF::Type::kRect ||
gfx::RectF(crop_rect) != rpdq_params.backdrop_filter_bounds->rect();
}
}
SkRect bounds = gfx::RectFToSkRect(rpdq_params.bypass_clip.has_value()
......
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