Chromium Code Reviews| Index: src/effects/SkGpuBlurUtils.cpp |
| diff --git a/src/effects/SkGpuBlurUtils.cpp b/src/effects/SkGpuBlurUtils.cpp |
| index 6cb349e13686001a75c77655dc325b978de91877..4997afe22f7364d48e27275a4b7b499fd5bf2d0b 100644 |
| --- a/src/effects/SkGpuBlurUtils.cpp |
| +++ b/src/effects/SkGpuBlurUtils.cpp |
| @@ -13,6 +13,7 @@ |
| #include "effects/GrConvolutionEffect.h" |
| #include "effects/GrMatrixConvolutionEffect.h" |
| #include "GrContext.h" |
| +#include "GrDrawContext.h" |
| #endif |
| namespace SkGpuBlurUtils { |
| @@ -43,7 +44,7 @@ static float adjust_sigma(float sigma, int maxTextureSize, int *scaleFactor, int |
| return sigma; |
| } |
| -static void convolve_gaussian_1d(GrContext* context, |
| +static void convolve_gaussian_1d(GrDrawContext* drawContext, |
| GrRenderTarget* rt, |
| const GrClip& clip, |
| const SkRect& srcRect, |
| @@ -58,10 +59,10 @@ static void convolve_gaussian_1d(GrContext* context, |
| SkAutoTUnref<GrFragmentProcessor> conv(GrConvolutionEffect::CreateGaussian( |
| texture, direction, radius, sigma, useBounds, bounds)); |
| paint.addColorProcessor(conv); |
| - context->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), dstRect, srcRect); |
| + drawContext->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), dstRect, srcRect); |
| } |
| -static void convolve_gaussian_2d(GrContext* context, |
| +static void convolve_gaussian_2d(GrDrawContext* drawContext, |
| GrRenderTarget* rt, |
|
bsalomon
2015/05/22 20:33:57
could a next evolution GrDrawContext() include the
robertphillips
2015/05/26 16:12:58
Right - in the future each GrDrawContext will hold
|
| const GrClip& clip, |
| const SkRect& srcRect, |
| @@ -81,10 +82,10 @@ static void convolve_gaussian_2d(GrContext* context, |
| useBounds ? GrTextureDomain::kClamp_Mode : GrTextureDomain::kIgnore_Mode, |
| true, sigmaX, sigmaY)); |
| paint.addColorProcessor(conv); |
| - context->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), dstRect, srcRect); |
| + drawContext->drawNonAARectToRect(rt, clip, paint, SkMatrix::I(), dstRect, srcRect); |
| } |
| -static void convolve_gaussian(GrContext* context, |
| +static void convolve_gaussian(GrDrawContext* drawContext, |
| GrRenderTarget* rt, |
| const GrClip& clip, |
| const SkRect& srcRect, |
| @@ -96,7 +97,7 @@ static void convolve_gaussian(GrContext* context, |
| bool cropToSrcRect) { |
| float bounds[2] = { 0.0f, 1.0f }; |
| if (!cropToSrcRect) { |
| - convolve_gaussian_1d(context, rt, clip, srcRect, dstRect, texture, |
| + convolve_gaussian_1d(drawContext, rt, clip, srcRect, dstRect, texture, |
| direction, radius, sigma, false, bounds); |
| return; |
| } |
| @@ -128,15 +129,15 @@ static void convolve_gaussian(GrContext* context, |
| } |
| if (radius >= size * SK_ScalarHalf) { |
| // Blur radius covers srcRect; use bounds over entire draw |
| - convolve_gaussian_1d(context, rt, clip, srcRect, dstRect, texture, |
| + convolve_gaussian_1d(drawContext, rt, clip, srcRect, dstRect, texture, |
| direction, radius, sigma, true, bounds); |
| } else { |
| // Draw upper and lower margins with bounds; middle without. |
| - convolve_gaussian_1d(context, rt, clip, lowerSrcRect, lowerDstRect, texture, |
| + convolve_gaussian_1d(drawContext, rt, clip, lowerSrcRect, lowerDstRect, texture, |
| direction, radius, sigma, true, bounds); |
| - convolve_gaussian_1d(context, rt, clip, upperSrcRect, upperDstRect, texture, |
| + convolve_gaussian_1d(drawContext, rt, clip, upperSrcRect, upperDstRect, texture, |
| direction, radius, sigma, true, bounds); |
| - convolve_gaussian_1d(context, rt, clip, middleSrcRect, middleDstRect, texture, |
| + convolve_gaussian_1d(drawContext, rt, clip, middleSrcRect, middleDstRect, texture, |
| direction, radius, sigma, false, bounds); |
| } |
| } |
| @@ -195,6 +196,11 @@ GrTexture* GaussianBlur(GrContext* context, |
| return NULL; |
| } |
| + GrDrawContext* drawContext = context->drawContext(); |
| + if (!drawContext) { |
| + return NULL; |
| + } |
| + |
| for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) { |
| GrPaint paint; |
| SkMatrix matrix; |
| @@ -219,8 +225,8 @@ GrTexture* GaussianBlur(GrContext* context, |
| } |
| scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, |
| i < scaleFactorY ? 0.5f : 1.0f); |
| - context->drawNonAARectToRect(dstTexture->asRenderTarget(), clip, paint, SkMatrix::I(), |
| - dstRect, srcRect); |
| + drawContext->drawNonAARectToRect(dstTexture->asRenderTarget(), clip, paint, SkMatrix::I(), |
| + dstRect, srcRect); |
| srcRect = dstRect; |
| srcTexture = dstTexture; |
| SkTSwap(dstTexture, tempTexture); |
| @@ -235,7 +241,7 @@ GrTexture* GaussianBlur(GrContext* context, |
| // We shouldn't be scaling because this is a small size blur |
| SkASSERT((scaleFactorX == scaleFactorY) == 1); |
| SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
| - convolve_gaussian_2d(context, dstTexture->asRenderTarget(), clip, srcRect, dstRect, |
| + convolve_gaussian_2d(drawContext, dstTexture->asRenderTarget(), clip, srcRect, dstRect, |
| srcTexture, radiusX, radiusY, sigmaX, sigmaY, cropToRect, srcIRect); |
| srcTexture = dstTexture; |
| srcRect = dstRect; |
| @@ -248,10 +254,10 @@ GrTexture* GaussianBlur(GrContext* context, |
| // X convolution from reading garbage. |
| clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, |
| radiusX, srcIRect.height()); |
| - context->clear(&clearRect, 0x0, false, srcTexture->asRenderTarget()); |
| + drawContext->clear(srcTexture->asRenderTarget(), &clearRect, 0x0, false); |
| } |
| SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
| - convolve_gaussian(context, dstTexture->asRenderTarget(), clip, srcRect, dstRect, |
| + convolve_gaussian(drawContext, dstTexture->asRenderTarget(), clip, srcRect, dstRect, |
| srcTexture, Gr1DKernelEffect::kX_Direction, radiusX, sigmaX, |
| cropToRect); |
| srcTexture = dstTexture; |
| @@ -265,11 +271,11 @@ GrTexture* GaussianBlur(GrContext* context, |
| // convolution from reading garbage. |
| clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, |
| srcIRect.width(), radiusY); |
| - context->clear(&clearRect, 0x0, false, srcTexture->asRenderTarget()); |
| + drawContext->clear(srcTexture->asRenderTarget(), &clearRect, 0x0, false); |
| } |
| SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
| - convolve_gaussian(context, dstTexture->asRenderTarget(), clip, srcRect, |
| + convolve_gaussian(drawContext, dstTexture->asRenderTarget(), clip, srcRect, |
| dstRect, srcTexture, Gr1DKernelEffect::kY_Direction, radiusY, sigmaY, |
| cropToRect); |
| srcTexture = dstTexture; |
| @@ -283,10 +289,10 @@ GrTexture* GaussianBlur(GrContext* context, |
| // upsampling. |
| clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, |
| srcIRect.width() + 1, 1); |
| - context->clear(&clearRect, 0x0, false, srcTexture->asRenderTarget()); |
| + drawContext->clear(srcTexture->asRenderTarget(), &clearRect, 0x0, false); |
| clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, |
| 1, srcIRect.height()); |
| - context->clear(&clearRect, 0x0, false, srcTexture->asRenderTarget()); |
| + drawContext->clear(srcTexture->asRenderTarget(), &clearRect, 0x0, false); |
| SkMatrix matrix; |
| matrix.setIDiv(srcTexture->width(), srcTexture->height()); |
| @@ -297,8 +303,8 @@ GrTexture* GaussianBlur(GrContext* context, |
| SkRect dstRect(srcRect); |
| scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); |
| - context->drawNonAARectToRect(dstTexture->asRenderTarget(), clip, paint, |
| - SkMatrix::I(), dstRect, srcRect); |
| + drawContext->drawNonAARectToRect(dstTexture->asRenderTarget(), clip, paint, |
| + SkMatrix::I(), dstRect, srcRect); |
| srcRect = dstRect; |
| srcTexture = dstTexture; |
| SkTSwap(dstTexture, tempTexture); |