| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkGpuBlurUtils.h" | 8 #include "SkGpuBlurUtils.h" |
| 9 | 9 |
| 10 #include "SkRect.h" | 10 #include "SkRect.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 int radius, | 51 int radius, |
| 52 float sigma, | 52 float sigma, |
| 53 bool useBounds, | 53 bool useBounds, |
| 54 float bounds[2]) { | 54 float bounds[2]) { |
| 55 GrPaint paint; | 55 GrPaint paint; |
| 56 paint.reset(); | 56 paint.reset(); |
| 57 SkAutoTUnref<GrFragmentProcessor> conv(GrConvolutionEffect::CreateGaussian( | 57 SkAutoTUnref<GrFragmentProcessor> conv(GrConvolutionEffect::CreateGaussian( |
| 58 texture, direction, radius, sigma, useBounds, bounds)); | 58 texture, direction, radius, sigma, useBounds, bounds)); |
| 59 paint.reset(); | 59 paint.reset(); |
| 60 paint.addColorProcessor(conv); | 60 paint.addColorProcessor(conv); |
| 61 context->drawRectToRect(paint, dstRect, srcRect); | 61 context->drawRectToRect(paint, SkMatrix::I(), dstRect, srcRect); |
| 62 } | 62 } |
| 63 | 63 |
| 64 static void convolve_gaussian_2d(GrContext* context, | 64 static void convolve_gaussian_2d(GrContext* context, |
| 65 const SkRect& srcRect, | 65 const SkRect& srcRect, |
| 66 const SkRect& dstRect, | 66 const SkRect& dstRect, |
| 67 GrTexture* texture, | 67 GrTexture* texture, |
| 68 int radiusX, | 68 int radiusX, |
| 69 int radiusY, | 69 int radiusY, |
| 70 SkScalar sigmaX, | 70 SkScalar sigmaX, |
| 71 SkScalar sigmaY, | 71 SkScalar sigmaY, |
| 72 bool useBounds, | 72 bool useBounds, |
| 73 SkIRect bounds) { | 73 SkIRect bounds) { |
| 74 SkISize size = SkISize::Make(2 * radiusX + 1, 2 * radiusY + 1); | 74 SkISize size = SkISize::Make(2 * radiusX + 1, 2 * radiusY + 1); |
| 75 SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY); | 75 SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY); |
| 76 GrPaint paint; | 76 GrPaint paint; |
| 77 paint.reset(); | 77 paint.reset(); |
| 78 SkAutoTUnref<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::CreateGaus
sian( | 78 SkAutoTUnref<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::CreateGaus
sian( |
| 79 texture, bounds, size, 1.0, 0.0, kernelOffset, | 79 texture, bounds, size, 1.0, 0.0, kernelOffset, |
| 80 useBounds ? GrTextureDomain::kClamp_Mode : GrTextureDomain::kIgnore_
Mode, | 80 useBounds ? GrTextureDomain::kClamp_Mode : GrTextureDomain::kIgnore_
Mode, |
| 81 true, sigmaX, sigmaY)); | 81 true, sigmaX, sigmaY)); |
| 82 paint.reset(); | 82 paint.reset(); |
| 83 paint.addColorProcessor(conv); | 83 paint.addColorProcessor(conv); |
| 84 context->drawRectToRect(paint, dstRect, srcRect); | 84 context->drawRectToRect(paint, SkMatrix::I(), dstRect, srcRect); |
| 85 } | 85 } |
| 86 | 86 |
| 87 static void convolve_gaussian(GrContext* context, | 87 static void convolve_gaussian(GrContext* context, |
| 88 const SkRect& srcRect, | 88 const SkRect& srcRect, |
| 89 const SkRect& dstRect, | 89 const SkRect& dstRect, |
| 90 GrTexture* texture, | 90 GrTexture* texture, |
| 91 Gr1DKernelEffect::Direction direction, | 91 Gr1DKernelEffect::Direction direction, |
| 92 int radius, | 92 int radius, |
| 93 float sigma, | 93 float sigma, |
| 94 bool cropToSrcRect) { | 94 bool cropToSrcRect) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 GrTexture* srcTexture, | 143 GrTexture* srcTexture, |
| 144 bool canClobberSrc, | 144 bool canClobberSrc, |
| 145 const SkRect& rect, | 145 const SkRect& rect, |
| 146 bool cropToRect, | 146 bool cropToRect, |
| 147 float sigmaX, | 147 float sigmaX, |
| 148 float sigmaY) { | 148 float sigmaY) { |
| 149 SkASSERT(context); | 149 SkASSERT(context); |
| 150 | 150 |
| 151 GrContext::AutoRenderTarget art(context); | 151 GrContext::AutoRenderTarget art(context); |
| 152 | 152 |
| 153 GrContext::AutoMatrix am; | |
| 154 am.setIdentity(context); | |
| 155 | |
| 156 SkIRect clearRect; | 153 SkIRect clearRect; |
| 157 int scaleFactorX, radiusX; | 154 int scaleFactorX, radiusX; |
| 158 int scaleFactorY, radiusY; | 155 int scaleFactorY, radiusY; |
| 159 int maxTextureSize = context->getMaxTextureSize(); | 156 int maxTextureSize = context->getMaxTextureSize(); |
| 160 sigmaX = adjust_sigma(sigmaX, maxTextureSize, &scaleFactorX, &radiusX); | 157 sigmaX = adjust_sigma(sigmaX, maxTextureSize, &scaleFactorX, &radiusX); |
| 161 sigmaY = adjust_sigma(sigmaY, maxTextureSize, &scaleFactorY, &radiusY); | 158 sigmaY = adjust_sigma(sigmaY, maxTextureSize, &scaleFactorY, &radiusY); |
| 162 | 159 |
| 163 SkRect srcRect(rect); | 160 SkRect srcRect(rect); |
| 164 scale_rect(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY); | 161 scale_rect(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY); |
| 165 srcRect.roundOut(&srcRect); | 162 srcRect.roundOut(&srcRect); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 domain, | 210 domain, |
| 214 GrTextureDomain::kDecal_Mode, | 211 GrTextureDomain::kDecal_Mode, |
| 215 GrTextureParams::kBilerp_FilterMode)); | 212 GrTextureParams::kBilerp_FilterMode)); |
| 216 paint.addColorProcessor(fp); | 213 paint.addColorProcessor(fp); |
| 217 } else { | 214 } else { |
| 218 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k
Bilerp_FilterMode); | 215 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k
Bilerp_FilterMode); |
| 219 paint.addColorTextureProcessor(srcTexture, matrix, params); | 216 paint.addColorTextureProcessor(srcTexture, matrix, params); |
| 220 } | 217 } |
| 221 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, | 218 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, |
| 222 i < scaleFactorY ? 0.5f : 1.0f); | 219 i < scaleFactorY ? 0.5f : 1.0f); |
| 223 context->drawRectToRect(paint, dstRect, srcRect); | 220 context->drawRectToRect(paint, SkMatrix::I(), dstRect, srcRect); |
| 224 srcRect = dstRect; | 221 srcRect = dstRect; |
| 225 srcTexture = dstTexture; | 222 srcTexture = dstTexture; |
| 226 SkTSwap(dstTexture, tempTexture); | 223 SkTSwap(dstTexture, tempTexture); |
| 227 } | 224 } |
| 228 | 225 |
| 229 const SkIRect srcIRect = srcRect.roundOut(); | 226 const SkIRect srcIRect = srcRect.roundOut(); |
| 230 | 227 |
| 231 // For really small blurs(Certainly no wider than 5x5 on desktop gpus) it is
faster to just | 228 // For really small blurs(Certainly no wider than 5x5 on desktop gpus) it is
faster to just |
| 232 // launch a single non separable kernel vs two launches | 229 // launch a single non separable kernel vs two launches |
| 233 if (sigmaX > 0.0f && sigmaY > 0 && | 230 if (sigmaX > 0.0f && sigmaY > 0 && |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 matrix.setIDiv(srcTexture->width(), srcTexture->height()); | 289 matrix.setIDiv(srcTexture->width(), srcTexture->height()); |
| 293 context->setRenderTarget(dstTexture->asRenderTarget()); | 290 context->setRenderTarget(dstTexture->asRenderTarget()); |
| 294 | 291 |
| 295 GrPaint paint; | 292 GrPaint paint; |
| 296 // FIXME: this should be mitchell, not bilinear. | 293 // FIXME: this should be mitchell, not bilinear. |
| 297 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile
rp_FilterMode); | 294 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile
rp_FilterMode); |
| 298 paint.addColorTextureProcessor(srcTexture, matrix, params); | 295 paint.addColorTextureProcessor(srcTexture, matrix, params); |
| 299 | 296 |
| 300 SkRect dstRect(srcRect); | 297 SkRect dstRect(srcRect); |
| 301 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); | 298 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); |
| 302 context->drawRectToRect(paint, dstRect, srcRect); | 299 context->drawRectToRect(paint, SkMatrix::I(), dstRect, srcRect); |
| 303 srcRect = dstRect; | 300 srcRect = dstRect; |
| 304 srcTexture = dstTexture; | 301 srcTexture = dstTexture; |
| 305 SkTSwap(dstTexture, tempTexture); | 302 SkTSwap(dstTexture, tempTexture); |
| 306 } | 303 } |
| 307 return SkRef(srcTexture); | 304 return SkRef(srcTexture); |
| 308 } | 305 } |
| 309 #endif | 306 #endif |
| 310 | 307 |
| 311 } | 308 } |
| OLD | NEW |