aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkGpuBlurUtils.cpp
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-01-30 15:58:27 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-30 15:58:33 +0000
commit877b15b301d798a0eb7aeb9ad36db383ef63ace9 (patch)
treed49796db4929d53f13987ac3b4828eb824c8138d /src/core/SkGpuBlurUtils.cpp
parentd0dc05b98b71af43b44f13beba1292db52b75539 (diff)
Revert "Make blur utils take GrTextureProxies"
This reverts commit d0dc05b98b71af43b44f13beba1292db52b75539. Reason for revert: assertion failure on N7 Original change's description: > Make blur utils take GrTextureProxies > > Change-Id: I1c5054de6d9827eece2f73c4c78818b4db0bc611 > Reviewed-on: https://skia-review.googlesource.com/7738 > Reviewed-by: Brian Salomon <bsalomon@google.com> > Commit-Queue: Robert Phillips <robertphillips@google.com> > TBR=bsalomon@google.com,robertphillips@google.com,reviews@skia.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Change-Id: I82d9385e23279db4c7a6757f1224e603e231354c Reviewed-on: https://skia-review.googlesource.com/7744 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/core/SkGpuBlurUtils.cpp')
-rw-r--r--src/core/SkGpuBlurUtils.cpp93
1 files changed, 46 insertions, 47 deletions
diff --git a/src/core/SkGpuBlurUtils.cpp b/src/core/SkGpuBlurUtils.cpp
index d58582da46..d7522ca726 100644
--- a/src/core/SkGpuBlurUtils.cpp
+++ b/src/core/SkGpuBlurUtils.cpp
@@ -66,21 +66,20 @@ static float adjust_sigma(float sigma, int maxTextureSize, int *scaleFactor, int
return sigma;
}
-static void convolve_gaussian_1d(GrContext* context,
- GrRenderTargetContext* renderTargetContext,
+static void convolve_gaussian_1d(GrRenderTargetContext* renderTargetContext,
const GrClip& clip,
const SkIRect& dstRect,
const SkIPoint& srcOffset,
- sk_sp<GrTextureProxy> proxy,
+ GrTexture* texture,
Gr1DKernelEffect::Direction direction,
int radius,
float sigma,
bool useBounds,
- int bounds[2]) {
+ float bounds[2]) {
GrPaint paint;
paint.setGammaCorrect(renderTargetContext->isGammaCorrect());
sk_sp<GrFragmentProcessor> conv(GrGaussianConvolutionFragmentProcessor::Make(
- context, std::move(proxy), direction, radius, sigma, useBounds, bounds));
+ texture, direction, radius, sigma, useBounds, bounds));
paint.addColorFragmentProcessor(std::move(conv));
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
SkMatrix localMatrix = SkMatrix::MakeTrans(-SkIntToScalar(srcOffset.x()),
@@ -89,12 +88,11 @@ static void convolve_gaussian_1d(GrContext* context,
SkRect::Make(dstRect), localMatrix);
}
-static void convolve_gaussian_2d(GrContext* context,
- GrRenderTargetContext* renderTargetContext,
+static void convolve_gaussian_2d(GrRenderTargetContext* renderTargetContext,
const GrClip& clip,
const SkIRect& dstRect,
const SkIPoint& srcOffset,
- sk_sp<GrTextureProxy> proxy,
+ GrTexture* texture,
int radiusX,
int radiusY,
SkScalar sigmaX,
@@ -109,7 +107,7 @@ static void convolve_gaussian_2d(GrContext* context,
SkIRect bounds = srcBounds ? *srcBounds : SkIRect::EmptyIRect();
sk_sp<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::MakeGaussian(
- context, std::move(proxy), bounds, size, 1.0, 0.0, kernelOffset,
+ texture, bounds, size, 1.0, 0.0, kernelOffset,
srcBounds ? GrTextureDomain::kDecal_Mode : GrTextureDomain::kIgnore_Mode,
true, sigmaX, sigmaY));
paint.addColorFragmentProcessor(std::move(conv));
@@ -118,29 +116,28 @@ static void convolve_gaussian_2d(GrContext* context,
SkRect::Make(dstRect), localMatrix);
}
-static void convolve_gaussian(GrContext* context,
- GrRenderTargetContext* renderTargetContext,
+static void convolve_gaussian(GrRenderTargetContext* renderTargetContext,
const GrClip& clip,
const SkIRect& srcRect,
- sk_sp<GrTextureProxy> proxy,
+ GrTexture* texture,
Gr1DKernelEffect::Direction direction,
int radius,
float sigma,
const SkIRect* srcBounds,
const SkIPoint& srcOffset) {
- int bounds[2] = { 0, 0 };
+ float bounds[2] = { 0.0f, 1.0f };
SkIRect dstRect = SkIRect::MakeWH(srcRect.width(), srcRect.height());
if (!srcBounds) {
- convolve_gaussian_1d(context, renderTargetContext, clip, dstRect, srcOffset,
- std::move(proxy), direction, radius, sigma, false, bounds);
+ convolve_gaussian_1d(renderTargetContext, clip, dstRect, srcOffset, texture,
+ direction, radius, sigma, false, bounds);
return;
}
SkIRect midRect = *srcBounds, leftRect, rightRect;
midRect.offset(srcOffset);
SkIRect topRect, bottomRect;
if (direction == Gr1DKernelEffect::kX_Direction) {
- bounds[0] = srcBounds->left();
- bounds[1] = srcBounds->right();
+ bounds[0] = SkIntToFloat(srcBounds->left()) / texture->width();
+ bounds[1] = SkIntToFloat(srcBounds->right()) / texture->width();
topRect = SkIRect::MakeLTRB(0, 0, dstRect.right(), midRect.top());
bottomRect = SkIRect::MakeLTRB(0, midRect.bottom(), dstRect.right(), dstRect.bottom());
midRect.inset(radius, 0);
@@ -150,8 +147,8 @@ static void convolve_gaussian(GrContext* context,
dstRect.fTop = midRect.top();
dstRect.fBottom = midRect.bottom();
} else {
- bounds[0] = srcBounds->top();
- bounds[1] = srcBounds->bottom();
+ bounds[0] = SkIntToFloat(srcBounds->top()) / texture->height();
+ bounds[1] = SkIntToFloat(srcBounds->bottom()) / texture->height();
topRect = SkIRect::MakeLTRB(0, 0, midRect.left(), dstRect.bottom());
bottomRect = SkIRect::MakeLTRB(midRect.right(), 0, dstRect.right(), dstRect.bottom());
midRect.inset(0, radius);
@@ -170,23 +167,23 @@ static void convolve_gaussian(GrContext* context,
}
if (midRect.isEmpty()) {
// Blur radius covers srcBounds; use bounds over entire draw
- convolve_gaussian_1d(context, renderTargetContext, clip, dstRect, srcOffset,
- std::move(proxy), direction, radius, sigma, true, bounds);
+ convolve_gaussian_1d(renderTargetContext, clip, dstRect, srcOffset, texture,
+ direction, radius, sigma, true, bounds);
} else {
// Draw right and left margins with bounds; middle without.
- convolve_gaussian_1d(context, renderTargetContext, clip, leftRect, srcOffset,
- proxy, direction, radius, sigma, true, bounds);
- convolve_gaussian_1d(context, renderTargetContext, clip, rightRect, srcOffset,
- proxy, direction, radius, sigma, true, bounds);
- convolve_gaussian_1d(context, renderTargetContext, clip, midRect, srcOffset,
- std::move(proxy), direction, radius, sigma, false, bounds);
+ convolve_gaussian_1d(renderTargetContext, clip, leftRect, srcOffset, texture,
+ direction, radius, sigma, true, bounds);
+ convolve_gaussian_1d(renderTargetContext, clip, rightRect, srcOffset, texture,
+ direction, radius, sigma, true, bounds);
+ convolve_gaussian_1d(renderTargetContext, clip, midRect, srcOffset, texture,
+ direction, radius, sigma, false, bounds);
}
}
namespace SkGpuBlurUtils {
sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
- sk_sp<GrTextureProxy> srcProxy,
+ GrTexture* origSrc,
sk_sp<SkColorSpace> colorSpace,
const SkIRect& dstBounds,
const SkIRect* srcBounds,
@@ -220,14 +217,18 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
// setup new clip
GrFixedClip clip(localDstBounds);
- const GrPixelConfig config = srcProxy->config();
+ sk_sp<GrTexture> srcTexture(sk_ref_sp(origSrc));
- SkASSERT(kBGRA_8888_GrPixelConfig == config || kRGBA_8888_GrPixelConfig == config ||
- kSRGBA_8888_GrPixelConfig == config || kSBGRA_8888_GrPixelConfig == config ||
- kRGBA_half_GrPixelConfig == config || kAlpha_8_GrPixelConfig == config);
+ SkASSERT(kBGRA_8888_GrPixelConfig == srcTexture->config() ||
+ kRGBA_8888_GrPixelConfig == srcTexture->config() ||
+ kSRGBA_8888_GrPixelConfig == srcTexture->config() ||
+ kSBGRA_8888_GrPixelConfig == srcTexture->config() ||
+ kRGBA_half_GrPixelConfig == srcTexture->config() ||
+ kAlpha_8_GrPixelConfig == srcTexture->config());
const int width = dstBounds.width();
const int height = dstBounds.height();
+ const GrPixelConfig config = srcTexture->config();
sk_sp<GrRenderTargetContext> dstRenderTargetContext(context->makeDeferredRenderTargetContext(
fit, width, height, config, colorSpace, 0, kBottomLeft_GrSurfaceOrigin));
@@ -242,8 +243,8 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
// We shouldn't be scaling because this is a small size blur
SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY));
- convolve_gaussian_2d(context, dstRenderTargetContext.get(), clip, localDstBounds, srcOffset,
- std::move(srcProxy), radiusX, radiusY, sigmaX, sigmaY, srcBounds);
+ convolve_gaussian_2d(dstRenderTargetContext.get(), clip, localDstBounds, srcOffset,
+ srcTexture.get(), radiusX, radiusY, sigmaX, sigmaY, srcBounds);
return dstRenderTargetContext;
}
@@ -267,8 +268,7 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
domain.inset((i < scaleFactorX) ? SK_ScalarHalf : 0.0f,
(i < scaleFactorY) ? SK_ScalarHalf : 0.0f);
sk_sp<GrFragmentProcessor> fp(GrTextureDomainEffect::Make(
- context,
- std::move(srcProxy),
+ srcTexture.get(),
nullptr,
SkMatrix::I(),
domain,
@@ -279,8 +279,7 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
srcOffset.set(0, 0);
} else {
GrSamplerParams params(SkShader::kClamp_TileMode, GrSamplerParams::kBilerp_FilterMode);
- paint.addColorTextureProcessor(context, std::move(srcProxy), nullptr,
- SkMatrix::I(), params);
+ paint.addColorTextureProcessor(srcTexture.get(), nullptr, SkMatrix::I(), params);
}
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
shrink_irect_by_2(&dstRect, i < scaleFactorX, i < scaleFactorY);
@@ -290,8 +289,8 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
srcRenderTargetContext = dstRenderTargetContext;
srcRect = dstRect;
- srcProxy = sk_ref_sp(srcRenderTargetContext->asDeferredTexture());
- if (!srcProxy) {
+ srcTexture = srcRenderTargetContext->asTexture();
+ if (!srcTexture) {
return nullptr;
}
dstRenderTargetContext.swap(tmpRenderTargetContext);
@@ -311,12 +310,12 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
srcRenderTargetContext->priv().absClear(&clearRect, 0x0);
}
- convolve_gaussian(context, dstRenderTargetContext.get(), clip, srcRect,
- std::move(srcProxy), Gr1DKernelEffect::kX_Direction, radiusX, sigmaX,
+ convolve_gaussian(dstRenderTargetContext.get(), clip, srcRect,
+ srcTexture.get(), Gr1DKernelEffect::kX_Direction, radiusX, sigmaX,
srcBounds, srcOffset);
srcRenderTargetContext = dstRenderTargetContext;
- srcProxy = sk_ref_sp(srcRenderTargetContext->asDeferredTexture());
- if (!srcProxy) {
+ srcTexture = srcRenderTargetContext->asTexture();
+ if (!srcTexture) {
return nullptr;
}
srcRect.offsetTo(0, 0);
@@ -336,8 +335,8 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
srcRenderTargetContext->priv().absClear(&clearRect, 0x0);
}
- convolve_gaussian(context, dstRenderTargetContext.get(), clip, srcRect,
- std::move(srcProxy), Gr1DKernelEffect::kY_Direction, radiusY, sigmaY,
+ convolve_gaussian(dstRenderTargetContext.get(), clip, srcRect,
+ srcTexture.get(), Gr1DKernelEffect::kY_Direction, radiusY, sigmaY,
srcBounds, srcOffset);
srcRenderTargetContext = dstRenderTargetContext;
@@ -346,7 +345,7 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
}
SkASSERT(srcRenderTargetContext);
- srcProxy.reset(nullptr); // we don't use this from here on out
+ srcTexture = nullptr; // we don't use this from here on out
if (scaleFactorX > 1 || scaleFactorY > 1) {
// Clear one pixel to the right and below, to accommodate bilinear upsampling.