| 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 tempTexture = srcTexture; | 221 tempTexture = srcTexture; |
| 222 } else { | 222 } else { |
| 223 temp2.reset(context->textureProvider()->createApproxTexture(desc)); | 223 temp2.reset(context->textureProvider()->createApproxTexture(desc)); |
| 224 tempTexture = temp2.get(); | 224 tempTexture = temp2.get(); |
| 225 } | 225 } |
| 226 | 226 |
| 227 if (nullptr == dstTexture || nullptr == tempTexture) { | 227 if (nullptr == dstTexture || nullptr == tempTexture) { |
| 228 return nullptr; | 228 return nullptr; |
| 229 } | 229 } |
| 230 | 230 |
| 231 SkAutoTUnref<GrDrawContext> srcDrawContext; | 231 sk_sp<GrDrawContext> srcDrawContext; |
| 232 | 232 |
| 233 for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) { | 233 for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) { |
| 234 GrPaint paint; | 234 GrPaint paint; |
| 235 paint.setGammaCorrect(gammaCorrect); | 235 paint.setGammaCorrect(gammaCorrect); |
| 236 SkMatrix matrix; | 236 SkMatrix matrix; |
| 237 matrix.setIDiv(srcTexture->width(), srcTexture->height()); | 237 matrix.setIDiv(srcTexture->width(), srcTexture->height()); |
| 238 SkRect dstRect(srcRect); | 238 SkRect dstRect(srcRect); |
| 239 if (srcBounds && i == 1) { | 239 if (srcBounds && i == 1) { |
| 240 SkRect domain; | 240 SkRect domain; |
| 241 matrix.mapRect(&domain, *srcBounds); | 241 matrix.mapRect(&domain, *srcBounds); |
| 242 domain.inset((i < scaleFactorX) ? SK_ScalarHalf / srcTexture->width(
) : 0.0f, | 242 domain.inset((i < scaleFactorX) ? SK_ScalarHalf / srcTexture->width(
) : 0.0f, |
| 243 (i < scaleFactorY) ? SK_ScalarHalf / srcTexture->height
() : 0.0f); | 243 (i < scaleFactorY) ? SK_ScalarHalf / srcTexture->height
() : 0.0f); |
| 244 SkAutoTUnref<const GrFragmentProcessor> fp(GrTextureDomainEffect::Cr
eate( | 244 SkAutoTUnref<const GrFragmentProcessor> fp(GrTextureDomainEffect::Cr
eate( |
| 245 srcTexture, | 245 srcTexture, |
| 246 matrix, | 246 matrix, |
| 247 domain, | 247 domain, |
| 248 GrTextureDomain::kDecal_Mode, | 248 GrTextureDomain::kDecal_Mode, |
| 249 GrTextureParams::kBilerp_FilterMode)); | 249 GrTextureParams::kBilerp_FilterMode)); |
| 250 paint.addColorFragmentProcessor(fp); | 250 paint.addColorFragmentProcessor(fp); |
| 251 srcRect.offset(-srcOffset); | 251 srcRect.offset(-srcOffset); |
| 252 srcOffset.set(0, 0); | 252 srcOffset.set(0, 0); |
| 253 } else { | 253 } else { |
| 254 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k
Bilerp_FilterMode); | 254 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k
Bilerp_FilterMode); |
| 255 paint.addColorTextureProcessor(srcTexture, matrix, params); | 255 paint.addColorTextureProcessor(srcTexture, matrix, params); |
| 256 } | 256 } |
| 257 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 257 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 258 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, | 258 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, |
| 259 i < scaleFactorY ? 0.5f : 1.0f); | 259 i < scaleFactorY ? 0.5f : 1.0f); |
| 260 | 260 |
| 261 SkAutoTUnref<GrDrawContext> dstDrawContext( | 261 sk_sp<GrDrawContext> dstDrawContext( |
| 262 context->drawContext(dstTexture->as
RenderTarget())); | 262 context->drawContext(sk_ref_sp(dstTexture->as
RenderTarget()))); |
| 263 if (!dstDrawContext) { | 263 if (!dstDrawContext) { |
| 264 return nullptr; | 264 return nullptr; |
| 265 } | 265 } |
| 266 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcR
ect); | 266 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcR
ect); |
| 267 | 267 |
| 268 srcDrawContext.swap(dstDrawContext); | 268 srcDrawContext.swap(dstDrawContext); |
| 269 srcRect = dstRect; | 269 srcRect = dstRect; |
| 270 srcTexture = dstTexture; | 270 srcTexture = dstTexture; |
| 271 SkTSwap(dstTexture, tempTexture); | 271 SkTSwap(dstTexture, tempTexture); |
| 272 localSrcBounds = srcRect; | 272 localSrcBounds = srcRect; |
| 273 } | 273 } |
| 274 | 274 |
| 275 SkSurfaceProps props(gammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag : 0, | 275 SkSurfaceProps props(gammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag : 0, |
| 276 SkSurfaceProps::kLegacyFontHost_InitType); | 276 SkSurfaceProps::kLegacyFontHost_InitType); |
| 277 | 277 |
| 278 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i
s faster to just | 278 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i
s faster to just |
| 279 // launch a single non separable kernel vs two launches | 279 // launch a single non separable kernel vs two launches |
| 280 srcRect = localDstBounds; | 280 srcRect = localDstBounds; |
| 281 if (sigmaX > 0.0f && sigmaY > 0.0f && | 281 if (sigmaX > 0.0f && sigmaY > 0.0f && |
| 282 (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) { | 282 (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) { |
| 283 // We shouldn't be scaling because this is a small size blur | 283 // We shouldn't be scaling because this is a small size blur |
| 284 SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); | 284 SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); |
| 285 | 285 |
| 286 SkAutoTUnref<GrDrawContext> dstDrawContext( | 286 sk_sp<GrDrawContext> dstDrawContext( |
| 287 context->drawContext(dstTexture->asRenderTarget(), &props)); | 287 context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()), &props
)); |
| 288 if (!dstDrawContext) { | 288 if (!dstDrawContext) { |
| 289 return nullptr; | 289 return nullptr; |
| 290 } | 290 } |
| 291 convolve_gaussian_2d(dstDrawContext, clip, srcRect, srcOffset, | 291 convolve_gaussian_2d(dstDrawContext.get(), clip, srcRect, srcOffset, |
| 292 srcTexture, radiusX, radiusY, sigmaX, sigmaY, srcBo
unds); | 292 srcTexture, radiusX, radiusY, sigmaX, sigmaY, srcBo
unds); |
| 293 | 293 |
| 294 srcDrawContext.swap(dstDrawContext); | 294 srcDrawContext.swap(dstDrawContext); |
| 295 srcRect.offsetTo(0, 0); | 295 srcRect.offsetTo(0, 0); |
| 296 srcTexture = dstTexture; | 296 srcTexture = dstTexture; |
| 297 SkTSwap(dstTexture, tempTexture); | 297 SkTSwap(dstTexture, tempTexture); |
| 298 | 298 |
| 299 } else { | 299 } else { |
| 300 scale_rect(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY); | 300 scale_rect(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY); |
| 301 srcRect.roundOut(&srcRect); | 301 srcRect.roundOut(&srcRect); |
| 302 const SkIRect srcIRect = srcRect.roundOut(); | 302 const SkIRect srcIRect = srcRect.roundOut(); |
| 303 if (sigmaX > 0.0f) { | 303 if (sigmaX > 0.0f) { |
| 304 if (scaleFactorX > 1) { | 304 if (scaleFactorX > 1) { |
| 305 // TODO: if we pass in the source draw context we don't need thi
s here | 305 // TODO: if we pass in the source draw context we don't need thi
s here |
| 306 if (!srcDrawContext) { | 306 if (!srcDrawContext) { |
| 307 srcDrawContext.reset(context->drawContext(srcTexture->asRend
erTarget())); | 307 srcDrawContext = context->drawContext(sk_ref_sp(srcTexture->
asRenderTarget())); |
| 308 if (!srcDrawContext) { | 308 if (!srcDrawContext) { |
| 309 return nullptr; | 309 return nullptr; |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 | 312 |
| 313 // Clear out a radius to the right of the srcRect to prevent the | 313 // Clear out a radius to the right of the srcRect to prevent the |
| 314 // X convolution from reading garbage. | 314 // X convolution from reading garbage. |
| 315 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, | 315 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, |
| 316 radiusX, srcIRect.height()); | 316 radiusX, srcIRect.height()); |
| 317 srcDrawContext->clear(&clearRect, 0x0, false); | 317 srcDrawContext->clear(&clearRect, 0x0, false); |
| 318 } | 318 } |
| 319 | 319 |
| 320 SkAutoTUnref<GrDrawContext> dstDrawContext( | 320 sk_sp<GrDrawContext> dstDrawContext( |
| 321 context->drawContext(dstTexture->asRenderTarget(), &props)); | 321 context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()), &p
rops)); |
| 322 if (!dstDrawContext) { | 322 if (!dstDrawContext) { |
| 323 return nullptr; | 323 return nullptr; |
| 324 } | 324 } |
| 325 convolve_gaussian(dstDrawContext, clip, srcRect, | 325 convolve_gaussian(dstDrawContext.get(), clip, srcRect, |
| 326 srcTexture, Gr1DKernelEffect::kX_Direction, radius
X, sigmaX, | 326 srcTexture, Gr1DKernelEffect::kX_Direction, radius
X, sigmaX, |
| 327 srcBounds, srcOffset); | 327 srcBounds, srcOffset); |
| 328 srcDrawContext.swap(dstDrawContext); | 328 srcDrawContext.swap(dstDrawContext); |
| 329 srcTexture = dstTexture; | 329 srcTexture = dstTexture; |
| 330 srcRect.offsetTo(0, 0); | 330 srcRect.offsetTo(0, 0); |
| 331 SkTSwap(dstTexture, tempTexture); | 331 SkTSwap(dstTexture, tempTexture); |
| 332 localSrcBounds = srcRect; | 332 localSrcBounds = srcRect; |
| 333 srcOffset.set(0, 0); | 333 srcOffset.set(0, 0); |
| 334 } | 334 } |
| 335 | 335 |
| 336 if (sigmaY > 0.0f) { | 336 if (sigmaY > 0.0f) { |
| 337 if (scaleFactorY > 1 || sigmaX > 0.0f) { | 337 if (scaleFactorY > 1 || sigmaX > 0.0f) { |
| 338 // TODO: if we pass in the source draw context we don't need thi
s here | 338 // TODO: if we pass in the source draw context we don't need thi
s here |
| 339 if (!srcDrawContext) { | 339 if (!srcDrawContext) { |
| 340 srcDrawContext.reset(context->drawContext(srcTexture->asRend
erTarget())); | 340 srcDrawContext = context->drawContext(sk_ref_sp(srcTexture->
asRenderTarget())); |
| 341 if (!srcDrawContext) { | 341 if (!srcDrawContext) { |
| 342 return nullptr; | 342 return nullptr; |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 | 345 |
| 346 // Clear out a radius below the srcRect to prevent the Y | 346 // Clear out a radius below the srcRect to prevent the Y |
| 347 // convolution from reading garbage. | 347 // convolution from reading garbage. |
| 348 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, | 348 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, |
| 349 srcIRect.width(), radiusY); | 349 srcIRect.width(), radiusY); |
| 350 srcDrawContext->clear(&clearRect, 0x0, false); | 350 srcDrawContext->clear(&clearRect, 0x0, false); |
| 351 } | 351 } |
| 352 | 352 |
| 353 SkAutoTUnref<GrDrawContext> dstDrawContext( | 353 sk_sp<GrDrawContext> dstDrawContext( |
| 354 context->drawContext(dstTexture->asRenderTarget(), &props)); | 354 context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()), &p
rops)); |
| 355 if (!dstDrawContext) { | 355 if (!dstDrawContext) { |
| 356 return nullptr; | 356 return nullptr; |
| 357 } | 357 } |
| 358 convolve_gaussian(dstDrawContext, clip, srcRect, | 358 convolve_gaussian(dstDrawContext.get(), clip, srcRect, |
| 359 srcTexture, Gr1DKernelEffect::kY_Direction, radius
Y, sigmaY, | 359 srcTexture, Gr1DKernelEffect::kY_Direction, radius
Y, sigmaY, |
| 360 srcBounds, srcOffset); | 360 srcBounds, srcOffset); |
| 361 | 361 |
| 362 srcDrawContext.swap(dstDrawContext); | 362 srcDrawContext.swap(dstDrawContext); |
| 363 srcTexture = dstTexture; | 363 srcTexture = dstTexture; |
| 364 srcRect.offsetTo(0, 0); | 364 srcRect.offsetTo(0, 0); |
| 365 SkTSwap(dstTexture, tempTexture); | 365 SkTSwap(dstTexture, tempTexture); |
| 366 } | 366 } |
| 367 } | 367 } |
| 368 const SkIRect srcIRect = srcRect.roundOut(); | 368 const SkIRect srcIRect = srcRect.roundOut(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 384 GrPaint paint; | 384 GrPaint paint; |
| 385 paint.setGammaCorrect(gammaCorrect); | 385 paint.setGammaCorrect(gammaCorrect); |
| 386 // FIXME: this should be mitchell, not bilinear. | 386 // FIXME: this should be mitchell, not bilinear. |
| 387 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile
rp_FilterMode); | 387 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile
rp_FilterMode); |
| 388 paint.addColorTextureProcessor(srcTexture, matrix, params); | 388 paint.addColorTextureProcessor(srcTexture, matrix, params); |
| 389 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 389 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 390 | 390 |
| 391 SkRect dstRect(srcRect); | 391 SkRect dstRect(srcRect); |
| 392 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); | 392 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); |
| 393 | 393 |
| 394 SkAutoTUnref<GrDrawContext> dstDrawContext( | 394 sk_sp<GrDrawContext> dstDrawContext( |
| 395 context->drawContext(dstTexture->asRenderTarget(
))); | 395 context->drawContext(sk_ref_sp(dstTexture->asRen
derTarget()))); |
| 396 if (!dstDrawContext) { | 396 if (!dstDrawContext) { |
| 397 return nullptr; | 397 return nullptr; |
| 398 } | 398 } |
| 399 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcR
ect); | 399 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcR
ect); |
| 400 | 400 |
| 401 srcDrawContext.swap(dstDrawContext); | 401 srcDrawContext.swap(dstDrawContext); |
| 402 srcRect = dstRect; | 402 srcRect = dstRect; |
| 403 srcTexture = dstTexture; | 403 srcTexture = dstTexture; |
| 404 SkTSwap(dstTexture, tempTexture); | 404 SkTSwap(dstTexture, tempTexture); |
| 405 } | 405 } |
| 406 | 406 |
| 407 return SkRef(srcTexture); | 407 return SkRef(srcTexture); |
| 408 } | 408 } |
| 409 #endif | 409 #endif |
| 410 | 410 |
| 411 } | 411 } |
| OLD | NEW |