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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 srcRect = dstRect; | 243 srcRect = dstRect; |
244 SkTSwap(dstTexture, tempTexture); | 244 SkTSwap(dstTexture, tempTexture); |
245 | 245 |
246 } else { | 246 } else { |
247 if (sigmaX > 0.0f) { | 247 if (sigmaX > 0.0f) { |
248 if (scaleFactorX > 1) { | 248 if (scaleFactorX > 1) { |
249 // Clear out a radius to the right of the srcRect to prevent the | 249 // Clear out a radius to the right of the srcRect to prevent the |
250 // X convolution from reading garbage. | 250 // X convolution from reading garbage. |
251 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, | 251 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, |
252 radiusX, srcIRect.height()); | 252 radiusX, srcIRect.height()); |
253 context->clear(&clearRect, 0x0, false); | 253 context->clear(&clearRect, 0x0, false, context->getRenderTarget(
)); |
254 } | 254 } |
255 context->setRenderTarget(dstTexture->asRenderTarget()); | 255 context->setRenderTarget(dstTexture->asRenderTarget()); |
256 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | 256 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
257 convolve_gaussian(context, srcRect, dstRect, srcTexture, | 257 convolve_gaussian(context, srcRect, dstRect, srcTexture, |
258 Gr1DKernelEffect::kX_Direction, radiusX, sigmaX, c
ropToRect); | 258 Gr1DKernelEffect::kX_Direction, radiusX, sigmaX, c
ropToRect); |
259 srcTexture = dstTexture; | 259 srcTexture = dstTexture; |
260 srcRect = dstRect; | 260 srcRect = dstRect; |
261 SkTSwap(dstTexture, tempTexture); | 261 SkTSwap(dstTexture, tempTexture); |
262 } | 262 } |
263 | 263 |
264 if (sigmaY > 0.0f) { | 264 if (sigmaY > 0.0f) { |
265 if (scaleFactorY > 1 || sigmaX > 0.0f) { | 265 if (scaleFactorY > 1 || sigmaX > 0.0f) { |
266 // Clear out a radius below the srcRect to prevent the Y | 266 // Clear out a radius below the srcRect to prevent the Y |
267 // convolution from reading garbage. | 267 // convolution from reading garbage. |
268 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, | 268 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, |
269 srcIRect.width(), radiusY); | 269 srcIRect.width(), radiusY); |
270 context->clear(&clearRect, 0x0, false); | 270 context->clear(&clearRect, 0x0, false, context->getRenderTarget(
)); |
271 } | 271 } |
272 | 272 |
273 context->setRenderTarget(dstTexture->asRenderTarget()); | 273 context->setRenderTarget(dstTexture->asRenderTarget()); |
274 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | 274 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
275 convolve_gaussian(context, srcRect, dstRect, srcTexture, | 275 convolve_gaussian(context, srcRect, dstRect, srcTexture, |
276 Gr1DKernelEffect::kY_Direction, radiusY, sigmaY, c
ropToRect); | 276 Gr1DKernelEffect::kY_Direction, radiusY, sigmaY, c
ropToRect); |
277 srcTexture = dstTexture; | 277 srcTexture = dstTexture; |
278 srcRect = dstRect; | 278 srcRect = dstRect; |
279 SkTSwap(dstTexture, tempTexture); | 279 SkTSwap(dstTexture, tempTexture); |
280 } | 280 } |
281 } | 281 } |
282 | 282 |
283 if (scaleFactorX > 1 || scaleFactorY > 1) { | 283 if (scaleFactorX > 1 || scaleFactorY > 1) { |
284 // Clear one pixel to the right and below, to accommodate bilinear | 284 // Clear one pixel to the right and below, to accommodate bilinear |
285 // upsampling. | 285 // upsampling. |
286 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, | 286 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, |
287 srcIRect.width() + 1, 1); | 287 srcIRect.width() + 1, 1); |
288 context->clear(&clearRect, 0x0, false); | 288 context->clear(&clearRect, 0x0, false, context->getRenderTarget()); |
289 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, | 289 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, |
290 1, srcIRect.height()); | 290 1, srcIRect.height()); |
291 context->clear(&clearRect, 0x0, false); | 291 context->clear(&clearRect, 0x0, false, context->getRenderTarget()); |
292 SkMatrix matrix; | 292 SkMatrix matrix; |
293 matrix.setIDiv(srcTexture->width(), srcTexture->height()); | 293 matrix.setIDiv(srcTexture->width(), srcTexture->height()); |
294 context->setRenderTarget(dstTexture->asRenderTarget()); | 294 context->setRenderTarget(dstTexture->asRenderTarget()); |
295 | 295 |
296 GrPaint paint; | 296 GrPaint paint; |
297 // FIXME: this should be mitchell, not bilinear. | 297 // FIXME: this should be mitchell, not bilinear. |
298 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile
rp_FilterMode); | 298 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile
rp_FilterMode); |
299 paint.addColorTextureProcessor(srcTexture, matrix, params); | 299 paint.addColorTextureProcessor(srcTexture, matrix, params); |
300 | 300 |
301 SkRect dstRect(srcRect); | 301 SkRect dstRect(srcRect); |
302 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); | 302 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); |
303 context->drawRectToRect(paint, dstRect, srcRect); | 303 context->drawRectToRect(paint, dstRect, srcRect); |
304 srcRect = dstRect; | 304 srcRect = dstRect; |
305 srcTexture = dstTexture; | 305 srcTexture = dstTexture; |
306 SkTSwap(dstTexture, tempTexture); | 306 SkTSwap(dstTexture, tempTexture); |
307 } | 307 } |
308 return SkRef(srcTexture); | 308 return SkRef(srcTexture); |
309 } | 309 } |
310 #endif | 310 #endif |
311 | 311 |
312 } | 312 } |
OLD | NEW |