blob: a48ba1251b10ab65ac856c92b59e9a61390cd031 [file] [log] [blame]
Brian Salomon702c5a32020-04-28 16:21:48 -04001/*
2 * Copyright 2020 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
10#include "include/effects/SkGradientShader.h"
Robert Phillips2f9dad42020-11-12 14:48:28 -050011#include "include/gpu/GrRecordingContext.h"
Robert Phillips7a0d3c32021-07-21 15:39:51 -040012#include "src/core/SkCanvasPriv.h"
Brian Salomon702c5a32020-04-28 16:21:48 -040013#include "src/core/SkGpuBlurUtils.h"
Robert Phillips95c250c2020-06-29 15:36:12 -040014#include "src/gpu/GrRecordingContextPriv.h"
Brian Salomon702c5a32020-04-28 16:21:48 -040015#include "src/gpu/GrStyle.h"
16#include "src/gpu/SkGr.h"
John Stilesf743d4e2020-07-23 11:35:08 -040017#include "src/gpu/effects/GrBlendFragmentProcessor.h"
Robert Phillips550de7f2021-07-06 16:28:52 -040018#include "src/gpu/effects/GrTextureEffect.h"
Brian Salomon702c5a32020-04-28 16:21:48 -040019#include "src/image/SkImage_Base.h"
20
Robert Phillips7a0d3c32021-07-21 15:39:51 -040021namespace {
22
Robert Phillips95c250c2020-06-29 15:36:12 -040023static GrSurfaceProxyView blur(GrRecordingContext* ctx,
Brian Salomon11ad4cc2020-05-15 12:07:59 -040024 GrSurfaceProxyView src,
25 SkIRect dstB,
26 SkIRect srcB,
27 float sigmaX,
28 float sigmaY,
29 SkTileMode mode) {
Brian Salomonf9707462021-03-15 16:50:04 -040030 auto resultSDC = SkGpuBlurUtils::GaussianBlur(ctx,
31 src,
32 GrColorType::kRGBA_8888,
33 kPremul_SkAlphaType,
34 nullptr,
35 dstB,
36 srcB,
37 sigmaX,
38 sigmaY,
39 mode);
40 if (!resultSDC) {
Brian Salomon11ad4cc2020-05-15 12:07:59 -040041 return {};
42 }
Brian Salomonf9707462021-03-15 16:50:04 -040043 return resultSDC->readSurfaceView();
Brian Salomon11ad4cc2020-05-15 12:07:59 -040044};
45
Brian Salomonf9707462021-03-15 16:50:04 -040046// Performs tiling first of the src into dst bounds with a surrounding skirt so the blur can use
47// clamp. Does repeated blurs rather than invoking downsampling.
48static GrSurfaceProxyView slow_blur(GrRecordingContext* ctx,
49 GrSurfaceProxyView src,
50 SkIRect dstB,
51 SkIRect srcB,
52 float sigmaX,
53 float sigmaY,
54 SkTileMode mode) {
55 auto tileInto = [ctx](GrSurfaceProxyView src,
56 SkIRect srcTileRect,
57 SkISize resultSize,
58 SkIPoint offset,
59 SkTileMode mode) {
60 GrImageInfo info(GrColorType::kRGBA_8888, kPremul_SkAlphaType, nullptr, resultSize);
61 auto fc = GrSurfaceFillContext::Make(ctx, info);
62 if (!fc) {
63 return GrSurfaceProxyView{};
64 }
65 GrSamplerState sampler(SkTileModeToWrapMode(mode), SkFilterMode::kNearest);
66 auto fp = GrTextureEffect::MakeSubset(src,
67 kPremul_SkAlphaType,
68 SkMatrix::Translate(-offset.x(), -offset.y()),
69 sampler,
70 SkRect::Make(srcTileRect),
71 *ctx->priv().caps());
72 fc->fillWithFP(std::move(fp));
73 return fc->readSurfaceView();
74 };
Brian Salomon702c5a32020-04-28 16:21:48 -040075
Brian Salomonf9707462021-03-15 16:50:04 -040076 SkIPoint outset = {SkGpuBlurUtils::SigmaRadius(sigmaX), SkGpuBlurUtils::SigmaRadius(sigmaY)};
77 SkISize size = {dstB.width() + 2*outset.x(), dstB.height() + 2*outset.y()};
78 src = tileInto(std::move(src), srcB, size, outset - dstB.topLeft(), mode);
79 if (!src) {
80 return {};
Brian Salomon702c5a32020-04-28 16:21:48 -040081 }
Brian Salomonf9707462021-03-15 16:50:04 -040082 dstB = SkIRect::MakePtSize(outset, dstB.size());
83
84 while (sigmaX || sigmaY) {
85 float stepX = sigmaX;
86 if (stepX > SkGpuBlurUtils::kMaxSigma) {
87 stepX = SkGpuBlurUtils::kMaxSigma;
88 // A blur of sigma1 followed by a blur of sigma2 is equiv. to a single blur of
89 // sqrt(sigma1^2 + sigma2^2).
90 sigmaX = sqrt(sigmaX*sigmaX - SkGpuBlurUtils::kMaxSigma*SkGpuBlurUtils::kMaxSigma);
91 } else {
92 sigmaX = 0.f;
93 }
94 float stepY = sigmaY;
95 if (stepY > SkGpuBlurUtils::kMaxSigma) {
96 stepY = SkGpuBlurUtils::kMaxSigma;
97 sigmaY = sqrt(sigmaY*sigmaY- SkGpuBlurUtils::kMaxSigma*SkGpuBlurUtils::kMaxSigma);
98 } else {
99 sigmaY = 0.f;
100 }
101 auto bounds = SkIRect::MakeSize(src.dimensions());
102 auto sdc = SkGpuBlurUtils::GaussianBlur(ctx,
103 std::move(src),
104 GrColorType::kRGBA_8888,
105 kPremul_SkAlphaType,
106 nullptr,
107 bounds,
108 bounds,
109 stepX,
110 stepY,
111 SkTileMode::kClamp);
112 if (!sdc) {
113 return {};
114 }
115 src = sdc->readSurfaceView();
116 }
117 // We have o use the original mode here because we may have only blurred in X or Y and then
118 // the other dimension was not expanded.
119 auto srcRect = SkIRect::MakeSize(src.dimensions());
120 return tileInto(std::move(src), srcRect, dstB.size(), -outset, SkTileMode::kClamp);
121};
122
123// Makes a src texture for as a source for blurs. If 'contentArea' then the content will
124// be in that rect, the 1-pixel surrounding border will be transparent black, and red outside of
125// that. Otherwise, the content fills the dimensions.
126GrSurfaceProxyView make_src_image(GrRecordingContext* rContext,
127 SkISize dimensions,
128 const SkIRect* contentArea = nullptr) {
129 auto srcII = SkImageInfo::Make(dimensions, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
130 auto surf = SkSurface::MakeRenderTarget(rContext, SkBudgeted::kYes, srcII);
131 if (!surf) {
132 return {};
133 }
134
135 float w, h;
136 if (contentArea) {
137 surf->getCanvas()->clear(SK_ColorRED);
138 surf->getCanvas()->clipIRect(contentArea->makeOutset(1, 1));
139 surf->getCanvas()->clear(SK_ColorTRANSPARENT);
140 surf->getCanvas()->clipIRect(*contentArea);
141 surf->getCanvas()->translate(contentArea->top(), contentArea->left());
142 w = contentArea->width();
143 h = contentArea->height();
144 } else {
145 w = dimensions.width();
146 h = dimensions.height();
147 }
148
149 surf->getCanvas()->drawColor(SK_ColorDKGRAY);
150 SkPaint paint;
151 paint.setAntiAlias(true);
152 paint.setStyle(SkPaint::kStroke_Style);
153 // Draw four horizontal lines at 1/8, 1/4, 3/4, 7/8.
154 paint.setStrokeWidth(h/12.f);
155 paint.setColor(SK_ColorRED);
156 surf->getCanvas()->drawLine({0.f, 1.f*h/8.f}, {w, 1.f*h/8.f}, paint);
157 paint.setColor(/* sea foam */ 0xFF71EEB8);
158 surf->getCanvas()->drawLine({0.f, 1.f*h/4.f}, {w, 1.f*h/4.f}, paint);
159 paint.setColor(SK_ColorYELLOW);
160 surf->getCanvas()->drawLine({0.f, 3.f*h/4.f}, {w, 3.f*h/4.f}, paint);
161 paint.setColor(SK_ColorCYAN);
162 surf->getCanvas()->drawLine({0.f, 7.f*h/8.f}, {w, 7.f*h/8.f}, paint);
163
164 // Draw four vertical lines at 1/8, 1/4, 3/4, 7/8.
165 paint.setStrokeWidth(w/12.f);
166 paint.setColor(/* orange */ 0xFFFFA500);
167 surf->getCanvas()->drawLine({1.f*w/8.f, 0.f}, {1.f*h/8.f, h}, paint);
168 paint.setColor(SK_ColorBLUE);
169 surf->getCanvas()->drawLine({1.f*w/4.f, 0.f}, {1.f*h/4.f, h}, paint);
170 paint.setColor(SK_ColorMAGENTA);
171 surf->getCanvas()->drawLine({3.f*w/4.f, 0.f}, {3.f*h/4.f, h}, paint);
172 paint.setColor(SK_ColorGREEN);
173 surf->getCanvas()->drawLine({7.f*w/8.f, 0.f}, {7.f*h/8.f, h}, paint);
174
175 auto img = surf->makeImageSnapshot();
176 auto [src, ct] = as_IB(img)->asView(rContext, GrMipmapped::kNo);
177 return src;
178}
179
Robert Phillips7a0d3c32021-07-21 15:39:51 -0400180} // namespace
181
182namespace skiagm {
183
184static GM::DrawResult run(GrRecordingContext* rContext, SkCanvas* canvas, SkString* errorMsg,
185 bool subsetSrc, bool ref) {
Brian Salomonf9707462021-03-15 16:50:04 -0400186 GrSurfaceProxyView src = make_src_image(rContext, {60, 60});
Brian Salomon702c5a32020-04-28 16:21:48 -0400187 if (!src) {
Robert Phillips7a0d3c32021-07-21 15:39:51 -0400188 *errorMsg = "Failed to create source image";
189 return DrawResult::kSkip;
190 }
191
192 auto sdc = SkCanvasPriv::TopDeviceSurfaceDrawContext(canvas);
193 if (!sdc) {
194 *errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly;
195 return DrawResult::kSkip;
Brian Salomon702c5a32020-04-28 16:21:48 -0400196 }
Brian Salomon702c5a32020-04-28 16:21:48 -0400197
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400198 SkIRect srcRect = SkIRect::MakeSize(src.dimensions());
199 if (subsetSrc) {
200 srcRect = SkIRect::MakeXYWH(2.f*srcRect.width() /8.f,
201 1.f*srcRect.height()/8.f,
202 5.f*srcRect.width() /8.f,
203 6.f*srcRect.height()/8.f);
204 }
205 int srcW = srcRect.width();
206 int srcH = srcRect.height();
207 // Each set of rects is drawn in one test area so they probably should not abut or overlap
208 // to visualize the blurs separately.
209 const std::vector<SkIRect> dstRectSets[] = {
Brian Salomon287d5982020-05-19 14:24:43 -0400210 // encloses source bounds.
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400211 {
212 srcRect.makeOutset(srcW/5, srcH/5)
213 },
Brian Salomon702c5a32020-04-28 16:21:48 -0400214
Brian Salomon287d5982020-05-19 14:24:43 -0400215 // partial overlap from above/below.
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400216 {
217 SkIRect::MakeXYWH(srcRect.x(), srcRect.y() + 3*srcH/4, srcW, srcH),
218 SkIRect::MakeXYWH(srcRect.x(), srcRect.y() - 3*srcH/4, srcW, srcH)
219 },
220
Brian Salomon287d5982020-05-19 14:24:43 -0400221 // adjacent to each side of src bounds.
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400222 {
223 srcRect.makeOffset( 0, srcH),
224 srcRect.makeOffset( srcW, 0),
225 srcRect.makeOffset( 0, -srcH),
226 srcRect.makeOffset(-srcW, 0),
227 },
228
Brian Salomon287d5982020-05-19 14:24:43 -0400229 // fully outside src bounds in one direction.
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400230 {
231 SkIRect::MakeXYWH(-6.f*srcW/8.f, -7.f*srcH/8.f, 4.f*srcW/8.f, 20.f*srcH/8.f)
232 .makeOffset(srcRect.topLeft()),
233 SkIRect::MakeXYWH(-1.f*srcW/8.f, -7.f*srcH/8.f, 16.f*srcW/8.f, 2.f*srcH/8.f)
234 .makeOffset(srcRect.topLeft()),
235 SkIRect::MakeXYWH(10.f*srcW/8.f, -3.f*srcH/8.f, 4.f*srcW/8.f, 16.f*srcH/8.f)
236 .makeOffset(srcRect.topLeft()),
237 SkIRect::MakeXYWH(-7.f*srcW/8.f, 14.f*srcH/8.f, 18.f*srcW/8.f, 1.f*srcH/8.f)
238 .makeOffset(srcRect.topLeft()),
239 },
Brian Salomon287d5982020-05-19 14:24:43 -0400240
241 // outside of src bounds in both directions.
242 {
243 SkIRect::MakeXYWH(-5.f*srcW/8.f, -5.f*srcH/8.f, 2.f*srcW/8.f, 2.f*srcH/8.f)
244 .makeOffset(srcRect.topLeft()),
245 SkIRect::MakeXYWH(-5.f*srcW/8.f, 12.f*srcH/8.f, 2.f*srcW/8.f, 2.f*srcH/8.f)
246 .makeOffset(srcRect.topLeft()),
247 SkIRect::MakeXYWH(12.f*srcW/8.f, -5.f*srcH/8.f, 2.f*srcW/8.f, 2.f*srcH/8.f)
248 .makeOffset(srcRect.topLeft()),
249 SkIRect::MakeXYWH(12.f*srcW/8.f, 12.f*srcH/8.f, 2.f*srcW/8.f, 2.f*srcH/8.f)
250 .makeOffset(srcRect.topLeft()),
251 },
Brian Salomon702c5a32020-04-28 16:21:48 -0400252 };
253
Robert Phillips2f9dad42020-11-12 14:48:28 -0500254 const auto& caps = *rContext->priv().caps();
Brian Salomon702c5a32020-04-28 16:21:48 -0400255
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400256 static constexpr SkScalar kPad = 10;
257 SkVector trans = {kPad, kPad};
258
Brian Salomonf9707462021-03-15 16:50:04 -0400259 sdc->clear(SK_PMColor4fWHITE);
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400260
261 SkIRect testArea = srcRect;
262 testArea.outset(testArea.width(), testArea.height());
263 for (const auto& dstRectSet : dstRectSets) {
264 for (int t = 0; t < kSkTileModeCount; ++t) {
265 auto mode = static_cast<SkTileMode>(t);
266 GrSamplerState sampler(SkTileModeToWrapMode(mode), GrSamplerState::Filter::kNearest);
Mike Reed1f607332020-05-21 12:11:27 -0400267 SkMatrix m = SkMatrix::Translate(trans.x() - testArea.x(), trans.y() - testArea.y());
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400268 // Draw the src subset in the tile mode faded as a reference before drawing the blur
269 // on top.
270 {
Brian Osmanf48f76e2020-07-15 16:04:17 -0400271 static constexpr float kAlpha = 0.2f;
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400272 auto fp = GrTextureEffect::MakeSubset(src, kPremul_SkAlphaType, SkMatrix::I(),
273 sampler, SkRect::Make(srcRect), caps);
Brian Osmanf48f76e2020-07-15 16:04:17 -0400274 fp = GrFragmentProcessor::ModulateRGBA(std::move(fp),
275 {kAlpha, kAlpha, kAlpha, kAlpha});
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400276 GrPaint paint;
John Stiles5933d7d2020-07-21 12:28:35 -0400277 paint.setColorFragmentProcessor(std::move(fp));
Brian Salomonf9707462021-03-15 16:50:04 -0400278 sdc->drawRect(nullptr, std::move(paint), GrAA::kNo, m, SkRect::Make(testArea));
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400279 }
280 // Do a blur for each dstRect in the set over our testArea-sized background.
281 for (const auto& dstRect : dstRectSet) {
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400282 const SkScalar sigmaX = src.width() / 10.f;
283 const SkScalar sigmaY = src.height() / 10.f;
Brian Salomonf9707462021-03-15 16:50:04 -0400284 auto blurFn = ref ? slow_blur : blur;
Brian Salomon702c5a32020-04-28 16:21:48 -0400285 // Blur using the rect and draw on top.
Brian Salomonf9707462021-03-15 16:50:04 -0400286 if (auto blurView = blurFn(rContext,
287 src,
288 dstRect,
289 srcRect,
290 sigmaX,
291 sigmaY,
292 mode)) {
293 auto fp = GrTextureEffect::Make(blurView,
294 kPremul_SkAlphaType,
295 SkMatrix::I(),
296 sampler,
297 caps);
298 // Compose against white (default paint color)
Brian Salomon4b6e2f02021-07-08 14:04:21 -0400299 fp = GrBlendFragmentProcessor::Make(std::move(fp),
300 /*dst=*/nullptr,
301 SkBlendMode::kSrcOver);
Brian Salomon702c5a32020-04-28 16:21:48 -0400302 GrPaint paint;
303 // Compose against white (default paint color) and then replace the dst
304 // (SkBlendMode::kSrc).
Brian Salomon4b6e2f02021-07-08 14:04:21 -0400305 fp = GrBlendFragmentProcessor::Make(std::move(fp),
306 /*dst=*/nullptr,
307 SkBlendMode::kSrcOver);
John Stiles5933d7d2020-07-21 12:28:35 -0400308 paint.setColorFragmentProcessor(std::move(fp));
Brian Salomon702c5a32020-04-28 16:21:48 -0400309 paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
Brian Salomonf9707462021-03-15 16:50:04 -0400310 sdc->fillRectToRect(nullptr,
311 std::move(paint),
312 GrAA::kNo,
313 m,
314 SkRect::Make(dstRect),
315 SkRect::Make(blurView.dimensions()));
Brian Salomon702c5a32020-04-28 16:21:48 -0400316 }
Brian Salomon702c5a32020-04-28 16:21:48 -0400317 // Show the outline of the dst rect. Mostly for kDecal but also allows visual
318 // confirmation that the resulting blur is the right size and in the right place.
319 {
320 GrPaint paint;
321 static constexpr float kAlpha = 0.6f;
322 paint.setColor4f({0, kAlpha, 0, kAlpha});
323 SkPaint stroke;
324 stroke.setStyle(SkPaint::kStroke_Style);
325 stroke.setStrokeWidth(1.f);
326 GrStyle style(stroke);
327 auto dstR = SkRect::Make(dstRect).makeOutset(0.5f, 0.5f);
Brian Salomonf9707462021-03-15 16:50:04 -0400328 sdc->drawRect(nullptr, std::move(paint), GrAA::kNo, m, dstR, &style);
Brian Salomon702c5a32020-04-28 16:21:48 -0400329 }
Brian Salomon702c5a32020-04-28 16:21:48 -0400330 }
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400331 // Show the rect that's being blurred.
332 {
333 GrPaint paint;
334 static constexpr float kAlpha = 0.3f;
335 paint.setColor4f({0, 0, 0, kAlpha});
336 SkPaint stroke;
337 stroke.setStyle(SkPaint::kStroke_Style);
338 stroke.setStrokeWidth(1.f);
339 GrStyle style(stroke);
340 auto srcR = SkRect::Make(srcRect).makeOutset(0.5f, 0.5f);
Brian Salomonf9707462021-03-15 16:50:04 -0400341 sdc->drawRect(nullptr, std::move(paint), GrAA::kNo, m, srcR, &style);
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400342 }
343 trans.fX += testArea.width() + kPad;
Brian Salomon702c5a32020-04-28 16:21:48 -0400344 }
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400345 trans.fX = kPad;
346 trans.fY += testArea.height() + kPad;
Brian Salomon702c5a32020-04-28 16:21:48 -0400347 }
Robert Phillips7a0d3c32021-07-21 15:39:51 -0400348
349 return DrawResult::kOk;
Brian Salomon702c5a32020-04-28 16:21:48 -0400350}
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400351
Robert Phillips7a0d3c32021-07-21 15:39:51 -0400352DEF_SIMPLE_GPU_GM_CAN_FAIL(gpu_blur_utils, rContext, canvas, errorMsg, 765, 955) {
353 return run(rContext, canvas, errorMsg, false, false);
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400354}
355
Robert Phillips7a0d3c32021-07-21 15:39:51 -0400356DEF_SIMPLE_GPU_GM_CAN_FAIL(gpu_blur_utils_ref, rContext, canvas, errorMsg, 765, 955) {
357 return run(rContext, canvas, errorMsg, false, true);
358}
359
360DEF_SIMPLE_GPU_GM_CAN_FAIL(gpu_blur_utils_subset_rect, rContext, canvas, errorMsg, 485, 730) {
361 return run(rContext, canvas, errorMsg, true, false);
362}
363
364DEF_SIMPLE_GPU_GM_CAN_FAIL(gpu_blur_utils_subset_ref, rContext, canvas, errorMsg, 485, 730) {
365 return run(rContext, canvas, errorMsg, true, true);
Brian Salomonf9707462021-03-15 16:50:04 -0400366}
367
368// Because of the way blur sigmas concat (sigTotal = sqrt(sig1^2 + sig2^2) generating these images
369// for very large sigmas is incredibly slow. This can be enabled while working on the blur code to
Brian Salomoned3c75b2021-03-23 09:22:00 -0400370// check results.
Brian Salomonf9707462021-03-15 16:50:04 -0400371static bool constexpr kShowSlowRefImages = false;
372
Robert Phillips7a0d3c32021-07-21 15:39:51 -0400373static DrawResult do_very_large_blur_gm(GrRecordingContext* rContext,
374 SkCanvas* canvas,
375 SkString* errorMsg,
376 GrSurfaceProxyView src,
377 SkIRect srcB) {
378 auto sdc = SkCanvasPriv::TopDeviceSurfaceDrawContext(canvas);
379 if (!sdc) {
380 *errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly;
381 return DrawResult::kSkip;
382 }
383
Brian Salomonf9707462021-03-15 16:50:04 -0400384 // Clear to a color other than gray to contrast with test image.
385 sdc->clear(SkColor4f{0.3f, 0.4f, 0.2f, 1});
386
387 int x = 10;
388 int y = 10;
389 for (auto blurDirs : {0b01, 0b10, 0b11}) {
390 for (int t = 0; t <= static_cast<int>(SkTileMode::kLastTileMode); ++t) {
391 auto tm = static_cast<SkTileMode>(t);
392 auto dstB = srcB.makeOutset(30, 30);
Brian Salomoned3c75b2021-03-23 09:22:00 -0400393 for (float sigma : {0.f, 5.f, 25.f, 80.f}) {
Brian Salomonf9707462021-03-15 16:50:04 -0400394 std::vector<decltype(blur)*> blurs;
395 blurs.push_back(blur);
396 if (kShowSlowRefImages) {
397 blurs.push_back(slow_blur);
398 }
399 for (auto b : blurs) {
400 float sigX = sigma*((blurDirs & 0b01) >> 0);
401 float sigY = sigma*((blurDirs & 0b10) >> 1);
402 GrSurfaceProxyView result = b(rContext, src, dstB, srcB, sigX, sigY, tm);
403 auto dstRect = SkIRect::MakeSize(dstB.size()).makeOffset(x, y);
404 // Draw a rect to show where the result should be so it's obvious if it's
405 // missing.
406 GrPaint paint;
407 paint.setColor4f(b == blur ? SkPMColor4f{0, 0, 1, 1} : SkPMColor4f{1, 0, 0, 1});
408 sdc->drawRect(nullptr,
409 std::move(paint),
410 GrAA::kNo,
411 SkMatrix::I(),
412 SkRect::Make(dstRect).makeOutset(0.5, 0.5),
413 &GrStyle::SimpleHairline());
414 if (result) {
415 std::unique_ptr<GrFragmentProcessor> fp =
416 GrTextureEffect::Make(std::move(result), kPremul_SkAlphaType);
Brian Salomon4b6e2f02021-07-08 14:04:21 -0400417 fp = GrBlendFragmentProcessor::Make(std::move(fp),
418 /*dst=*/nullptr,
419 SkBlendMode::kSrcOver);
Brian Salomonf9707462021-03-15 16:50:04 -0400420 sdc->fillRectToRectWithFP(SkIRect::MakeSize(dstB.size()),
421 dstRect,
422 std::move(fp));
423 }
424 x += dstB.width() + 10;
425 }
426 }
427 x = 10;
428 y += dstB.height() + 10;
429 }
430 }
Robert Phillips7a0d3c32021-07-21 15:39:51 -0400431
432 return DrawResult::kOk;
Brian Salomonf9707462021-03-15 16:50:04 -0400433}
434
Robert Phillips7a0d3c32021-07-21 15:39:51 -0400435DEF_SIMPLE_GPU_GM_CAN_FAIL(very_large_sigma_gpu_blur, rContext, canvas, errorMsg, 350, 1030) {
436 auto src = make_src_image(rContext, {15, 15});
Brian Salomonf9707462021-03-15 16:50:04 -0400437 auto srcB = SkIRect::MakeSize(src.dimensions());
Robert Phillips7a0d3c32021-07-21 15:39:51 -0400438 return do_very_large_blur_gm(rContext, canvas, errorMsg, std::move(src), srcB);
Brian Salomonf9707462021-03-15 16:50:04 -0400439}
440
Robert Phillips7a0d3c32021-07-21 15:39:51 -0400441DEF_SIMPLE_GPU_GM_CAN_FAIL(very_large_sigma_gpu_blur_subset,
442 rContext,
443 canvas,
444 errorMsg,
445 350, 1030) {
Brian Salomoned3c75b2021-03-23 09:22:00 -0400446 auto srcB = SkIRect::MakeXYWH(2, 2, 15, 15);
Brian Salomonf9707462021-03-15 16:50:04 -0400447 SkISize imageSize = SkISize{srcB.width() + 4, srcB.height() + 4};
Robert Phillips7a0d3c32021-07-21 15:39:51 -0400448 auto src = make_src_image(rContext, imageSize, &srcB);
449 return do_very_large_blur_gm(rContext, canvas, errorMsg, std::move(src), srcB);
Brian Salomonf9707462021-03-15 16:50:04 -0400450}
451
Robert Phillips7a0d3c32021-07-21 15:39:51 -0400452DEF_SIMPLE_GPU_GM_CAN_FAIL(very_large_sigma_gpu_blur_subset_transparent_border,
453 rContext,
454 canvas,
455 errorMsg,
456 355, 1055) {
Brian Salomoned3c75b2021-03-23 09:22:00 -0400457 auto srcB = SkIRect::MakeXYWH(3, 3, 15, 15);
Brian Salomonf9707462021-03-15 16:50:04 -0400458 SkISize imageSize = SkISize{srcB.width() + 4, srcB.height() + 4};
Robert Phillips7a0d3c32021-07-21 15:39:51 -0400459 auto src = make_src_image(rContext, imageSize, &srcB);
460 return do_very_large_blur_gm(rContext, canvas, errorMsg, std::move(src), srcB.makeOutset(1, 1));
Brian Salomon11ad4cc2020-05-15 12:07:59 -0400461}
Robert Phillips7a0d3c32021-07-21 15:39:51 -0400462
463} // namespace skiagm