xref: /aosp_15_r20/external/skia/gm/crbug_1313579.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "gm/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkMatrix.h"
11 #include "include/core/SkRect.h"
12 #include "include/effects/SkImageFilters.h"
13 
14 // SkiaRenderer can wind up specifying near-integer scale-and-translate matrices on SkCanvas before
15 // applying a backdrop blur image filter via saveLayer() with an integer clip, crop rect, and
16 // SaveLayerRec bounds. Round-out is used to determine the bounds of the input image needed in IFs.
17 // This could cause an extra row/column of pixels to be included in the blur. When that row/column
18 // is significantly different in color than the intended blur content and the radius is large then
19 // clamp mode blur creates a very noticeable color bleed artifact.
20 DEF_SIMPLE_GM(crbug_1313579, canvas, 110, 110) {
21     static constexpr auto kBGRect = SkIRect{0, 0, 100, 100};
22 
23    sk_sp<SkImageFilter> backdrop_filter =
24             SkImageFilters::Blur(50.f, 50.f, SkTileMode::kClamp, nullptr, kBGRect);
25 
26     SkMatrix m;
27 
28     canvas->clear(SK_ColorGREEN);
29 
30     m.setAll(0.999999f, 0,         4.99999f,
31              0,         0.999999f, 4.99999f,
32              0,         0,         1);
33     canvas->concat(m);
34     canvas->clipIRect(kBGRect);
35     canvas->clear(SK_ColorWHITE);
36     canvas->saveLayer(SkCanvas::SaveLayerRec(nullptr, nullptr, backdrop_filter.get(), 0));
37     canvas->restore();
38 }
39