2020-04-28 20:21:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 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"
|
|
|
|
|
2022-04-05 16:56:01 +00:00
|
|
|
#include "include/core/SkColorSpace.h"
|
2020-04-28 20:21:48 +00:00
|
|
|
#include "include/effects/SkGradientShader.h"
|
2020-11-12 19:48:28 +00:00
|
|
|
#include "include/gpu/GrRecordingContext.h"
|
2021-07-21 19:39:51 +00:00
|
|
|
#include "src/core/SkCanvasPriv.h"
|
2020-04-28 20:21:48 +00:00
|
|
|
#include "src/core/SkGpuBlurUtils.h"
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
|
|
|
|
#include "src/gpu/ganesh/GrStyle.h"
|
|
|
|
#include "src/gpu/ganesh/SkGr.h"
|
|
|
|
#include "src/gpu/ganesh/effects/GrBlendFragmentProcessor.h"
|
|
|
|
#include "src/gpu/ganesh/effects/GrTextureEffect.h"
|
|
|
|
#include "src/gpu/ganesh/v1/SurfaceDrawContext_v1.h"
|
2020-04-28 20:21:48 +00:00
|
|
|
#include "src/image/SkImage_Base.h"
|
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
namespace {
|
|
|
|
|
2020-06-29 19:36:12 +00:00
|
|
|
static GrSurfaceProxyView blur(GrRecordingContext* ctx,
|
2020-05-15 16:07:59 +00:00
|
|
|
GrSurfaceProxyView src,
|
|
|
|
SkIRect dstB,
|
|
|
|
SkIRect srcB,
|
|
|
|
float sigmaX,
|
|
|
|
float sigmaY,
|
|
|
|
SkTileMode mode) {
|
2021-03-15 20:50:04 +00:00
|
|
|
auto resultSDC = SkGpuBlurUtils::GaussianBlur(ctx,
|
|
|
|
src,
|
|
|
|
GrColorType::kRGBA_8888,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
nullptr,
|
|
|
|
dstB,
|
|
|
|
srcB,
|
|
|
|
sigmaX,
|
|
|
|
sigmaY,
|
|
|
|
mode);
|
|
|
|
if (!resultSDC) {
|
2020-05-15 16:07:59 +00:00
|
|
|
return {};
|
|
|
|
}
|
2021-03-15 20:50:04 +00:00
|
|
|
return resultSDC->readSurfaceView();
|
2020-05-15 16:07:59 +00:00
|
|
|
};
|
|
|
|
|
2021-03-15 20:50:04 +00:00
|
|
|
// Performs tiling first of the src into dst bounds with a surrounding skirt so the blur can use
|
|
|
|
// clamp. Does repeated blurs rather than invoking downsampling.
|
2021-08-02 15:14:38 +00:00
|
|
|
static GrSurfaceProxyView slow_blur(GrRecordingContext* rContext,
|
2021-03-15 20:50:04 +00:00
|
|
|
GrSurfaceProxyView src,
|
|
|
|
SkIRect dstB,
|
|
|
|
SkIRect srcB,
|
|
|
|
float sigmaX,
|
|
|
|
float sigmaY,
|
|
|
|
SkTileMode mode) {
|
2021-08-02 15:14:38 +00:00
|
|
|
auto tileInto = [rContext](GrSurfaceProxyView src,
|
|
|
|
SkIRect srcTileRect,
|
|
|
|
SkISize resultSize,
|
|
|
|
SkIPoint offset,
|
|
|
|
SkTileMode mode) {
|
2021-03-15 20:50:04 +00:00
|
|
|
GrImageInfo info(GrColorType::kRGBA_8888, kPremul_SkAlphaType, nullptr, resultSize);
|
2021-08-02 15:14:38 +00:00
|
|
|
auto sfc = rContext->priv().makeSFC(info);
|
2021-07-26 17:23:10 +00:00
|
|
|
if (!sfc) {
|
2021-03-15 20:50:04 +00:00
|
|
|
return GrSurfaceProxyView{};
|
|
|
|
}
|
|
|
|
GrSamplerState sampler(SkTileModeToWrapMode(mode), SkFilterMode::kNearest);
|
|
|
|
auto fp = GrTextureEffect::MakeSubset(src,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
SkMatrix::Translate(-offset.x(), -offset.y()),
|
|
|
|
sampler,
|
|
|
|
SkRect::Make(srcTileRect),
|
2021-08-02 15:14:38 +00:00
|
|
|
*rContext->priv().caps());
|
2021-07-26 17:23:10 +00:00
|
|
|
sfc->fillWithFP(std::move(fp));
|
|
|
|
return sfc->readSurfaceView();
|
2021-03-15 20:50:04 +00:00
|
|
|
};
|
2020-04-28 20:21:48 +00:00
|
|
|
|
2021-03-15 20:50:04 +00:00
|
|
|
SkIPoint outset = {SkGpuBlurUtils::SigmaRadius(sigmaX), SkGpuBlurUtils::SigmaRadius(sigmaY)};
|
|
|
|
SkISize size = {dstB.width() + 2*outset.x(), dstB.height() + 2*outset.y()};
|
|
|
|
src = tileInto(std::move(src), srcB, size, outset - dstB.topLeft(), mode);
|
|
|
|
if (!src) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
dstB = SkIRect::MakePtSize(outset, dstB.size());
|
2020-04-28 20:21:48 +00:00
|
|
|
|
2021-03-15 20:50:04 +00:00
|
|
|
while (sigmaX || sigmaY) {
|
|
|
|
float stepX = sigmaX;
|
|
|
|
if (stepX > SkGpuBlurUtils::kMaxSigma) {
|
|
|
|
stepX = SkGpuBlurUtils::kMaxSigma;
|
|
|
|
// A blur of sigma1 followed by a blur of sigma2 is equiv. to a single blur of
|
|
|
|
// sqrt(sigma1^2 + sigma2^2).
|
|
|
|
sigmaX = sqrt(sigmaX*sigmaX - SkGpuBlurUtils::kMaxSigma*SkGpuBlurUtils::kMaxSigma);
|
|
|
|
} else {
|
|
|
|
sigmaX = 0.f;
|
|
|
|
}
|
|
|
|
float stepY = sigmaY;
|
|
|
|
if (stepY > SkGpuBlurUtils::kMaxSigma) {
|
|
|
|
stepY = SkGpuBlurUtils::kMaxSigma;
|
|
|
|
sigmaY = sqrt(sigmaY*sigmaY- SkGpuBlurUtils::kMaxSigma*SkGpuBlurUtils::kMaxSigma);
|
|
|
|
} else {
|
|
|
|
sigmaY = 0.f;
|
|
|
|
}
|
|
|
|
auto bounds = SkIRect::MakeSize(src.dimensions());
|
2021-08-02 15:14:38 +00:00
|
|
|
auto sdc = SkGpuBlurUtils::GaussianBlur(rContext,
|
2021-03-15 20:50:04 +00:00
|
|
|
std::move(src),
|
|
|
|
GrColorType::kRGBA_8888,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
nullptr,
|
|
|
|
bounds,
|
|
|
|
bounds,
|
|
|
|
stepX,
|
|
|
|
stepY,
|
|
|
|
SkTileMode::kClamp);
|
|
|
|
if (!sdc) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
src = sdc->readSurfaceView();
|
2020-04-28 20:21:48 +00:00
|
|
|
}
|
2021-03-15 20:50:04 +00:00
|
|
|
// We have o use the original mode here because we may have only blurred in X or Y and then
|
|
|
|
// the other dimension was not expanded.
|
|
|
|
auto srcRect = SkIRect::MakeSize(src.dimensions());
|
|
|
|
return tileInto(std::move(src), srcRect, dstB.size(), -outset, SkTileMode::kClamp);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Makes a src texture for as a source for blurs. If 'contentArea' then the content will
|
|
|
|
// be in that rect, the 1-pixel surrounding border will be transparent black, and red outside of
|
|
|
|
// that. Otherwise, the content fills the dimensions.
|
|
|
|
GrSurfaceProxyView make_src_image(GrRecordingContext* rContext,
|
|
|
|
SkISize dimensions,
|
|
|
|
const SkIRect* contentArea = nullptr) {
|
|
|
|
auto srcII = SkImageInfo::Make(dimensions, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
auto surf = SkSurface::MakeRenderTarget(rContext, SkBudgeted::kYes, srcII);
|
|
|
|
if (!surf) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
float w, h;
|
|
|
|
if (contentArea) {
|
|
|
|
surf->getCanvas()->clear(SK_ColorRED);
|
|
|
|
surf->getCanvas()->clipIRect(contentArea->makeOutset(1, 1));
|
|
|
|
surf->getCanvas()->clear(SK_ColorTRANSPARENT);
|
|
|
|
surf->getCanvas()->clipIRect(*contentArea);
|
|
|
|
surf->getCanvas()->translate(contentArea->top(), contentArea->left());
|
|
|
|
w = contentArea->width();
|
|
|
|
h = contentArea->height();
|
|
|
|
} else {
|
|
|
|
w = dimensions.width();
|
|
|
|
h = dimensions.height();
|
|
|
|
}
|
|
|
|
|
|
|
|
surf->getCanvas()->drawColor(SK_ColorDKGRAY);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
// Draw four horizontal lines at 1/8, 1/4, 3/4, 7/8.
|
|
|
|
paint.setStrokeWidth(h/12.f);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
surf->getCanvas()->drawLine({0.f, 1.f*h/8.f}, {w, 1.f*h/8.f}, paint);
|
|
|
|
paint.setColor(/* sea foam */ 0xFF71EEB8);
|
|
|
|
surf->getCanvas()->drawLine({0.f, 1.f*h/4.f}, {w, 1.f*h/4.f}, paint);
|
|
|
|
paint.setColor(SK_ColorYELLOW);
|
|
|
|
surf->getCanvas()->drawLine({0.f, 3.f*h/4.f}, {w, 3.f*h/4.f}, paint);
|
|
|
|
paint.setColor(SK_ColorCYAN);
|
|
|
|
surf->getCanvas()->drawLine({0.f, 7.f*h/8.f}, {w, 7.f*h/8.f}, paint);
|
|
|
|
|
|
|
|
// Draw four vertical lines at 1/8, 1/4, 3/4, 7/8.
|
|
|
|
paint.setStrokeWidth(w/12.f);
|
|
|
|
paint.setColor(/* orange */ 0xFFFFA500);
|
|
|
|
surf->getCanvas()->drawLine({1.f*w/8.f, 0.f}, {1.f*h/8.f, h}, paint);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
surf->getCanvas()->drawLine({1.f*w/4.f, 0.f}, {1.f*h/4.f, h}, paint);
|
|
|
|
paint.setColor(SK_ColorMAGENTA);
|
|
|
|
surf->getCanvas()->drawLine({3.f*w/4.f, 0.f}, {3.f*h/4.f, h}, paint);
|
|
|
|
paint.setColor(SK_ColorGREEN);
|
|
|
|
surf->getCanvas()->drawLine({7.f*w/8.f, 0.f}, {7.f*h/8.f, h}, paint);
|
|
|
|
|
|
|
|
auto img = surf->makeImageSnapshot();
|
|
|
|
auto [src, ct] = as_IB(img)->asView(rContext, GrMipmapped::kNo);
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
static GM::DrawResult run(GrRecordingContext* rContext, SkCanvas* canvas, SkString* errorMsg,
|
|
|
|
bool subsetSrc, bool ref) {
|
2021-03-15 20:50:04 +00:00
|
|
|
GrSurfaceProxyView src = make_src_image(rContext, {60, 60});
|
2020-04-28 20:21:48 +00:00
|
|
|
if (!src) {
|
2021-07-21 19:39:51 +00:00
|
|
|
*errorMsg = "Failed to create source image";
|
|
|
|
return DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto sdc = SkCanvasPriv::TopDeviceSurfaceDrawContext(canvas);
|
|
|
|
if (!sdc) {
|
|
|
|
*errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly;
|
|
|
|
return DrawResult::kSkip;
|
2020-04-28 20:21:48 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 16:07:59 +00:00
|
|
|
SkIRect srcRect = SkIRect::MakeSize(src.dimensions());
|
|
|
|
if (subsetSrc) {
|
|
|
|
srcRect = SkIRect::MakeXYWH(2.f*srcRect.width() /8.f,
|
|
|
|
1.f*srcRect.height()/8.f,
|
|
|
|
5.f*srcRect.width() /8.f,
|
|
|
|
6.f*srcRect.height()/8.f);
|
|
|
|
}
|
|
|
|
int srcW = srcRect.width();
|
|
|
|
int srcH = srcRect.height();
|
|
|
|
// Each set of rects is drawn in one test area so they probably should not abut or overlap
|
|
|
|
// to visualize the blurs separately.
|
|
|
|
const std::vector<SkIRect> dstRectSets[] = {
|
2020-05-19 18:24:43 +00:00
|
|
|
// encloses source bounds.
|
2020-05-15 16:07:59 +00:00
|
|
|
{
|
|
|
|
srcRect.makeOutset(srcW/5, srcH/5)
|
|
|
|
},
|
|
|
|
|
2020-05-19 18:24:43 +00:00
|
|
|
// partial overlap from above/below.
|
2020-05-15 16:07:59 +00:00
|
|
|
{
|
|
|
|
SkIRect::MakeXYWH(srcRect.x(), srcRect.y() + 3*srcH/4, srcW, srcH),
|
|
|
|
SkIRect::MakeXYWH(srcRect.x(), srcRect.y() - 3*srcH/4, srcW, srcH)
|
|
|
|
},
|
2020-05-13 21:16:01 +00:00
|
|
|
|
2020-05-19 18:24:43 +00:00
|
|
|
// adjacent to each side of src bounds.
|
2020-05-15 16:07:59 +00:00
|
|
|
{
|
|
|
|
srcRect.makeOffset( 0, srcH),
|
|
|
|
srcRect.makeOffset( srcW, 0),
|
|
|
|
srcRect.makeOffset( 0, -srcH),
|
|
|
|
srcRect.makeOffset(-srcW, 0),
|
|
|
|
},
|
|
|
|
|
2020-05-19 18:24:43 +00:00
|
|
|
// fully outside src bounds in one direction.
|
2020-05-15 16:07:59 +00:00
|
|
|
{
|
|
|
|
SkIRect::MakeXYWH(-6.f*srcW/8.f, -7.f*srcH/8.f, 4.f*srcW/8.f, 20.f*srcH/8.f)
|
|
|
|
.makeOffset(srcRect.topLeft()),
|
|
|
|
SkIRect::MakeXYWH(-1.f*srcW/8.f, -7.f*srcH/8.f, 16.f*srcW/8.f, 2.f*srcH/8.f)
|
|
|
|
.makeOffset(srcRect.topLeft()),
|
|
|
|
SkIRect::MakeXYWH(10.f*srcW/8.f, -3.f*srcH/8.f, 4.f*srcW/8.f, 16.f*srcH/8.f)
|
|
|
|
.makeOffset(srcRect.topLeft()),
|
|
|
|
SkIRect::MakeXYWH(-7.f*srcW/8.f, 14.f*srcH/8.f, 18.f*srcW/8.f, 1.f*srcH/8.f)
|
|
|
|
.makeOffset(srcRect.topLeft()),
|
|
|
|
},
|
2020-05-19 18:24:43 +00:00
|
|
|
|
|
|
|
// outside of src bounds in both directions.
|
|
|
|
{
|
|
|
|
SkIRect::MakeXYWH(-5.f*srcW/8.f, -5.f*srcH/8.f, 2.f*srcW/8.f, 2.f*srcH/8.f)
|
|
|
|
.makeOffset(srcRect.topLeft()),
|
|
|
|
SkIRect::MakeXYWH(-5.f*srcW/8.f, 12.f*srcH/8.f, 2.f*srcW/8.f, 2.f*srcH/8.f)
|
|
|
|
.makeOffset(srcRect.topLeft()),
|
|
|
|
SkIRect::MakeXYWH(12.f*srcW/8.f, -5.f*srcH/8.f, 2.f*srcW/8.f, 2.f*srcH/8.f)
|
|
|
|
.makeOffset(srcRect.topLeft()),
|
|
|
|
SkIRect::MakeXYWH(12.f*srcW/8.f, 12.f*srcH/8.f, 2.f*srcW/8.f, 2.f*srcH/8.f)
|
|
|
|
.makeOffset(srcRect.topLeft()),
|
|
|
|
},
|
2020-04-28 20:21:48 +00:00
|
|
|
};
|
|
|
|
|
2020-11-12 19:48:28 +00:00
|
|
|
const auto& caps = *rContext->priv().caps();
|
2020-05-15 16:07:59 +00:00
|
|
|
|
|
|
|
static constexpr SkScalar kPad = 10;
|
|
|
|
SkVector trans = {kPad, kPad};
|
|
|
|
|
2021-03-15 20:50:04 +00:00
|
|
|
sdc->clear(SK_PMColor4fWHITE);
|
2020-05-15 16:07:59 +00:00
|
|
|
|
|
|
|
SkIRect testArea = srcRect;
|
|
|
|
testArea.outset(testArea.width(), testArea.height());
|
|
|
|
for (const auto& dstRectSet : dstRectSets) {
|
|
|
|
for (int t = 0; t < kSkTileModeCount; ++t) {
|
|
|
|
auto mode = static_cast<SkTileMode>(t);
|
|
|
|
GrSamplerState sampler(SkTileModeToWrapMode(mode), GrSamplerState::Filter::kNearest);
|
2020-05-21 16:11:27 +00:00
|
|
|
SkMatrix m = SkMatrix::Translate(trans.x() - testArea.x(), trans.y() - testArea.y());
|
2020-05-15 16:07:59 +00:00
|
|
|
// Draw the src subset in the tile mode faded as a reference before drawing the blur
|
|
|
|
// on top.
|
|
|
|
{
|
2020-07-15 20:04:17 +00:00
|
|
|
static constexpr float kAlpha = 0.2f;
|
2020-05-15 16:07:59 +00:00
|
|
|
auto fp = GrTextureEffect::MakeSubset(src, kPremul_SkAlphaType, SkMatrix::I(),
|
|
|
|
sampler, SkRect::Make(srcRect), caps);
|
2020-07-15 20:04:17 +00:00
|
|
|
fp = GrFragmentProcessor::ModulateRGBA(std::move(fp),
|
|
|
|
{kAlpha, kAlpha, kAlpha, kAlpha});
|
2020-05-15 16:07:59 +00:00
|
|
|
GrPaint paint;
|
2020-07-21 16:28:35 +00:00
|
|
|
paint.setColorFragmentProcessor(std::move(fp));
|
2021-03-15 20:50:04 +00:00
|
|
|
sdc->drawRect(nullptr, std::move(paint), GrAA::kNo, m, SkRect::Make(testArea));
|
2020-05-15 16:07:59 +00:00
|
|
|
}
|
|
|
|
// Do a blur for each dstRect in the set over our testArea-sized background.
|
|
|
|
for (const auto& dstRect : dstRectSet) {
|
|
|
|
const SkScalar sigmaX = src.width() / 10.f;
|
|
|
|
const SkScalar sigmaY = src.height() / 10.f;
|
2021-03-15 20:50:04 +00:00
|
|
|
auto blurFn = ref ? slow_blur : blur;
|
2020-04-28 20:21:48 +00:00
|
|
|
// Blur using the rect and draw on top.
|
2021-03-15 20:50:04 +00:00
|
|
|
if (auto blurView = blurFn(rContext,
|
|
|
|
src,
|
|
|
|
dstRect,
|
|
|
|
srcRect,
|
|
|
|
sigmaX,
|
|
|
|
sigmaY,
|
|
|
|
mode)) {
|
|
|
|
auto fp = GrTextureEffect::Make(blurView,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
SkMatrix::I(),
|
|
|
|
sampler,
|
|
|
|
caps);
|
|
|
|
// Compose against white (default paint color)
|
2022-03-29 23:15:01 +00:00
|
|
|
fp = GrBlendFragmentProcessor::Make<SkBlendMode::kSrcOver>(std::move(fp),
|
|
|
|
/*dst=*/nullptr);
|
2020-04-28 20:21:48 +00:00
|
|
|
GrPaint paint;
|
|
|
|
// Compose against white (default paint color) and then replace the dst
|
|
|
|
// (SkBlendMode::kSrc).
|
2022-03-29 23:15:01 +00:00
|
|
|
fp = GrBlendFragmentProcessor::Make<SkBlendMode::kSrcOver>(std::move(fp),
|
|
|
|
/*dst=*/nullptr);
|
2020-07-21 16:28:35 +00:00
|
|
|
paint.setColorFragmentProcessor(std::move(fp));
|
2020-04-28 20:21:48 +00:00
|
|
|
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
|
2021-03-15 20:50:04 +00:00
|
|
|
sdc->fillRectToRect(nullptr,
|
|
|
|
std::move(paint),
|
|
|
|
GrAA::kNo,
|
|
|
|
m,
|
|
|
|
SkRect::Make(dstRect),
|
|
|
|
SkRect::Make(blurView.dimensions()));
|
2020-04-28 20:21:48 +00:00
|
|
|
}
|
|
|
|
// Show the outline of the dst rect. Mostly for kDecal but also allows visual
|
|
|
|
// confirmation that the resulting blur is the right size and in the right place.
|
|
|
|
{
|
|
|
|
GrPaint paint;
|
|
|
|
static constexpr float kAlpha = 0.6f;
|
|
|
|
paint.setColor4f({0, kAlpha, 0, kAlpha});
|
|
|
|
SkPaint stroke;
|
|
|
|
stroke.setStyle(SkPaint::kStroke_Style);
|
|
|
|
stroke.setStrokeWidth(1.f);
|
|
|
|
GrStyle style(stroke);
|
|
|
|
auto dstR = SkRect::Make(dstRect).makeOutset(0.5f, 0.5f);
|
2021-03-15 20:50:04 +00:00
|
|
|
sdc->drawRect(nullptr, std::move(paint), GrAA::kNo, m, dstR, &style);
|
2020-04-28 20:21:48 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-15 16:07:59 +00:00
|
|
|
// Show the rect that's being blurred.
|
|
|
|
{
|
|
|
|
GrPaint paint;
|
|
|
|
static constexpr float kAlpha = 0.3f;
|
|
|
|
paint.setColor4f({0, 0, 0, kAlpha});
|
|
|
|
SkPaint stroke;
|
|
|
|
stroke.setStyle(SkPaint::kStroke_Style);
|
|
|
|
stroke.setStrokeWidth(1.f);
|
|
|
|
GrStyle style(stroke);
|
|
|
|
auto srcR = SkRect::Make(srcRect).makeOutset(0.5f, 0.5f);
|
2021-03-15 20:50:04 +00:00
|
|
|
sdc->drawRect(nullptr, std::move(paint), GrAA::kNo, m, srcR, &style);
|
2020-05-15 16:07:59 +00:00
|
|
|
}
|
|
|
|
trans.fX += testArea.width() + kPad;
|
2020-04-28 20:21:48 +00:00
|
|
|
}
|
2020-05-15 16:07:59 +00:00
|
|
|
trans.fX = kPad;
|
|
|
|
trans.fY += testArea.height() + kPad;
|
2020-04-28 20:21:48 +00:00
|
|
|
}
|
2021-07-21 19:39:51 +00:00
|
|
|
|
|
|
|
return DrawResult::kOk;
|
2020-04-28 20:21:48 +00:00
|
|
|
}
|
2020-05-15 16:07:59 +00:00
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
DEF_SIMPLE_GPU_GM_CAN_FAIL(gpu_blur_utils, rContext, canvas, errorMsg, 765, 955) {
|
|
|
|
return run(rContext, canvas, errorMsg, false, false);
|
|
|
|
}
|
2021-03-15 20:50:04 +00:00
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
DEF_SIMPLE_GPU_GM_CAN_FAIL(gpu_blur_utils_ref, rContext, canvas, errorMsg, 765, 955) {
|
|
|
|
return run(rContext, canvas, errorMsg, false, true);
|
|
|
|
}
|
2021-03-15 20:50:04 +00:00
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
DEF_SIMPLE_GPU_GM_CAN_FAIL(gpu_blur_utils_subset_rect, rContext, canvas, errorMsg, 485, 730) {
|
|
|
|
return run(rContext, canvas, errorMsg, true, false);
|
2021-03-15 20:50:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
DEF_SIMPLE_GPU_GM_CAN_FAIL(gpu_blur_utils_subset_ref, rContext, canvas, errorMsg, 485, 730) {
|
|
|
|
return run(rContext, canvas, errorMsg, true, true);
|
2021-03-15 20:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Because of the way blur sigmas concat (sigTotal = sqrt(sig1^2 + sig2^2) generating these images
|
|
|
|
// for very large sigmas is incredibly slow. This can be enabled while working on the blur code to
|
2021-03-23 13:22:00 +00:00
|
|
|
// check results.
|
2021-03-15 20:50:04 +00:00
|
|
|
static bool constexpr kShowSlowRefImages = false;
|
2020-05-15 16:07:59 +00:00
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
static DrawResult do_very_large_blur_gm(GrRecordingContext* rContext,
|
|
|
|
SkCanvas* canvas,
|
|
|
|
SkString* errorMsg,
|
|
|
|
GrSurfaceProxyView src,
|
|
|
|
SkIRect srcB) {
|
|
|
|
auto sdc = SkCanvasPriv::TopDeviceSurfaceDrawContext(canvas);
|
|
|
|
if (!sdc) {
|
|
|
|
*errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly;
|
|
|
|
return DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
|
2021-03-15 20:50:04 +00:00
|
|
|
// Clear to a color other than gray to contrast with test image.
|
|
|
|
sdc->clear(SkColor4f{0.3f, 0.4f, 0.2f, 1});
|
|
|
|
|
|
|
|
int x = 10;
|
|
|
|
int y = 10;
|
|
|
|
for (auto blurDirs : {0b01, 0b10, 0b11}) {
|
2022-01-11 15:41:44 +00:00
|
|
|
for (int t = 0; t < kSkTileModeCount; ++t) {
|
2021-03-15 20:50:04 +00:00
|
|
|
auto tm = static_cast<SkTileMode>(t);
|
|
|
|
auto dstB = srcB.makeOutset(30, 30);
|
2021-03-23 13:22:00 +00:00
|
|
|
for (float sigma : {0.f, 5.f, 25.f, 80.f}) {
|
2021-03-15 20:50:04 +00:00
|
|
|
std::vector<decltype(blur)*> blurs;
|
|
|
|
blurs.push_back(blur);
|
|
|
|
if (kShowSlowRefImages) {
|
|
|
|
blurs.push_back(slow_blur);
|
|
|
|
}
|
|
|
|
for (auto b : blurs) {
|
|
|
|
float sigX = sigma*((blurDirs & 0b01) >> 0);
|
|
|
|
float sigY = sigma*((blurDirs & 0b10) >> 1);
|
|
|
|
GrSurfaceProxyView result = b(rContext, src, dstB, srcB, sigX, sigY, tm);
|
|
|
|
auto dstRect = SkIRect::MakeSize(dstB.size()).makeOffset(x, y);
|
|
|
|
// Draw a rect to show where the result should be so it's obvious if it's
|
|
|
|
// missing.
|
|
|
|
GrPaint paint;
|
|
|
|
paint.setColor4f(b == blur ? SkPMColor4f{0, 0, 1, 1} : SkPMColor4f{1, 0, 0, 1});
|
|
|
|
sdc->drawRect(nullptr,
|
|
|
|
std::move(paint),
|
|
|
|
GrAA::kNo,
|
|
|
|
SkMatrix::I(),
|
|
|
|
SkRect::Make(dstRect).makeOutset(0.5, 0.5),
|
|
|
|
&GrStyle::SimpleHairline());
|
|
|
|
if (result) {
|
|
|
|
std::unique_ptr<GrFragmentProcessor> fp =
|
|
|
|
GrTextureEffect::Make(std::move(result), kPremul_SkAlphaType);
|
2022-03-29 23:15:01 +00:00
|
|
|
fp = GrBlendFragmentProcessor::Make<SkBlendMode::kSrcOver>(std::move(fp),
|
|
|
|
/*dst=*/nullptr);
|
2021-03-15 20:50:04 +00:00
|
|
|
sdc->fillRectToRectWithFP(SkIRect::MakeSize(dstB.size()),
|
|
|
|
dstRect,
|
|
|
|
std::move(fp));
|
|
|
|
}
|
|
|
|
x += dstB.width() + 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
x = 10;
|
|
|
|
y += dstB.height() + 10;
|
|
|
|
}
|
|
|
|
}
|
2021-07-21 19:39:51 +00:00
|
|
|
|
|
|
|
return DrawResult::kOk;
|
2021-03-15 20:50:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
DEF_SIMPLE_GPU_GM_CAN_FAIL(very_large_sigma_gpu_blur, rContext, canvas, errorMsg, 350, 1030) {
|
|
|
|
auto src = make_src_image(rContext, {15, 15});
|
2021-03-15 20:50:04 +00:00
|
|
|
auto srcB = SkIRect::MakeSize(src.dimensions());
|
2021-07-21 19:39:51 +00:00
|
|
|
return do_very_large_blur_gm(rContext, canvas, errorMsg, std::move(src), srcB);
|
2021-03-15 20:50:04 +00:00
|
|
|
}
|
2020-05-15 16:07:59 +00:00
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
DEF_SIMPLE_GPU_GM_CAN_FAIL(very_large_sigma_gpu_blur_subset,
|
|
|
|
rContext,
|
|
|
|
canvas,
|
|
|
|
errorMsg,
|
|
|
|
350, 1030) {
|
2021-03-23 13:22:00 +00:00
|
|
|
auto srcB = SkIRect::MakeXYWH(2, 2, 15, 15);
|
2021-03-15 20:50:04 +00:00
|
|
|
SkISize imageSize = SkISize{srcB.width() + 4, srcB.height() + 4};
|
2021-07-21 19:39:51 +00:00
|
|
|
auto src = make_src_image(rContext, imageSize, &srcB);
|
|
|
|
return do_very_large_blur_gm(rContext, canvas, errorMsg, std::move(src), srcB);
|
2020-05-15 16:07:59 +00:00
|
|
|
}
|
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
DEF_SIMPLE_GPU_GM_CAN_FAIL(very_large_sigma_gpu_blur_subset_transparent_border,
|
|
|
|
rContext,
|
|
|
|
canvas,
|
|
|
|
errorMsg,
|
|
|
|
355, 1055) {
|
2021-03-23 13:22:00 +00:00
|
|
|
auto srcB = SkIRect::MakeXYWH(3, 3, 15, 15);
|
2021-03-15 20:50:04 +00:00
|
|
|
SkISize imageSize = SkISize{srcB.width() + 4, srcB.height() + 4};
|
2021-07-21 19:39:51 +00:00
|
|
|
auto src = make_src_image(rContext, imageSize, &srcB);
|
|
|
|
return do_very_large_blur_gm(rContext, canvas, errorMsg, std::move(src), srcB.makeOutset(1, 1));
|
2020-05-15 16:07:59 +00:00
|
|
|
}
|
2021-07-21 19:39:51 +00:00
|
|
|
|
|
|
|
} // namespace skiagm
|