skia2/gm/crbug_1313579.cpp
Brian Salomon de301c8d70 Reland "skif:LayerSpace<SkRect>::roundOut/In have epsilon tolerance."
This is a reland of commit acb8770918

Original change's description:
> skif:LayerSpace<SkRect>::roundOut/In have epsilon tolerance.
>
> Adds a little tolerance so that e.g. left=30.999994 with roundOut
> will still round to 31 not 30. Helps avoid cases where imprecision
> leads to including an entire unwanted row/column of an input image
> to an image filter.
>
> This Chrome change must land first:
> https://chromium-review.googlesource.com/c/chromium/src/+/3577185/
>
> Bug: chromium:1313579
> Change-Id: I143c8f99b90413a6b610f2b3a5e54e648777ca68
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/528652
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Brian Salomon <bsalomon@google.com>

Bug: chromium:1313579
Change-Id: Ia827c6fc01542fa3d56f560cde517570b8f0021d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/529744
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2022-04-14 14:41:22 +00:00

42 lines
1.7 KiB
C++

/*
* Copyright 2022 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkRect.h"
#include "include/effects/SkImageFilters.h"
// SkiaRenderer can wind up specifying near-integer scale-and-translate matrices on SkCanvas before
// applying a backdrop blur image filter via saveLayer() with an integer clip, crop rect, and
// SaveLayerRec bounds. Round-out is used to determine the bounds of the input image needed in IFs.
// This could cause an extra row/column of pixels to be included in the blur. When that row/column
// is significantly different in color than the intended blur content and the radius is large then
// clamp mode blur creates a very noticeable color bleed artifact.
DEF_SIMPLE_GM(crbug_1313579, canvas, 110, 110) {
static constexpr auto kBGRect = SkIRect{0, 0, 100, 100};
sk_sp<SkImageFilter> backdrop_filter =
SkImageFilters::Blur(50.f, 50.f, SkTileMode::kClamp, nullptr);
sk_sp<SkImageFilter> crop = SkImageFilters::Offset(0, 0, nullptr, &kBGRect);
backdrop_filter = SkImageFilters::Compose(
crop, SkImageFilters::Compose(std::move(backdrop_filter), crop));
SkMatrix m;
canvas->clear(SK_ColorGREEN);
m.setAll(0.999999f, 0, 4.99999f,
0, 0.999999f, 4.99999f,
0, 0, 1);
canvas->concat(m);
canvas->clipIRect(kBGRect);
canvas->clear(SK_ColorWHITE);
canvas->saveLayer(SkCanvas::SaveLayerRec(nullptr, nullptr, backdrop_filter.get(), 0));
canvas->restore();
}