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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 const GrClip& clip, | 49 const GrClip& clip, |
50 const SkRect& dstRect, | 50 const SkRect& dstRect, |
51 const SkPoint& srcOffset, | 51 const SkPoint& srcOffset, |
52 GrTexture* texture, | 52 GrTexture* texture, |
53 Gr1DKernelEffect::Direction direction, | 53 Gr1DKernelEffect::Direction direction, |
54 int radius, | 54 int radius, |
55 float sigma, | 55 float sigma, |
56 bool useBounds, | 56 bool useBounds, |
57 float bounds[2]) { | 57 float bounds[2]) { |
58 GrPaint paint; | 58 GrPaint paint; |
59 paint.setAllowSRGBInputs(drawContext->allowSRGBInputs()); | 59 paint.setGammaCorrect(drawContext->isGammaCorrect()); |
60 SkAutoTUnref<GrFragmentProcessor> conv(GrConvolutionEffect::CreateGaussian( | 60 SkAutoTUnref<GrFragmentProcessor> conv(GrConvolutionEffect::CreateGaussian( |
61 texture, direction, radius, sigma, useBounds, bounds)); | 61 texture, direction, radius, sigma, useBounds, bounds)); |
62 paint.addColorFragmentProcessor(conv); | 62 paint.addColorFragmentProcessor(conv); |
63 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 63 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
64 SkMatrix localMatrix = SkMatrix::MakeTrans(-srcOffset.x(), -srcOffset.y()); | 64 SkMatrix localMatrix = SkMatrix::MakeTrans(-srcOffset.x(), -srcOffset.y()); |
65 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), dstRect, lo
calMatrix); | 65 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), dstRect, lo
calMatrix); |
66 } | 66 } |
67 | 67 |
68 static void convolve_gaussian_2d(GrDrawContext* drawContext, | 68 static void convolve_gaussian_2d(GrDrawContext* drawContext, |
69 const GrClip& clip, | 69 const GrClip& clip, |
70 const SkRect& dstRect, | 70 const SkRect& dstRect, |
71 const SkPoint& srcOffset, | 71 const SkPoint& srcOffset, |
72 GrTexture* texture, | 72 GrTexture* texture, |
73 int radiusX, | 73 int radiusX, |
74 int radiusY, | 74 int radiusY, |
75 SkScalar sigmaX, | 75 SkScalar sigmaX, |
76 SkScalar sigmaY, | 76 SkScalar sigmaY, |
77 const SkRect* srcBounds) { | 77 const SkRect* srcBounds) { |
78 SkMatrix localMatrix = SkMatrix::MakeTrans(-srcOffset.x(), -srcOffset.y()); | 78 SkMatrix localMatrix = SkMatrix::MakeTrans(-srcOffset.x(), -srcOffset.y()); |
79 SkISize size = SkISize::Make(2 * radiusX + 1, 2 * radiusY + 1); | 79 SkISize size = SkISize::Make(2 * radiusX + 1, 2 * radiusY + 1); |
80 SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY); | 80 SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY); |
81 GrPaint paint; | 81 GrPaint paint; |
82 paint.setAllowSRGBInputs(drawContext->allowSRGBInputs()); | 82 paint.setGammaCorrect(drawContext->isGammaCorrect()); |
83 SkIRect bounds; | 83 SkIRect bounds; |
84 if (srcBounds) { | 84 if (srcBounds) { |
85 srcBounds->roundOut(&bounds); | 85 srcBounds->roundOut(&bounds); |
86 } else { | 86 } else { |
87 bounds.setEmpty(); | 87 bounds.setEmpty(); |
88 } | 88 } |
89 | 89 |
90 SkAutoTUnref<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::CreateGaus
sian( | 90 SkAutoTUnref<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::CreateGaus
sian( |
91 texture, bounds, size, 1.0, 0.0, kernelOffset, | 91 texture, bounds, size, 1.0, 0.0, kernelOffset, |
92 srcBounds ? GrTextureDomain::kDecal_Mode : GrTextureDomain::kIgnore_
Mode, | 92 srcBounds ? GrTextureDomain::kDecal_Mode : GrTextureDomain::kIgnore_
Mode, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 convolve_gaussian_1d(drawContext, clip, rightRect, srcOffset, texture, | 159 convolve_gaussian_1d(drawContext, clip, rightRect, srcOffset, texture, |
160 direction, radius, sigma, true, bounds); | 160 direction, radius, sigma, true, bounds); |
161 convolve_gaussian_1d(drawContext, clip, midRect, srcOffset, texture, | 161 convolve_gaussian_1d(drawContext, clip, midRect, srcOffset, texture, |
162 direction, radius, sigma, false, bounds); | 162 direction, radius, sigma, false, bounds); |
163 } | 163 } |
164 } | 164 } |
165 | 165 |
166 GrTexture* GaussianBlur(GrContext* context, | 166 GrTexture* GaussianBlur(GrContext* context, |
167 GrTexture* srcTexture, | 167 GrTexture* srcTexture, |
168 bool canClobberSrc, | 168 bool canClobberSrc, |
169 bool allowSRGBInputs, | 169 bool gammaCorrect, |
170 const SkRect& dstBounds, | 170 const SkRect& dstBounds, |
171 const SkRect* srcBounds, | 171 const SkRect* srcBounds, |
172 float sigmaX, | 172 float sigmaX, |
173 float sigmaY) { | 173 float sigmaY) { |
174 SkASSERT(context); | 174 SkASSERT(context); |
175 SkIRect clearRect; | 175 SkIRect clearRect; |
176 int scaleFactorX, radiusX; | 176 int scaleFactorX, radiusX; |
177 int scaleFactorY, radiusY; | 177 int scaleFactorY, radiusY; |
178 int maxTextureSize = context->caps()->maxTextureSize(); | 178 int maxTextureSize = context->caps()->maxTextureSize(); |
179 sigmaX = adjust_sigma(sigmaX, maxTextureSize, &scaleFactorX, &radiusX); | 179 sigmaX = adjust_sigma(sigmaX, maxTextureSize, &scaleFactorX, &radiusX); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SkAutoTUnref<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.setAllowSRGBInputs(allowSRGBInputs); | 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, |
(...skipping 19 matching lines...) Expand all Loading... |
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(allowSRGBInputs ? SkSurfaceProps::kAllowSRGBInputs_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 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, | 375 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, |
376 srcIRect.width() + 1, 1); | 376 srcIRect.width() + 1, 1); |
377 srcDrawContext->clear(&clearRect, 0x0, false); | 377 srcDrawContext->clear(&clearRect, 0x0, false); |
378 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, | 378 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, |
379 1, srcIRect.height()); | 379 1, srcIRect.height()); |
380 srcDrawContext->clear(&clearRect, 0x0, false); | 380 srcDrawContext->clear(&clearRect, 0x0, false); |
381 SkMatrix matrix; | 381 SkMatrix matrix; |
382 matrix.setIDiv(srcTexture->width(), srcTexture->height()); | 382 matrix.setIDiv(srcTexture->width(), srcTexture->height()); |
383 | 383 |
384 GrPaint paint; | 384 GrPaint paint; |
385 paint.setAllowSRGBInputs(allowSRGBInputs); | 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 SkAutoTUnref<GrDrawContext> dstDrawContext( |
395 context->drawContext(dstTexture->asRenderTarget(
))); | 395 context->drawContext(dstTexture->asRenderTarget(
))); |
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 |