Revert of Simplify SkGpuBlurUtils::GaussianBlur method (patchset #2 id:20001 of https://codereview.chromium.org/1958603002/ )
Reason for revert:
Looks like it's causing some issues with the bleed_image GM.
Original issue's description:
> 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
>
> Committed: https://skia.googlesource.com/skia/+/56a85e69a8d034e0fdee00e8207cda0a9da06fee
TBR=bsalomon@google.com,robertphillips@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Review-Url: https://codereview.chromium.org/1956023002
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 1c9a27e..b6fa30b 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -202,8 +202,7 @@
int width, int height,
GrPixelConfig config,
int sampleCnt = 0,
- GrSurfaceOrigin origin = kDefault_GrSurfaceOrigin,
- const SkSurfaceProps* surfaceProps = nullptr);
+ GrSurfaceOrigin origin = kDefault_GrSurfaceOrigin);
///////////////////////////////////////////////////////////////////////////
// Misc.
diff --git a/src/effects/SkBlurImageFilter.cpp b/src/effects/SkBlurImageFilter.cpp
index 4e1fde2..bbe351d 100644
--- a/src/effects/SkBlurImageFilter.cpp
+++ b/src/effects/SkBlurImageFilter.cpp
@@ -123,6 +123,7 @@
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 37d6c96..8e9eb52 100644
--- a/src/effects/SkBlurMaskFilter.cpp
+++ b/src/effects/SkBlurMaskFilter.cpp
@@ -1249,7 +1249,7 @@
// gaussianBlur. Otherwise, we need to save it for later compositing.
bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle);
*result = SkGpuBlurUtils::GaussianBlur(context, src, isNormalBlur && canOverwriteSrc,
- clipRect, nullptr,
+ false, clipRect, nullptr,
xformedSigma, xformedSigma);
if (nullptr == *result) {
return false;
diff --git a/src/effects/SkGpuBlurUtils.cpp b/src/effects/SkGpuBlurUtils.cpp
index 1cb2d1d..c3681fa 100644
--- a/src/effects/SkGpuBlurUtils.cpp
+++ b/src/effects/SkGpuBlurUtils.cpp
@@ -165,6 +165,7 @@
GrTexture* GaussianBlur(GrContext* context,
GrTexture* srcTexture,
+ bool canClobberSrc,
bool gammaCorrect,
const SkRect& dstBounds,
const SkRect* srcBounds,
@@ -204,38 +205,11 @@
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 = width;
- desc.fHeight = height;
- desc.fConfig = config;
+ desc.fWidth = SkScalarFloorToInt(dstBounds.width());
+ desc.fHeight = SkScalarFloorToInt(dstBounds.height());
+ desc.fConfig = srcTexture->config();
GrTexture* dstTexture;
GrTexture* tempTexture;
@@ -243,10 +217,14 @@
temp1.reset(context->textureProvider()->createApproxTexture(desc));
dstTexture = temp1.get();
- temp2.reset(context->textureProvider()->createApproxTexture(desc));
- tempTexture = temp2.get();
+ if (canClobberSrc) {
+ tempTexture = srcTexture;
+ } else {
+ temp2.reset(context->textureProvider()->createApproxTexture(desc));
+ tempTexture = temp2.get();
+ }
- if (!dstTexture || !tempTexture) {
+ if (nullptr == dstTexture || nullptr == tempTexture) {
return nullptr;
}
@@ -263,13 +241,13 @@
matrix.mapRect(&domain, *srcBounds);
domain.inset((i < scaleFactorX) ? SK_ScalarHalf / srcTexture->width() : 0.0f,
(i < scaleFactorY) ? SK_ScalarHalf / srcTexture->height() : 0.0f);
- sk_sp<const GrFragmentProcessor> fp(GrTextureDomainEffect::Create(
- srcTexture,
- matrix,
- domain,
- GrTextureDomain::kDecal_Mode,
- GrTextureParams::kBilerp_FilterMode));
- paint.addColorFragmentProcessor(fp.get());
+ SkAutoTUnref<const GrFragmentProcessor> fp(GrTextureDomainEffect::Create(
+ srcTexture,
+ matrix,
+ domain,
+ GrTextureDomain::kDecal_Mode,
+ GrTextureParams::kBilerp_FilterMode));
+ paint.addColorFragmentProcessor(fp);
srcRect.offset(-srcOffset);
srcOffset.set(0, 0);
} else {
@@ -294,77 +272,100 @@
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;
-
- 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);
- }
+ 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->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);
- }
+ convolve_gaussian_2d(dstDrawContext.get(), clip, srcRect, srcOffset,
+ srcTexture, radiusX, radiusY, sigmaX, sigmaY, srcBounds);
- 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()));
+ srcDrawContext.swap(dstDrawContext);
+ srcRect.offsetTo(0, 0);
+ srcTexture = dstTexture;
+ SkTSwap(dstTexture, tempTexture);
+
+ } 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 (!srcDrawContext) {
- return nullptr;
+ 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);
}
- // 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::kX_Direction, radiusX, sigmaX,
+ srcBounds, srcOffset);
+ srcDrawContext.swap(dstDrawContext);
+ srcTexture = dstTexture;
+ srcRect.offsetTo(0, 0);
+ SkTSwap(dstTexture, tempTexture);
+ localSrcBounds = srcRect;
+ srcOffset.set(0, 0);
}
- 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);
+ 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;
+ }
+ }
- srcDrawContext.swap(dstDrawContext);
- srcTexture = dstTexture;
- srcRect.offsetTo(0, 0);
- SkTSwap(dstTexture, tempTexture);
+ // 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);
+ }
}
-
- srcIRect = srcRect.roundOut();
+ const SkIRect srcIRect = srcRect.roundOut();
if (scaleFactorX > 1 || scaleFactorY > 1) {
SkASSERT(srcDrawContext);
diff --git a/src/effects/SkGpuBlurUtils.h b/src/effects/SkGpuBlurUtils.h
index 8bc4377..7dbfa13 100644
--- a/src/effects/SkGpuBlurUtils.h
+++ b/src/effects/SkGpuBlurUtils.h
@@ -24,6 +24,8 @@
* 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,
@@ -35,6 +37,7 @@
*/
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 4434940..3ea67c9 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -658,8 +658,7 @@
int width, int height,
GrPixelConfig config,
int sampleCnt,
- GrSurfaceOrigin origin,
- const SkSurfaceProps* surfaceProps) {
+ GrSurfaceOrigin origin) {
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fOrigin = origin;
@@ -678,8 +677,7 @@
return nullptr;
}
- sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(tex->asRenderTarget()),
- surfaceProps));
+ sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(tex->asRenderTarget())));
if (!drawContext) {
return nullptr;
}