| 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 190 |
| 191 SkIRect srcIRect; | 191 SkIRect srcIRect; |
| 192 srcRect.roundOut(&srcIRect); | 192 srcRect.roundOut(&srcIRect); |
| 193 | 193 |
| 194 if (sigmaX > 0.0f) { | 194 if (sigmaX > 0.0f) { |
| 195 if (scaleFactorX > 1) { | 195 if (scaleFactorX > 1) { |
| 196 // Clear out a radius to the right of the srcRect to prevent the | 196 // Clear out a radius to the right of the srcRect to prevent the |
| 197 // X convolution from reading garbage. | 197 // X convolution from reading garbage. |
| 198 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, | 198 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, |
| 199 radiusX, srcIRect.height()); | 199 radiusX, srcIRect.height()); |
| 200 context->clear(&clearRect, 0x0); | 200 context->clear(&clearRect, 0x0, false); |
| 201 } | 201 } |
| 202 context->setRenderTarget(dstTexture->asRenderTarget()); | 202 context->setRenderTarget(dstTexture->asRenderTarget()); |
| 203 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | 203 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
| 204 convolve_gaussian(context, srcRect, dstRect, srcTexture, | 204 convolve_gaussian(context, srcRect, dstRect, srcTexture, |
| 205 Gr1DKernelEffect::kX_Direction, radiusX, sigmaX, cropT
oRect); | 205 Gr1DKernelEffect::kX_Direction, radiusX, sigmaX, cropT
oRect); |
| 206 srcTexture = dstTexture; | 206 srcTexture = dstTexture; |
| 207 srcRect = dstRect; | 207 srcRect = dstRect; |
| 208 SkTSwap(dstTexture, tempTexture); | 208 SkTSwap(dstTexture, tempTexture); |
| 209 } | 209 } |
| 210 | 210 |
| 211 if (sigmaY > 0.0f) { | 211 if (sigmaY > 0.0f) { |
| 212 if (scaleFactorY > 1 || sigmaX > 0.0f) { | 212 if (scaleFactorY > 1 || sigmaX > 0.0f) { |
| 213 // Clear out a radius below the srcRect to prevent the Y | 213 // Clear out a radius below the srcRect to prevent the Y |
| 214 // convolution from reading garbage. | 214 // convolution from reading garbage. |
| 215 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, | 215 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, |
| 216 srcIRect.width(), radiusY); | 216 srcIRect.width(), radiusY); |
| 217 context->clear(&clearRect, 0x0); | 217 context->clear(&clearRect, 0x0, false); |
| 218 } | 218 } |
| 219 | 219 |
| 220 context->setRenderTarget(dstTexture->asRenderTarget()); | 220 context->setRenderTarget(dstTexture->asRenderTarget()); |
| 221 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | 221 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
| 222 convolve_gaussian(context, srcRect, dstRect, srcTexture, | 222 convolve_gaussian(context, srcRect, dstRect, srcTexture, |
| 223 Gr1DKernelEffect::kY_Direction, radiusY, sigmaY, cropT
oRect); | 223 Gr1DKernelEffect::kY_Direction, radiusY, sigmaY, cropT
oRect); |
| 224 srcTexture = dstTexture; | 224 srcTexture = dstTexture; |
| 225 srcRect = dstRect; | 225 srcRect = dstRect; |
| 226 SkTSwap(dstTexture, tempTexture); | 226 SkTSwap(dstTexture, tempTexture); |
| 227 } | 227 } |
| 228 | 228 |
| 229 if (scaleFactorX > 1 || scaleFactorY > 1) { | 229 if (scaleFactorX > 1 || scaleFactorY > 1) { |
| 230 // Clear one pixel to the right and below, to accommodate bilinear | 230 // Clear one pixel to the right and below, to accommodate bilinear |
| 231 // upsampling. | 231 // upsampling. |
| 232 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, | 232 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, |
| 233 srcIRect.width() + 1, 1); | 233 srcIRect.width() + 1, 1); |
| 234 context->clear(&clearRect, 0x0); | 234 context->clear(&clearRect, 0x0, false); |
| 235 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, | 235 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, |
| 236 1, srcIRect.height()); | 236 1, srcIRect.height()); |
| 237 context->clear(&clearRect, 0x0); | 237 context->clear(&clearRect, 0x0, false); |
| 238 SkMatrix matrix; | 238 SkMatrix matrix; |
| 239 matrix.setIDiv(srcTexture->width(), srcTexture->height()); | 239 matrix.setIDiv(srcTexture->width(), srcTexture->height()); |
| 240 context->setRenderTarget(dstTexture->asRenderTarget()); | 240 context->setRenderTarget(dstTexture->asRenderTarget()); |
| 241 | 241 |
| 242 GrPaint paint; | 242 GrPaint paint; |
| 243 // FIXME: this should be mitchell, not bilinear. | 243 // FIXME: this should be mitchell, not bilinear. |
| 244 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile
rp_FilterMode); | 244 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile
rp_FilterMode); |
| 245 paint.addColorTextureEffect(srcTexture, matrix, params); | 245 paint.addColorTextureEffect(srcTexture, matrix, params); |
| 246 | 246 |
| 247 SkRect dstRect(srcRect); | 247 SkRect dstRect(srcRect); |
| 248 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); | 248 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); |
| 249 context->drawRectToRect(paint, dstRect, srcRect); | 249 context->drawRectToRect(paint, dstRect, srcRect); |
| 250 srcRect = dstRect; | 250 srcRect = dstRect; |
| 251 srcTexture = dstTexture; | 251 srcTexture = dstTexture; |
| 252 SkTSwap(dstTexture, tempTexture); | 252 SkTSwap(dstTexture, tempTexture); |
| 253 } | 253 } |
| 254 if (srcTexture == temp1.texture()) { | 254 if (srcTexture == temp1.texture()) { |
| 255 return temp1.detach(); | 255 return temp1.detach(); |
| 256 } else if (srcTexture == temp2.texture()) { | 256 } else if (srcTexture == temp2.texture()) { |
| 257 return temp2.detach(); | 257 return temp2.detach(); |
| 258 } else { | 258 } else { |
| 259 srcTexture->ref(); | 259 srcTexture->ref(); |
| 260 return srcTexture; | 260 return srcTexture; |
| 261 } | 261 } |
| 262 } | 262 } |
| 263 #endif | 263 #endif |
| 264 | 264 |
| 265 } | 265 } |
| OLD | NEW |