| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 const SkRect& srcRect, | 47 const SkRect& srcRect, |
| 48 const SkRect& dstRect, | 48 const SkRect& dstRect, |
| 49 GrTexture* texture, | 49 GrTexture* texture, |
| 50 Gr1DKernelEffect::Direction direction, | 50 Gr1DKernelEffect::Direction direction, |
| 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<GrEffect> 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.addColorEffect(conv); | 60 paint.addColorProcessor(conv); |
| 61 context->drawRectToRect(paint, dstRect, srcRect); | 61 context->drawRectToRect(paint, 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<GrEffect> conv(GrMatrixConvolutionEffect::CreateGaussian( | 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.addColorEffect(conv); | 83 paint.addColorProcessor(conv); |
| 84 context->drawRectToRect(paint, dstRect, srcRect); | 84 context->drawRectToRect(paint, 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, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 SkMatrix matrix; | 190 SkMatrix matrix; |
| 191 matrix.setIDiv(srcTexture->width(), srcTexture->height()); | 191 matrix.setIDiv(srcTexture->width(), srcTexture->height()); |
| 192 context->setRenderTarget(dstTexture->asRenderTarget()); | 192 context->setRenderTarget(dstTexture->asRenderTarget()); |
| 193 SkRect dstRect(srcRect); | 193 SkRect dstRect(srcRect); |
| 194 if (cropToRect && i == 1) { | 194 if (cropToRect && i == 1) { |
| 195 dstRect.offset(-dstRect.fLeft, -dstRect.fTop); | 195 dstRect.offset(-dstRect.fLeft, -dstRect.fTop); |
| 196 SkRect domain; | 196 SkRect domain; |
| 197 matrix.mapRect(&domain, rect); | 197 matrix.mapRect(&domain, rect); |
| 198 domain.inset(i < scaleFactorX ? SK_ScalarHalf / srcTexture->width()
: 0.0f, | 198 domain.inset(i < scaleFactorX ? SK_ScalarHalf / srcTexture->width()
: 0.0f, |
| 199 i < scaleFactorY ? SK_ScalarHalf / srcTexture->height()
: 0.0f); | 199 i < scaleFactorY ? SK_ScalarHalf / srcTexture->height()
: 0.0f); |
| 200 SkAutoTUnref<GrEffect> effect(GrTextureDomainEffect::Create( | 200 SkAutoTUnref<GrFragmentProcessor> fp(GrTextureDomainEffect::Create( |
| 201 srcTexture, | 201 srcTexture, |
| 202 matrix, | 202 matrix, |
| 203 domain, | 203 domain, |
| 204 GrTextureDomain::kDecal_Mode, | 204 GrTextureDomain::kDecal_Mode, |
| 205 GrTextureParams::kBilerp_FilterMode)); | 205 GrTextureParams::kBilerp_FilterMode)); |
| 206 paint.addColorEffect(effect); | 206 paint.addColorProcessor(fp); |
| 207 } else { | 207 } else { |
| 208 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k
Bilerp_FilterMode); | 208 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k
Bilerp_FilterMode); |
| 209 paint.addColorTextureEffect(srcTexture, matrix, params); | 209 paint.addColorTextureProcessor(srcTexture, matrix, params); |
| 210 } | 210 } |
| 211 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, | 211 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, |
| 212 i < scaleFactorY ? 0.5f : 1.0f); | 212 i < scaleFactorY ? 0.5f : 1.0f); |
| 213 context->drawRectToRect(paint, dstRect, srcRect); | 213 context->drawRectToRect(paint, dstRect, srcRect); |
| 214 srcRect = dstRect; | 214 srcRect = dstRect; |
| 215 srcTexture = dstTexture; | 215 srcTexture = dstTexture; |
| 216 SkTSwap(dstTexture, tempTexture); | 216 SkTSwap(dstTexture, tempTexture); |
| 217 } | 217 } |
| 218 | 218 |
| 219 SkIRect srcIRect; | 219 SkIRect srcIRect; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, | 279 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, |
| 280 1, srcIRect.height()); | 280 1, srcIRect.height()); |
| 281 context->clear(&clearRect, 0x0, false); | 281 context->clear(&clearRect, 0x0, false); |
| 282 SkMatrix matrix; | 282 SkMatrix matrix; |
| 283 matrix.setIDiv(srcTexture->width(), srcTexture->height()); | 283 matrix.setIDiv(srcTexture->width(), srcTexture->height()); |
| 284 context->setRenderTarget(dstTexture->asRenderTarget()); | 284 context->setRenderTarget(dstTexture->asRenderTarget()); |
| 285 | 285 |
| 286 GrPaint paint; | 286 GrPaint paint; |
| 287 // FIXME: this should be mitchell, not bilinear. | 287 // FIXME: this should be mitchell, not bilinear. |
| 288 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile
rp_FilterMode); | 288 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile
rp_FilterMode); |
| 289 paint.addColorTextureEffect(srcTexture, matrix, params); | 289 paint.addColorTextureProcessor(srcTexture, matrix, params); |
| 290 | 290 |
| 291 SkRect dstRect(srcRect); | 291 SkRect dstRect(srcRect); |
| 292 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); | 292 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); |
| 293 context->drawRectToRect(paint, dstRect, srcRect); | 293 context->drawRectToRect(paint, dstRect, srcRect); |
| 294 srcRect = dstRect; | 294 srcRect = dstRect; |
| 295 srcTexture = dstTexture; | 295 srcTexture = dstTexture; |
| 296 SkTSwap(dstTexture, tempTexture); | 296 SkTSwap(dstTexture, tempTexture); |
| 297 } | 297 } |
| 298 if (srcTexture == temp1.texture()) { | 298 if (srcTexture == temp1.texture()) { |
| 299 return temp1.detach(); | 299 return temp1.detach(); |
| 300 } else if (srcTexture == temp2.texture()) { | 300 } else if (srcTexture == temp2.texture()) { |
| 301 return temp2.detach(); | 301 return temp2.detach(); |
| 302 } else { | 302 } else { |
| 303 srcTexture->ref(); | 303 srcTexture->ref(); |
| 304 return srcTexture; | 304 return srcTexture; |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 #endif | 307 #endif |
| 308 | 308 |
| 309 } | 309 } |
| OLD | NEW |