Revert "Make blur utils take GrTextureProxies"

This reverts commit d0dc05b98b.

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>
This commit is contained in:
Robert Phillips 2017-01-30 15:58:27 +00:00 committed by Skia Commit-Bot
parent d0dc05b98b
commit 877b15b301
7 changed files with 83 additions and 91 deletions

View File

@ -141,7 +141,7 @@ sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* sourc
// xform during the filter itself. // xform during the filter itself.
input = ImageToColorSpace(input.get(), ctx.outputProperties()); input = ImageToColorSpace(input.get(), ctx.outputProperties());
sk_sp<GrTextureProxy> inputTexture(input->asTextureProxy(context)); sk_sp<GrTexture> inputTexture(input->asTextureRef(context));
if (!inputTexture) { if (!inputTexture) {
return nullptr; return nullptr;
} }
@ -163,7 +163,7 @@ sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* sourc
// have the same gamut, so in this case, we do everything in the input's color space. // have the same gamut, so in this case, we do everything in the input's color space.
sk_sp<GrRenderTargetContext> renderTargetContext(SkGpuBlurUtils::GaussianBlur( sk_sp<GrRenderTargetContext> renderTargetContext(SkGpuBlurUtils::GaussianBlur(
context, context,
std::move(inputTexture), inputTexture.get(),
sk_ref_sp(input->getColorSpace()), sk_ref_sp(input->getColorSpace()),
dstBounds, dstBounds,
&inputBounds, &inputBounds,

View File

@ -66,21 +66,20 @@ static float adjust_sigma(float sigma, int maxTextureSize, int *scaleFactor, int
return sigma; return sigma;
} }
static void convolve_gaussian_1d(GrContext* context, static void convolve_gaussian_1d(GrRenderTargetContext* renderTargetContext,
GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
const SkIRect& dstRect, const SkIRect& dstRect,
const SkIPoint& srcOffset, const SkIPoint& srcOffset,
sk_sp<GrTextureProxy> proxy, GrTexture* texture,
Gr1DKernelEffect::Direction direction, Gr1DKernelEffect::Direction direction,
int radius, int radius,
float sigma, float sigma,
bool useBounds, bool useBounds,
int bounds[2]) { float bounds[2]) {
GrPaint paint; GrPaint paint;
paint.setGammaCorrect(renderTargetContext->isGammaCorrect()); paint.setGammaCorrect(renderTargetContext->isGammaCorrect());
sk_sp<GrFragmentProcessor> conv(GrGaussianConvolutionFragmentProcessor::Make( 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.addColorFragmentProcessor(std::move(conv));
paint.setPorterDuffXPFactory(SkBlendMode::kSrc); paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
SkMatrix localMatrix = SkMatrix::MakeTrans(-SkIntToScalar(srcOffset.x()), SkMatrix localMatrix = SkMatrix::MakeTrans(-SkIntToScalar(srcOffset.x()),
@ -89,12 +88,11 @@ static void convolve_gaussian_1d(GrContext* context,
SkRect::Make(dstRect), localMatrix); SkRect::Make(dstRect), localMatrix);
} }
static void convolve_gaussian_2d(GrContext* context, static void convolve_gaussian_2d(GrRenderTargetContext* renderTargetContext,
GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
const SkIRect& dstRect, const SkIRect& dstRect,
const SkIPoint& srcOffset, const SkIPoint& srcOffset,
sk_sp<GrTextureProxy> proxy, GrTexture* texture,
int radiusX, int radiusX,
int radiusY, int radiusY,
SkScalar sigmaX, SkScalar sigmaX,
@ -109,7 +107,7 @@ static void convolve_gaussian_2d(GrContext* context,
SkIRect bounds = srcBounds ? *srcBounds : SkIRect::EmptyIRect(); SkIRect bounds = srcBounds ? *srcBounds : SkIRect::EmptyIRect();
sk_sp<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::MakeGaussian( 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, srcBounds ? GrTextureDomain::kDecal_Mode : GrTextureDomain::kIgnore_Mode,
true, sigmaX, sigmaY)); true, sigmaX, sigmaY));
paint.addColorFragmentProcessor(std::move(conv)); paint.addColorFragmentProcessor(std::move(conv));
@ -118,29 +116,28 @@ static void convolve_gaussian_2d(GrContext* context,
SkRect::Make(dstRect), localMatrix); SkRect::Make(dstRect), localMatrix);
} }
static void convolve_gaussian(GrContext* context, static void convolve_gaussian(GrRenderTargetContext* renderTargetContext,
GrRenderTargetContext* renderTargetContext,
const GrClip& clip, const GrClip& clip,
const SkIRect& srcRect, const SkIRect& srcRect,
sk_sp<GrTextureProxy> proxy, GrTexture* texture,
Gr1DKernelEffect::Direction direction, Gr1DKernelEffect::Direction direction,
int radius, int radius,
float sigma, float sigma,
const SkIRect* srcBounds, const SkIRect* srcBounds,
const SkIPoint& srcOffset) { const SkIPoint& srcOffset) {
int bounds[2] = { 0, 0 }; float bounds[2] = { 0.0f, 1.0f };
SkIRect dstRect = SkIRect::MakeWH(srcRect.width(), srcRect.height()); SkIRect dstRect = SkIRect::MakeWH(srcRect.width(), srcRect.height());
if (!srcBounds) { if (!srcBounds) {
convolve_gaussian_1d(context, renderTargetContext, clip, dstRect, srcOffset, convolve_gaussian_1d(renderTargetContext, clip, dstRect, srcOffset, texture,
std::move(proxy), direction, radius, sigma, false, bounds); direction, radius, sigma, false, bounds);
return; return;
} }
SkIRect midRect = *srcBounds, leftRect, rightRect; SkIRect midRect = *srcBounds, leftRect, rightRect;
midRect.offset(srcOffset); midRect.offset(srcOffset);
SkIRect topRect, bottomRect; SkIRect topRect, bottomRect;
if (direction == Gr1DKernelEffect::kX_Direction) { if (direction == Gr1DKernelEffect::kX_Direction) {
bounds[0] = srcBounds->left(); bounds[0] = SkIntToFloat(srcBounds->left()) / texture->width();
bounds[1] = srcBounds->right(); bounds[1] = SkIntToFloat(srcBounds->right()) / texture->width();
topRect = SkIRect::MakeLTRB(0, 0, dstRect.right(), midRect.top()); topRect = SkIRect::MakeLTRB(0, 0, dstRect.right(), midRect.top());
bottomRect = SkIRect::MakeLTRB(0, midRect.bottom(), dstRect.right(), dstRect.bottom()); bottomRect = SkIRect::MakeLTRB(0, midRect.bottom(), dstRect.right(), dstRect.bottom());
midRect.inset(radius, 0); midRect.inset(radius, 0);
@ -150,8 +147,8 @@ static void convolve_gaussian(GrContext* context,
dstRect.fTop = midRect.top(); dstRect.fTop = midRect.top();
dstRect.fBottom = midRect.bottom(); dstRect.fBottom = midRect.bottom();
} else { } else {
bounds[0] = srcBounds->top(); bounds[0] = SkIntToFloat(srcBounds->top()) / texture->height();
bounds[1] = srcBounds->bottom(); bounds[1] = SkIntToFloat(srcBounds->bottom()) / texture->height();
topRect = SkIRect::MakeLTRB(0, 0, midRect.left(), dstRect.bottom()); topRect = SkIRect::MakeLTRB(0, 0, midRect.left(), dstRect.bottom());
bottomRect = SkIRect::MakeLTRB(midRect.right(), 0, dstRect.right(), dstRect.bottom()); bottomRect = SkIRect::MakeLTRB(midRect.right(), 0, dstRect.right(), dstRect.bottom());
midRect.inset(0, radius); midRect.inset(0, radius);
@ -170,23 +167,23 @@ static void convolve_gaussian(GrContext* context,
} }
if (midRect.isEmpty()) { if (midRect.isEmpty()) {
// Blur radius covers srcBounds; use bounds over entire draw // Blur radius covers srcBounds; use bounds over entire draw
convolve_gaussian_1d(context, renderTargetContext, clip, dstRect, srcOffset, convolve_gaussian_1d(renderTargetContext, clip, dstRect, srcOffset, texture,
std::move(proxy), direction, radius, sigma, true, bounds); direction, radius, sigma, true, bounds);
} else { } else {
// Draw right and left margins with bounds; middle without. // Draw right and left margins with bounds; middle without.
convolve_gaussian_1d(context, renderTargetContext, clip, leftRect, srcOffset, convolve_gaussian_1d(renderTargetContext, clip, leftRect, srcOffset, texture,
proxy, direction, radius, sigma, true, bounds); direction, radius, sigma, true, bounds);
convolve_gaussian_1d(context, renderTargetContext, clip, rightRect, srcOffset, convolve_gaussian_1d(renderTargetContext, clip, rightRect, srcOffset, texture,
proxy, direction, radius, sigma, true, bounds); direction, radius, sigma, true, bounds);
convolve_gaussian_1d(context, renderTargetContext, clip, midRect, srcOffset, convolve_gaussian_1d(renderTargetContext, clip, midRect, srcOffset, texture,
std::move(proxy), direction, radius, sigma, false, bounds); direction, radius, sigma, false, bounds);
} }
} }
namespace SkGpuBlurUtils { namespace SkGpuBlurUtils {
sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context, sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
sk_sp<GrTextureProxy> srcProxy, GrTexture* origSrc,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,
const SkIRect& dstBounds, const SkIRect& dstBounds,
const SkIRect* srcBounds, const SkIRect* srcBounds,
@ -220,14 +217,18 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
// setup new clip // setup new clip
GrFixedClip clip(localDstBounds); 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 || SkASSERT(kBGRA_8888_GrPixelConfig == srcTexture->config() ||
kSRGBA_8888_GrPixelConfig == config || kSBGRA_8888_GrPixelConfig == config || kRGBA_8888_GrPixelConfig == srcTexture->config() ||
kRGBA_half_GrPixelConfig == config || kAlpha_8_GrPixelConfig == 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 width = dstBounds.width();
const int height = dstBounds.height(); const int height = dstBounds.height();
const GrPixelConfig config = srcTexture->config();
sk_sp<GrRenderTargetContext> dstRenderTargetContext(context->makeDeferredRenderTargetContext( sk_sp<GrRenderTargetContext> dstRenderTargetContext(context->makeDeferredRenderTargetContext(
fit, width, height, config, colorSpace, 0, kBottomLeft_GrSurfaceOrigin)); 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 // We shouldn't be scaling because this is a small size blur
SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY));
convolve_gaussian_2d(context, dstRenderTargetContext.get(), clip, localDstBounds, srcOffset, convolve_gaussian_2d(dstRenderTargetContext.get(), clip, localDstBounds, srcOffset,
std::move(srcProxy), radiusX, radiusY, sigmaX, sigmaY, srcBounds); srcTexture.get(), radiusX, radiusY, sigmaX, sigmaY, srcBounds);
return dstRenderTargetContext; return dstRenderTargetContext;
} }
@ -267,8 +268,7 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
domain.inset((i < scaleFactorX) ? SK_ScalarHalf : 0.0f, domain.inset((i < scaleFactorX) ? SK_ScalarHalf : 0.0f,
(i < scaleFactorY) ? SK_ScalarHalf : 0.0f); (i < scaleFactorY) ? SK_ScalarHalf : 0.0f);
sk_sp<GrFragmentProcessor> fp(GrTextureDomainEffect::Make( sk_sp<GrFragmentProcessor> fp(GrTextureDomainEffect::Make(
context, srcTexture.get(),
std::move(srcProxy),
nullptr, nullptr,
SkMatrix::I(), SkMatrix::I(),
domain, domain,
@ -279,8 +279,7 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
srcOffset.set(0, 0); srcOffset.set(0, 0);
} else { } else {
GrSamplerParams params(SkShader::kClamp_TileMode, GrSamplerParams::kBilerp_FilterMode); GrSamplerParams params(SkShader::kClamp_TileMode, GrSamplerParams::kBilerp_FilterMode);
paint.addColorTextureProcessor(context, std::move(srcProxy), nullptr, paint.addColorTextureProcessor(srcTexture.get(), nullptr, SkMatrix::I(), params);
SkMatrix::I(), params);
} }
paint.setPorterDuffXPFactory(SkBlendMode::kSrc); paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
shrink_irect_by_2(&dstRect, i < scaleFactorX, i < scaleFactorY); shrink_irect_by_2(&dstRect, i < scaleFactorX, i < scaleFactorY);
@ -290,8 +289,8 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
srcRenderTargetContext = dstRenderTargetContext; srcRenderTargetContext = dstRenderTargetContext;
srcRect = dstRect; srcRect = dstRect;
srcProxy = sk_ref_sp(srcRenderTargetContext->asDeferredTexture()); srcTexture = srcRenderTargetContext->asTexture();
if (!srcProxy) { if (!srcTexture) {
return nullptr; return nullptr;
} }
dstRenderTargetContext.swap(tmpRenderTargetContext); dstRenderTargetContext.swap(tmpRenderTargetContext);
@ -311,12 +310,12 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
srcRenderTargetContext->priv().absClear(&clearRect, 0x0); srcRenderTargetContext->priv().absClear(&clearRect, 0x0);
} }
convolve_gaussian(context, dstRenderTargetContext.get(), clip, srcRect, convolve_gaussian(dstRenderTargetContext.get(), clip, srcRect,
std::move(srcProxy), Gr1DKernelEffect::kX_Direction, radiusX, sigmaX, srcTexture.get(), Gr1DKernelEffect::kX_Direction, radiusX, sigmaX,
srcBounds, srcOffset); srcBounds, srcOffset);
srcRenderTargetContext = dstRenderTargetContext; srcRenderTargetContext = dstRenderTargetContext;
srcProxy = sk_ref_sp(srcRenderTargetContext->asDeferredTexture()); srcTexture = srcRenderTargetContext->asTexture();
if (!srcProxy) { if (!srcTexture) {
return nullptr; return nullptr;
} }
srcRect.offsetTo(0, 0); srcRect.offsetTo(0, 0);
@ -336,8 +335,8 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
srcRenderTargetContext->priv().absClear(&clearRect, 0x0); srcRenderTargetContext->priv().absClear(&clearRect, 0x0);
} }
convolve_gaussian(context, dstRenderTargetContext.get(), clip, srcRect, convolve_gaussian(dstRenderTargetContext.get(), clip, srcRect,
std::move(srcProxy), Gr1DKernelEffect::kY_Direction, radiusY, sigmaY, srcTexture.get(), Gr1DKernelEffect::kY_Direction, radiusY, sigmaY,
srcBounds, srcOffset); srcBounds, srcOffset);
srcRenderTargetContext = dstRenderTargetContext; srcRenderTargetContext = dstRenderTargetContext;
@ -346,7 +345,7 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
} }
SkASSERT(srcRenderTargetContext); 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) { if (scaleFactorX > 1 || scaleFactorY > 1) {
// Clear one pixel to the right and below, to accommodate bilinear upsampling. // Clear one pixel to the right and below, to accommodate bilinear upsampling.

View File

@ -22,7 +22,7 @@ namespace SkGpuBlurUtils {
* as a renderTargetContext in case the caller wishes to future draw into the result. * as a renderTargetContext in case the caller wishes to future draw into the result.
* Note: one of sigmaX and sigmaY should be non-zero! * Note: one of sigmaX and sigmaY should be non-zero!
* @param context The GPU context * @param context The GPU context
* @param src The source to be blurred. * @param srcTexture The source texture to be blurred.
* @param colorSpace Color space of the source (used for the renderTargetContext result, * @param colorSpace Color space of the source (used for the renderTargetContext result,
* too). * too).
* @param dstBounds The destination bounds, relative to the source texture. * @param dstBounds The destination bounds, relative to the source texture.
@ -34,7 +34,7 @@ namespace SkGpuBlurUtils {
* @return The renderTargetContext containing the blurred result. * @return The renderTargetContext containing the blurred result.
*/ */
sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context, sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
sk_sp<GrTextureProxy> src, GrTexture* srcTexture,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,
const SkIRect& dstBounds, const SkIRect& dstBounds,
const SkIRect* srcBounds, const SkIRect* srcBounds,

View File

@ -1135,12 +1135,12 @@ static sk_sp<GrTexture> find_or_create_rrect_blur_mask(GrContext* context,
rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw, rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw,
GrStyle::SimpleFill()); GrStyle::SimpleFill());
sk_sp<GrTextureProxy> srcProxy(sk_ref_sp(rtc->asDeferredTexture())); sk_sp<GrTexture> srcTexture(rtc->asTexture());
if (!srcProxy) { if (!srcTexture) {
return nullptr; return nullptr;
} }
sk_sp<GrRenderTargetContext> rtc2(SkGpuBlurUtils::GaussianBlur(context, sk_sp<GrRenderTargetContext> rtc2(SkGpuBlurUtils::GaussianBlur(context,
std::move(srcProxy), srcTexture.get(),
nullptr, nullptr,
SkIRect::MakeWH( SkIRect::MakeWH(
size.fWidth, size.fWidth,
@ -1498,11 +1498,16 @@ sk_sp<GrTextureProxy> SkBlurMaskFilterImpl::filterMaskGPU(GrContext* context,
SkScalar xformedSigma = this->computeXformedSigma(ctm); SkScalar xformedSigma = this->computeXformedSigma(ctm);
SkASSERT(xformedSigma > 0); SkASSERT(xformedSigma > 0);
// TODO: defer this further (i.e., push the proxy into GaussianBlur)
GrTexture* src = srcProxy->instantiate(context->textureProvider());
if (!src) {
return nullptr;
}
// If we're doing a normal blur, we can clobber the pathTexture in the // If we're doing a normal blur, we can clobber the pathTexture in the
// gaussianBlur. Otherwise, we need to save it for later compositing. // gaussianBlur. Otherwise, we need to save it for later compositing.
bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle); bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle);
sk_sp<GrRenderTargetContext> renderTargetContext(SkGpuBlurUtils::GaussianBlur(context, sk_sp<GrRenderTargetContext> renderTargetContext(SkGpuBlurUtils::GaussianBlur(context, src,
srcProxy,
nullptr, clipRect, nullptr, clipRect,
nullptr, nullptr,
xformedSigma, xformedSigma,
@ -1515,7 +1520,7 @@ sk_sp<GrTextureProxy> SkBlurMaskFilterImpl::filterMaskGPU(GrContext* context,
GrPaint paint; GrPaint paint;
// Blend pathTexture over blurTexture. // Blend pathTexture over blurTexture.
paint.addCoverageFragmentProcessor( paint.addCoverageFragmentProcessor(
GrSimpleTextureEffect::Make(context, std::move(srcProxy), nullptr, SkMatrix::I())); GrSimpleTextureEffect::Make(src, nullptr, SkMatrix::I()));
if (kInner_SkBlurStyle == fBlurStyle) { if (kInner_SkBlurStyle == fBlurStyle) {
// inner: dst = dst * src // inner: dst = dst * src
paint.setCoverageSetOpXPFactory(SkRegion::kIntersect_Op); paint.setCoverageSetOpXPFactory(SkRegion::kIntersect_Op);

View File

@ -115,17 +115,12 @@ void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman,
} }
pdman.set2fv(fImageIncrementUni, 1, imageIncrement); pdman.set2fv(fImageIncrementUni, 1, imageIncrement);
if (conv.useBounds()) { if (conv.useBounds()) {
const int* bounds = conv.bounds(); const float* bounds = conv.bounds();
if (Gr1DKernelEffect::kX_Direction == conv.direction()) { if (Gr1DKernelEffect::kY_Direction == conv.direction() &&
SkScalar inv = SkScalarInvert(SkIntToScalar(texture.width())); texture.origin() != kTopLeft_GrSurfaceOrigin) {
pdman.set2f(fBoundsUni, inv * bounds[0], inv * bounds[1]); pdman.set2f(fBoundsUni, 1.0f - bounds[1], 1.0f - bounds[0]);
} else { } else {
SkScalar inv = SkScalarInvert(SkIntToScalar(texture.height())); pdman.set2f(fBoundsUni, bounds[0], bounds[1]);
if (texture.origin() != kTopLeft_GrSurfaceOrigin) {
pdman.set2f(fBoundsUni, 1.0f - (inv * bounds[1]), 1.0f - (inv * bounds[0]));
} else {
pdman.set2f(fBoundsUni, inv * bounds[1], inv * bounds[0]);
}
} }
} }
int width = Gr1DKernelEffect::WidthFromRadius(conv.radius()); int width = Gr1DKernelEffect::WidthFromRadius(conv.radius());
@ -149,6 +144,8 @@ void GrGLConvolutionEffect::GenKey(const GrProcessor& processor, const GrShaderC
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
static void fill_in_1D_guassian_kernel(float* kernel, int width, float gaussianSigma, int radius) { static void fill_in_1D_guassian_kernel(float* kernel, int width, float gaussianSigma, int radius) {
const float denom = 1.0f / (2.0f * gaussianSigma * gaussianSigma); const float denom = 1.0f / (2.0f * gaussianSigma * gaussianSigma);
@ -172,7 +169,7 @@ GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(G
int radius, int radius,
float gaussianSigma, float gaussianSigma,
bool useBounds, bool useBounds,
int bounds[2]) float bounds[2])
: INHERITED(texture, direction, radius, ModulationFlags(texture->config())) : INHERITED(texture, direction, radius, ModulationFlags(texture->config()))
, fUseBounds(useBounds) { , fUseBounds(useBounds) {
this->initClassID<GrGaussianConvolutionFragmentProcessor>(); this->initClassID<GrGaussianConvolutionFragmentProcessor>();
@ -190,7 +187,7 @@ GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
int radius, int radius,
float gaussianSigma, float gaussianSigma,
bool useBounds, bool useBounds,
int bounds[2]) float bounds[2])
: INHERITED{context, : INHERITED{context,
ModulationFlags(proxy->config()), ModulationFlags(proxy->config()),
GR_PROXY_MOVE(proxy), GR_PROXY_MOVE(proxy),
@ -233,25 +230,16 @@ sk_sp<GrFragmentProcessor> GrGaussianConvolutionFragmentProcessor::TestCreate(
GrProcessorTestData* d) { GrProcessorTestData* d) {
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: GrProcessorUnitTest::kAlphaTextureIdx; : GrProcessorUnitTest::kAlphaTextureIdx;
sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx); Direction dir = d->fRandom->nextBool() ? kX_Direction : kY_Direction;
int radius = d->fRandom->nextRangeU(1, kMaxKernelRadius);
bool useBounds = d->fRandom->nextBool(); bool useBounds = d->fRandom->nextBool();
int bounds[2]; float bounds[2];
for (size_t i = 0; i < SK_ARRAY_COUNT(bounds); ++i) {
Direction dir; bounds[i] = d->fRandom->nextF();
if (d->fRandom->nextBool()) {
dir = kX_Direction;
bounds[0] = d->fRandom->nextRangeU(0, proxy->width()-1);
bounds[1] = d->fRandom->nextRangeU(bounds[0], proxy->width()-1);
} else {
dir = kY_Direction;
bounds[0] = d->fRandom->nextRangeU(0, proxy->height()-1);
bounds[1] = d->fRandom->nextRangeU(bounds[0], proxy->height()-1);
} }
int radius = d->fRandom->nextRangeU(1, kMaxKernelRadius);
float sigma = radius / 3.f; float sigma = radius / 3.f;
return GrGaussianConvolutionFragmentProcessor::Make( return GrGaussianConvolutionFragmentProcessor::Make(
d->context(), d->textureProxy(texIdx), dir, radius, sigma, useBounds, bounds); d->context(), d->textureProxy(texIdx), dir, radius, sigma, useBounds, bounds);
} }

View File

@ -24,7 +24,7 @@ public:
int halfWidth, int halfWidth,
float gaussianSigma, float gaussianSigma,
bool useBounds, bool useBounds,
int* bounds) { float* bounds) {
return sk_sp<GrFragmentProcessor>(new GrGaussianConvolutionFragmentProcessor( return sk_sp<GrFragmentProcessor>(new GrGaussianConvolutionFragmentProcessor(
tex, dir, halfWidth, gaussianSigma, useBounds, bounds)); tex, dir, halfWidth, gaussianSigma, useBounds, bounds));
} }
@ -35,7 +35,7 @@ public:
int halfWidth, int halfWidth,
float gaussianSigma, float gaussianSigma,
bool useBounds, bool useBounds,
int* bounds) { float* bounds) {
return sk_sp<GrFragmentProcessor>(new GrGaussianConvolutionFragmentProcessor( return sk_sp<GrFragmentProcessor>(new GrGaussianConvolutionFragmentProcessor(
context, std::move(proxy), dir, halfWidth, gaussianSigma, useBounds, bounds)); context, std::move(proxy), dir, halfWidth, gaussianSigma, useBounds, bounds));
} }
@ -44,7 +44,7 @@ public:
const float* kernel() const { return fKernel; } const float* kernel() const { return fKernel; }
const int* bounds() const { return fBounds; } const float* bounds() const { return fBounds; }
bool useBounds() const { return fUseBounds; } bool useBounds() const { return fUseBounds; }
const char* name() const override { return "GaussianConvolution"; } const char* name() const override { return "GaussianConvolution"; }
@ -61,11 +61,11 @@ public:
private: private:
/// Convolve with a Gaussian kernel /// Convolve with a Gaussian kernel
GrGaussianConvolutionFragmentProcessor(GrTexture*, Direction, int halfWidth, GrGaussianConvolutionFragmentProcessor(GrTexture*, Direction, int halfWidth,
float gaussianSigma, bool useBounds, int bounds[2]); float gaussianSigma, bool useBounds, float bounds[2]);
GrGaussianConvolutionFragmentProcessor(GrContext*, sk_sp<GrTextureProxy>, Direction, GrGaussianConvolutionFragmentProcessor(GrContext*, sk_sp<GrTextureProxy>, Direction,
int halfWidth, float gaussianSigma, bool useBounds, int halfWidth, float gaussianSigma, bool useBounds,
int bounds[2]); float bounds[2]);
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
@ -85,7 +85,7 @@ private:
// some of the logic from SkGpuBlurUtils into this class related to radius/sigma calculations. // some of the logic from SkGpuBlurUtils into this class related to radius/sigma calculations.
float fKernel[kMaxKernelWidth]; float fKernel[kMaxKernelWidth];
bool fUseBounds; bool fUseBounds;
int fBounds[2]; float fBounds[2];
typedef Gr1DKernelEffect INHERITED; typedef Gr1DKernelEffect INHERITED;
}; };

View File

@ -3,8 +3,8 @@
* *
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#ifndef GrProxyMove_DEFINED #ifndef GrProxyMove_DEFINED
#define GrProxyMove_DEFINED #define GrProxyMove_DEFINED