diff options
author | robertphillips <robertphillips@google.com> | 2016-05-06 07:17:49 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-06 07:17:49 -0700 |
commit | 56a85e69a8d034e0fdee00e8207cda0a9da06fee (patch) | |
tree | 88851f5e9cfe7b4e4f0e570ac121d31a5b0b5f44 /src | |
parent | 6b53b9daeb2137a91d8ddb8e890d66c702bfbaa3 (diff) |
Simplify SkGpuBlurUtils::GaussianBlur method
No one was using the canClobberSrc capability and moving the direct filtering case forward makes the rest of the logic simpler.
Split out of: https://codereview.chromium.org/1959493002/ (Retract GrRenderTarget from SkGpuBlurUtils)
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1958603002
Review-Url: https://codereview.chromium.org/1958603002
Diffstat (limited to 'src')
-rw-r--r-- | src/effects/SkBlurImageFilter.cpp | 1 | ||||
-rw-r--r-- | src/effects/SkBlurMaskFilter.cpp | 2 | ||||
-rw-r--r-- | src/effects/SkGpuBlurUtils.cpp | 185 | ||||
-rw-r--r-- | src/effects/SkGpuBlurUtils.h | 3 | ||||
-rw-r--r-- | src/gpu/GrContext.cpp | 6 |
5 files changed, 97 insertions, 100 deletions
diff --git a/src/effects/SkBlurImageFilter.cpp b/src/effects/SkBlurImageFilter.cpp index bbe351db47..4e1fde250b 100644 --- a/src/effects/SkBlurImageFilter.cpp +++ b/src/effects/SkBlurImageFilter.cpp @@ -123,7 +123,6 @@ sk_sp<SkSpecialImage> SkBlurImageFilter::onFilterImage(SkSpecialImage* source, SkRect inputBoundsF(SkRect::Make(inputBounds)); sk_sp<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(context, inputTexture.get(), - false, source->props().isGammaCorrect(), SkRect::Make(dstBounds), &inputBoundsF, diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp index 6eb8474a2e..0215c3b169 100644 --- a/src/effects/SkBlurMaskFilter.cpp +++ b/src/effects/SkBlurMaskFilter.cpp @@ -1249,7 +1249,7 @@ bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src, // gaussianBlur. Otherwise, we need to save it for later compositing. bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle); *result = SkGpuBlurUtils::GaussianBlur(context, src, isNormalBlur && canOverwriteSrc, - false, clipRect, nullptr, + clipRect, nullptr, xformedSigma, xformedSigma); if (nullptr == *result) { return false; diff --git a/src/effects/SkGpuBlurUtils.cpp b/src/effects/SkGpuBlurUtils.cpp index c3681faca5..1cb2d1dd12 100644 --- a/src/effects/SkGpuBlurUtils.cpp +++ b/src/effects/SkGpuBlurUtils.cpp @@ -165,7 +165,6 @@ static void convolve_gaussian(GrDrawContext* drawContext, GrTexture* GaussianBlur(GrContext* context, GrTexture* srcTexture, - bool canClobberSrc, bool gammaCorrect, const SkRect& dstBounds, const SkRect* srcBounds, @@ -205,11 +204,38 @@ GrTexture* GaussianBlur(GrContext* context, kSBGRA_8888_GrPixelConfig == srcTexture->config() || kAlpha_8_GrPixelConfig == srcTexture->config()); + const int width = SkScalarFloorToInt(dstBounds.width()); + const int height = SkScalarFloorToInt(dstBounds.height()); + const GrPixelConfig config = srcTexture->config(); + + const SkSurfaceProps props(gammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag : 0, + SkSurfaceProps::kLegacyFontHost_InitType); + + // For really small blurs (certainly no wider than 5x5 on desktop gpus) it is faster to just + // launch a single non separable kernel vs two launches + if (sigmaX > 0.0f && sigmaY > 0.0f && + (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) { + // We shouldn't be scaling because this is a small size blur + SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); + + sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(SkBackingFit::kApprox, + width, height, config, + 0, kDefault_GrSurfaceOrigin, + &props)); + if (!dstDrawContext) { + return nullptr; + } + convolve_gaussian_2d(dstDrawContext.get(), clip, localDstBounds, srcOffset, + srcTexture, radiusX, radiusY, sigmaX, sigmaY, srcBounds); + + return dstDrawContext->asTexture().release(); + } + GrSurfaceDesc desc; desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fWidth = SkScalarFloorToInt(dstBounds.width()); - desc.fHeight = SkScalarFloorToInt(dstBounds.height()); - desc.fConfig = srcTexture->config(); + desc.fWidth = width; + desc.fHeight = height; + desc.fConfig = config; GrTexture* dstTexture; GrTexture* tempTexture; @@ -217,14 +243,10 @@ GrTexture* GaussianBlur(GrContext* context, temp1.reset(context->textureProvider()->createApproxTexture(desc)); dstTexture = temp1.get(); - if (canClobberSrc) { - tempTexture = srcTexture; - } else { - temp2.reset(context->textureProvider()->createApproxTexture(desc)); - tempTexture = temp2.get(); - } + temp2.reset(context->textureProvider()->createApproxTexture(desc)); + tempTexture = temp2.get(); - if (nullptr == dstTexture || nullptr == tempTexture) { + if (!dstTexture || !tempTexture) { return nullptr; } @@ -241,13 +263,13 @@ GrTexture* GaussianBlur(GrContext* context, matrix.mapRect(&domain, *srcBounds); domain.inset((i < scaleFactorX) ? SK_ScalarHalf / srcTexture->width() : 0.0f, (i < scaleFactorY) ? SK_ScalarHalf / srcTexture->height() : 0.0f); - SkAutoTUnref<const GrFragmentProcessor> fp(GrTextureDomainEffect::Create( - srcTexture, - matrix, - domain, - GrTextureDomain::kDecal_Mode, - GrTextureParams::kBilerp_FilterMode)); - paint.addColorFragmentProcessor(fp); + sk_sp<const GrFragmentProcessor> fp(GrTextureDomainEffect::Create( + srcTexture, + matrix, + domain, + GrTextureDomain::kDecal_Mode, + GrTextureParams::kBilerp_FilterMode)); + paint.addColorFragmentProcessor(fp.get()); srcRect.offset(-srcOffset); srcOffset.set(0, 0); } else { @@ -272,100 +294,77 @@ GrTexture* GaussianBlur(GrContext* context, localSrcBounds = srcRect; } - SkSurfaceProps props(gammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag : 0, - SkSurfaceProps::kLegacyFontHost_InitType); - - // For really small blurs (certainly no wider than 5x5 on desktop gpus) it is faster to just - // launch a single non separable kernel vs two launches srcRect = localDstBounds; - if (sigmaX > 0.0f && sigmaY > 0.0f && - (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) { - // We shouldn't be scaling because this is a small size blur - SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); + + scale_rect(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY); + srcRect.roundOut(&srcRect); + SkIRect srcIRect = srcRect.roundOut(); + if (sigmaX > 0.0f) { + if (scaleFactorX > 1) { + // TODO: if we pass in the source draw context we don't need this here + if (!srcDrawContext) { + srcDrawContext = context->drawContext(sk_ref_sp(srcTexture->asRenderTarget())); + if (!srcDrawContext) { + return nullptr; + } + } + + // Clear out a radius to the right of the srcRect to prevent the + // X convolution from reading garbage. + clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, + radiusX, srcIRect.height()); + srcDrawContext->clear(&clearRect, 0x0, false); + } sk_sp<GrDrawContext> dstDrawContext( context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()), &props)); if (!dstDrawContext) { return nullptr; } - convolve_gaussian_2d(dstDrawContext.get(), clip, srcRect, srcOffset, - srcTexture, radiusX, radiusY, sigmaX, sigmaY, srcBounds); - + convolve_gaussian(dstDrawContext.get(), clip, srcRect, + srcTexture, Gr1DKernelEffect::kX_Direction, radiusX, sigmaX, + srcBounds, srcOffset); srcDrawContext.swap(dstDrawContext); - srcRect.offsetTo(0, 0); srcTexture = dstTexture; + srcRect.offsetTo(0, 0); SkTSwap(dstTexture, tempTexture); + localSrcBounds = srcRect; + srcOffset.set(0, 0); + } - } else { - scale_rect(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY); - srcRect.roundOut(&srcRect); - const SkIRect srcIRect = srcRect.roundOut(); - if (sigmaX > 0.0f) { - if (scaleFactorX > 1) { - // TODO: if we pass in the source draw context we don't need this here + if (sigmaY > 0.0f) { + if (scaleFactorY > 1 || sigmaX > 0.0f) { + // TODO: if we pass in the source draw context we don't need this here + if (!srcDrawContext) { + srcDrawContext = context->drawContext(sk_ref_sp(srcTexture->asRenderTarget())); if (!srcDrawContext) { - srcDrawContext = context->drawContext(sk_ref_sp(srcTexture->asRenderTarget())); - if (!srcDrawContext) { - return nullptr; - } + return nullptr; } - - // Clear out a radius to the right of the srcRect to prevent the - // X convolution from reading garbage. - clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, - radiusX, srcIRect.height()); - srcDrawContext->clear(&clearRect, 0x0, false); } - sk_sp<GrDrawContext> dstDrawContext( - context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()), &props)); - if (!dstDrawContext) { - return nullptr; - } - convolve_gaussian(dstDrawContext.get(), clip, srcRect, - srcTexture, Gr1DKernelEffect::kX_Direction, radiusX, sigmaX, - srcBounds, srcOffset); - srcDrawContext.swap(dstDrawContext); - srcTexture = dstTexture; - srcRect.offsetTo(0, 0); - SkTSwap(dstTexture, tempTexture); - localSrcBounds = srcRect; - srcOffset.set(0, 0); + // Clear out a radius below the srcRect to prevent the Y + // convolution from reading garbage. + clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, + srcIRect.width(), radiusY); + srcDrawContext->clear(&clearRect, 0x0, false); } - if (sigmaY > 0.0f) { - if (scaleFactorY > 1 || sigmaX > 0.0f) { - // TODO: if we pass in the source draw context we don't need this here - if (!srcDrawContext) { - srcDrawContext = context->drawContext(sk_ref_sp(srcTexture->asRenderTarget())); - if (!srcDrawContext) { - return nullptr; - } - } - - // Clear out a radius below the srcRect to prevent the Y - // convolution from reading garbage. - clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, - srcIRect.width(), radiusY); - srcDrawContext->clear(&clearRect, 0x0, false); - } - - sk_sp<GrDrawContext> dstDrawContext( - context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()), &props)); - if (!dstDrawContext) { - return nullptr; - } - convolve_gaussian(dstDrawContext.get(), clip, srcRect, - srcTexture, Gr1DKernelEffect::kY_Direction, radiusY, sigmaY, - srcBounds, srcOffset); - - srcDrawContext.swap(dstDrawContext); - srcTexture = dstTexture; - srcRect.offsetTo(0, 0); - SkTSwap(dstTexture, tempTexture); + sk_sp<GrDrawContext> dstDrawContext( + context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()), &props)); + if (!dstDrawContext) { + return nullptr; } + convolve_gaussian(dstDrawContext.get(), clip, srcRect, + srcTexture, Gr1DKernelEffect::kY_Direction, radiusY, sigmaY, + srcBounds, srcOffset); + + srcDrawContext.swap(dstDrawContext); + srcTexture = dstTexture; + srcRect.offsetTo(0, 0); + SkTSwap(dstTexture, tempTexture); } - const SkIRect srcIRect = srcRect.roundOut(); + + srcIRect = srcRect.roundOut(); if (scaleFactorX > 1 || scaleFactorY > 1) { SkASSERT(srcDrawContext); diff --git a/src/effects/SkGpuBlurUtils.h b/src/effects/SkGpuBlurUtils.h index 7dbfa138ea..8bc4377f59 100644 --- a/src/effects/SkGpuBlurUtils.h +++ b/src/effects/SkGpuBlurUtils.h @@ -24,8 +24,6 @@ namespace SkGpuBlurUtils { * Applies a 2D Gaussian blur to a given texture. * @param context The GPU context * @param srcTexture The source texture to be blurred. - * @param canClobberSrc If true, srcTexture may be overwritten, and - * may be returned as the result. * @param gammaCorrect Should blur be gamma-correct (sRGB to linear, etc...) * @param dstBounds The destination bounds, relative to the source texture. * @param srcBounds The source bounds, relative to the source texture. If non-null, @@ -37,7 +35,6 @@ namespace SkGpuBlurUtils { */ GrTexture* GaussianBlur(GrContext* context, GrTexture* srcTexture, - bool canClobberSrc, bool gammaCorrect, const SkRect& dstBounds, const SkRect* srcBounds, diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 3ea67c9f01..443494073a 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -658,7 +658,8 @@ sk_sp<GrDrawContext> GrContext::newDrawContext(SkBackingFit fit, int width, int height, GrPixelConfig config, int sampleCnt, - GrSurfaceOrigin origin) { + GrSurfaceOrigin origin, + const SkSurfaceProps* surfaceProps) { GrSurfaceDesc desc; desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fOrigin = origin; @@ -677,7 +678,8 @@ sk_sp<GrDrawContext> GrContext::newDrawContext(SkBackingFit fit, return nullptr; } - sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(tex->asRenderTarget()))); + sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(tex->asRenderTarget()), + surfaceProps)); if (!drawContext) { return nullptr; } |