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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 const SkIRect& dstRect, | 69 const SkIRect& dstRect, |
70 const SkIPoint& srcOffset, | 70 const SkIPoint& srcOffset, |
71 GrTexture* texture, | 71 GrTexture* texture, |
72 Gr1DKernelEffect::Direction direction, | 72 Gr1DKernelEffect::Direction direction, |
73 int radius, | 73 int radius, |
74 float sigma, | 74 float sigma, |
75 bool useBounds, | 75 bool useBounds, |
76 float bounds[2]) { | 76 float bounds[2]) { |
77 GrPaint paint; | 77 GrPaint paint; |
78 paint.setGammaCorrect(drawContext->isGammaCorrect()); | 78 paint.setGammaCorrect(drawContext->isGammaCorrect()); |
79 SkAutoTUnref<GrFragmentProcessor> conv(GrConvolutionEffect::CreateGaussian( | 79 sk_sp<GrFragmentProcessor> conv(GrConvolutionEffect::MakeGaussian( |
80 texture, direction, radius, sigma, useBounds, bounds)); | 80 texture, direction, radius, sigma, useBounds, bounds)); |
81 paint.addColorFragmentProcessor(conv); | 81 paint.addColorFragmentProcessor(std::move(conv)); |
82 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 82 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
83 SkMatrix localMatrix = SkMatrix::MakeTrans(-SkIntToScalar(srcOffset.x()), | 83 SkMatrix localMatrix = SkMatrix::MakeTrans(-SkIntToScalar(srcOffset.x()), |
84 -SkIntToScalar(srcOffset.y())); | 84 -SkIntToScalar(srcOffset.y())); |
85 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), | 85 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), |
86 SkRect::Make(dstRect), localMatrix); | 86 SkRect::Make(dstRect), localMatrix); |
87 } | 87 } |
88 | 88 |
89 static void convolve_gaussian_2d(GrDrawContext* drawContext, | 89 static void convolve_gaussian_2d(GrDrawContext* drawContext, |
90 const GrClip& clip, | 90 const GrClip& clip, |
91 const SkIRect& dstRect, | 91 const SkIRect& dstRect, |
92 const SkIPoint& srcOffset, | 92 const SkIPoint& srcOffset, |
93 GrTexture* texture, | 93 GrTexture* texture, |
94 int radiusX, | 94 int radiusX, |
95 int radiusY, | 95 int radiusY, |
96 SkScalar sigmaX, | 96 SkScalar sigmaX, |
97 SkScalar sigmaY, | 97 SkScalar sigmaY, |
98 const SkIRect* srcBounds) { | 98 const SkIRect* srcBounds) { |
99 SkMatrix localMatrix = SkMatrix::MakeTrans(-SkIntToScalar(srcOffset.x()), | 99 SkMatrix localMatrix = SkMatrix::MakeTrans(-SkIntToScalar(srcOffset.x()), |
100 -SkIntToScalar(srcOffset.y())); | 100 -SkIntToScalar(srcOffset.y())); |
101 SkISize size = SkISize::Make(2 * radiusX + 1, 2 * radiusY + 1); | 101 SkISize size = SkISize::Make(2 * radiusX + 1, 2 * radiusY + 1); |
102 SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY); | 102 SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY); |
103 GrPaint paint; | 103 GrPaint paint; |
104 paint.setGammaCorrect(drawContext->isGammaCorrect()); | 104 paint.setGammaCorrect(drawContext->isGammaCorrect()); |
105 SkIRect bounds = srcBounds ? *srcBounds : SkIRect::EmptyIRect(); | 105 SkIRect bounds = srcBounds ? *srcBounds : SkIRect::EmptyIRect(); |
106 | 106 |
107 SkAutoTUnref<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::CreateGaus
sian( | 107 sk_sp<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::MakeGaussian( |
108 texture, bounds, size, 1.0, 0.0, kernelOffset, | 108 texture, bounds, size, 1.0, 0.0, kernelOffset, |
109 srcBounds ? GrTextureDomain::kDecal_Mode : GrTextureDomain::kIgnore_
Mode, | 109 srcBounds ? GrTextureDomain::kDecal_Mode : GrTextureDomain::kIgnore_
Mode, |
110 true, sigmaX, sigmaY)); | 110 true, sigmaX, sigmaY)); |
111 paint.addColorFragmentProcessor(conv); | 111 paint.addColorFragmentProcessor(std::move(conv)); |
112 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 112 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
113 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), | 113 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), |
114 SkRect::Make(dstRect), localMatrix); | 114 SkRect::Make(dstRect), localMatrix); |
115 } | 115 } |
116 | 116 |
117 static void convolve_gaussian(GrDrawContext* drawContext, | 117 static void convolve_gaussian(GrDrawContext* drawContext, |
118 const GrClip& clip, | 118 const GrClip& clip, |
119 const SkIRect& srcRect, | 119 const SkIRect& srcRect, |
120 GrTexture* texture, | 120 GrTexture* texture, |
121 Gr1DKernelEffect::Direction direction, | 121 Gr1DKernelEffect::Direction direction, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 GrPaint paint; | 266 GrPaint paint; |
267 paint.setGammaCorrect(gammaCorrect); | 267 paint.setGammaCorrect(gammaCorrect); |
268 SkMatrix matrix; | 268 SkMatrix matrix; |
269 matrix.setIDiv(srcTexture->width(), srcTexture->height()); | 269 matrix.setIDiv(srcTexture->width(), srcTexture->height()); |
270 SkIRect dstRect(srcRect); | 270 SkIRect dstRect(srcRect); |
271 if (srcBounds && i == 1) { | 271 if (srcBounds && i == 1) { |
272 SkRect domain; | 272 SkRect domain; |
273 matrix.mapRect(&domain, SkRect::Make(*srcBounds)); | 273 matrix.mapRect(&domain, SkRect::Make(*srcBounds)); |
274 domain.inset((i < scaleFactorX) ? SK_ScalarHalf / srcTexture->width(
) : 0.0f, | 274 domain.inset((i < scaleFactorX) ? SK_ScalarHalf / srcTexture->width(
) : 0.0f, |
275 (i < scaleFactorY) ? SK_ScalarHalf / srcTexture->height
() : 0.0f); | 275 (i < scaleFactorY) ? SK_ScalarHalf / srcTexture->height
() : 0.0f); |
276 sk_sp<const GrFragmentProcessor> fp(GrTextureDomainEffect::Create( | 276 sk_sp<GrFragmentProcessor> fp(GrTextureDomainEffect::Make( |
277 srcTexture.get(), | 277 srcTexture.get(), |
278 matrix, | 278 matrix, |
279 domain, | 279 domain, |
280 GrTextureDomain::kDecal_
Mode, | 280 GrTextureDomain::kDecal_
Mode, |
281 GrTextureParams::kBilerp
_FilterMode)); | 281 GrTextureParams::kBilerp
_FilterMode)); |
282 paint.addColorFragmentProcessor(fp.get()); | 282 paint.addColorFragmentProcessor(std::move(fp)); |
283 srcRect.offset(-srcOffset); | 283 srcRect.offset(-srcOffset); |
284 srcOffset.set(0, 0); | 284 srcOffset.set(0, 0); |
285 } else { | 285 } else { |
286 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k
Bilerp_FilterMode); | 286 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k
Bilerp_FilterMode); |
287 paint.addColorTextureProcessor(srcTexture.get(), matrix, params); | 287 paint.addColorTextureProcessor(srcTexture.get(), matrix, params); |
288 } | 288 } |
289 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 289 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
290 shrink_irect_by_2(&dstRect, i < scaleFactorX, i < scaleFactorY); | 290 shrink_irect_by_2(&dstRect, i < scaleFactorX, i < scaleFactorY); |
291 | 291 |
292 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), | 292 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 dstDrawContext.swap(tmpDrawContext); | 375 dstDrawContext.swap(tmpDrawContext); |
376 } | 376 } |
377 | 377 |
378 return srcDrawContext; | 378 return srcDrawContext; |
379 } | 379 } |
380 | 380 |
381 } | 381 } |
382 | 382 |
383 #endif | 383 #endif |
384 | 384 |
OLD | NEW |