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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 Gr1DKernelEffect::Direction direction, | 73 Gr1DKernelEffect::Direction direction, |
74 int radius, | 74 int radius, |
75 float sigma, | 75 float sigma, |
76 bool useBounds, | 76 bool useBounds, |
77 float bounds[2]) { | 77 float bounds[2]) { |
78 GrPaint paint; | 78 GrPaint paint; |
79 paint.setGammaCorrect(drawContext->isGammaCorrect()); | 79 paint.setGammaCorrect(drawContext->isGammaCorrect()); |
80 sk_sp<GrFragmentProcessor> conv(GrConvolutionEffect::MakeGaussian( | 80 sk_sp<GrFragmentProcessor> conv(GrConvolutionEffect::MakeGaussian( |
81 texture, direction, radius, sigma, useBounds, bounds)); | 81 texture, direction, radius, sigma, useBounds, bounds)); |
82 paint.addColorFragmentProcessor(std::move(conv)); | 82 paint.addColorFragmentProcessor(std::move(conv)); |
83 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 83 paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
84 SkMatrix localMatrix = SkMatrix::MakeTrans(-SkIntToScalar(srcOffset.x()), | 84 SkMatrix localMatrix = SkMatrix::MakeTrans(-SkIntToScalar(srcOffset.x()), |
85 -SkIntToScalar(srcOffset.y())); | 85 -SkIntToScalar(srcOffset.y())); |
86 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), | 86 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), |
87 SkRect::Make(dstRect), localMatrix); | 87 SkRect::Make(dstRect), localMatrix); |
88 } | 88 } |
89 | 89 |
90 static void convolve_gaussian_2d(GrDrawContext* drawContext, | 90 static void convolve_gaussian_2d(GrDrawContext* drawContext, |
91 const GrClip& clip, | 91 const GrClip& clip, |
92 const SkIRect& dstRect, | 92 const SkIRect& dstRect, |
93 const SkIPoint& srcOffset, | 93 const SkIPoint& srcOffset, |
94 GrTexture* texture, | 94 GrTexture* texture, |
95 int radiusX, | 95 int radiusX, |
96 int radiusY, | 96 int radiusY, |
97 SkScalar sigmaX, | 97 SkScalar sigmaX, |
98 SkScalar sigmaY, | 98 SkScalar sigmaY, |
99 const SkIRect* srcBounds) { | 99 const SkIRect* srcBounds) { |
100 SkMatrix localMatrix = SkMatrix::MakeTrans(-SkIntToScalar(srcOffset.x()), | 100 SkMatrix localMatrix = SkMatrix::MakeTrans(-SkIntToScalar(srcOffset.x()), |
101 -SkIntToScalar(srcOffset.y())); | 101 -SkIntToScalar(srcOffset.y())); |
102 SkISize size = SkISize::Make(2 * radiusX + 1, 2 * radiusY + 1); | 102 SkISize size = SkISize::Make(2 * radiusX + 1, 2 * radiusY + 1); |
103 SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY); | 103 SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY); |
104 GrPaint paint; | 104 GrPaint paint; |
105 paint.setGammaCorrect(drawContext->isGammaCorrect()); | 105 paint.setGammaCorrect(drawContext->isGammaCorrect()); |
106 SkIRect bounds = srcBounds ? *srcBounds : SkIRect::EmptyIRect(); | 106 SkIRect bounds = srcBounds ? *srcBounds : SkIRect::EmptyIRect(); |
107 | 107 |
108 sk_sp<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::MakeGaussian( | 108 sk_sp<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::MakeGaussian( |
109 texture, bounds, size, 1.0, 0.0, kernelOffset, | 109 texture, bounds, size, 1.0, 0.0, kernelOffset, |
110 srcBounds ? GrTextureDomain::kDecal_Mode : GrTextureDomain::kIgnore_
Mode, | 110 srcBounds ? GrTextureDomain::kDecal_Mode : GrTextureDomain::kIgnore_
Mode, |
111 true, sigmaX, sigmaY)); | 111 true, sigmaX, sigmaY)); |
112 paint.addColorFragmentProcessor(std::move(conv)); | 112 paint.addColorFragmentProcessor(std::move(conv)); |
113 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 113 paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
114 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), | 114 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), |
115 SkRect::Make(dstRect), localMatrix); | 115 SkRect::Make(dstRect), localMatrix); |
116 } | 116 } |
117 | 117 |
118 static void convolve_gaussian(GrDrawContext* drawContext, | 118 static void convolve_gaussian(GrDrawContext* drawContext, |
119 const GrClip& clip, | 119 const GrClip& clip, |
120 const SkIRect& srcRect, | 120 const SkIRect& srcRect, |
121 GrTexture* texture, | 121 GrTexture* texture, |
122 Gr1DKernelEffect::Direction direction, | 122 Gr1DKernelEffect::Direction direction, |
123 int radius, | 123 int radius, |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 domain, | 278 domain, |
279 GrTextureDomain::kDecal_
Mode, | 279 GrTextureDomain::kDecal_
Mode, |
280 GrTextureParams::kBilerp
_FilterMode)); | 280 GrTextureParams::kBilerp
_FilterMode)); |
281 paint.addColorFragmentProcessor(std::move(fp)); | 281 paint.addColorFragmentProcessor(std::move(fp)); |
282 srcRect.offset(-srcOffset); | 282 srcRect.offset(-srcOffset); |
283 srcOffset.set(0, 0); | 283 srcOffset.set(0, 0); |
284 } else { | 284 } else { |
285 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k
Bilerp_FilterMode); | 285 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k
Bilerp_FilterMode); |
286 paint.addColorTextureProcessor(srcTexture.get(), nullptr, matrix, pa
rams); | 286 paint.addColorTextureProcessor(srcTexture.get(), nullptr, matrix, pa
rams); |
287 } | 287 } |
288 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 288 paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
289 shrink_irect_by_2(&dstRect, i < scaleFactorX, i < scaleFactorY); | 289 shrink_irect_by_2(&dstRect, i < scaleFactorX, i < scaleFactorY); |
290 | 290 |
291 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), | 291 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), |
292 SkRect::Make(dstRect), SkRect::Make(srcRe
ct)); | 292 SkRect::Make(dstRect), SkRect::Make(srcRe
ct)); |
293 | 293 |
294 srcDrawContext = dstDrawContext; | 294 srcDrawContext = dstDrawContext; |
295 srcRect = dstRect; | 295 srcRect = dstRect; |
296 srcTexture = srcDrawContext->asTexture(); | 296 srcTexture = srcDrawContext->asTexture(); |
297 dstDrawContext.swap(tmpDrawContext); | 297 dstDrawContext.swap(tmpDrawContext); |
298 localSrcBounds = srcRect; | 298 localSrcBounds = srcRect; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 354 |
355 SkMatrix matrix; | 355 SkMatrix matrix; |
356 matrix.setIDiv(srcDrawContext->width(), srcDrawContext->height()); | 356 matrix.setIDiv(srcDrawContext->width(), srcDrawContext->height()); |
357 | 357 |
358 GrPaint paint; | 358 GrPaint paint; |
359 paint.setGammaCorrect(dstDrawContext->isGammaCorrect()); | 359 paint.setGammaCorrect(dstDrawContext->isGammaCorrect()); |
360 // FIXME: this should be mitchell, not bilinear. | 360 // FIXME: this should be mitchell, not bilinear. |
361 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile
rp_FilterMode); | 361 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile
rp_FilterMode); |
362 sk_sp<GrTexture> tex(srcDrawContext->asTexture()); | 362 sk_sp<GrTexture> tex(srcDrawContext->asTexture()); |
363 paint.addColorTextureProcessor(tex.get(), nullptr, matrix, params); | 363 paint.addColorTextureProcessor(tex.get(), nullptr, matrix, params); |
364 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 364 paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
365 | 365 |
366 SkIRect dstRect(srcRect); | 366 SkIRect dstRect(srcRect); |
367 scale_irect(&dstRect, scaleFactorX, scaleFactorY); | 367 scale_irect(&dstRect, scaleFactorX, scaleFactorY); |
368 | 368 |
369 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), | 369 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), |
370 SkRect::Make(dstRect), SkRect::Make(srcRe
ct)); | 370 SkRect::Make(dstRect), SkRect::Make(srcRe
ct)); |
371 | 371 |
372 srcDrawContext = dstDrawContext; | 372 srcDrawContext = dstDrawContext; |
373 srcRect = dstRect; | 373 srcRect = dstRect; |
374 dstDrawContext.swap(tmpDrawContext); | 374 dstDrawContext.swap(tmpDrawContext); |
375 } | 375 } |
376 | 376 |
377 return srcDrawContext; | 377 return srcDrawContext; |
378 } | 378 } |
379 | 379 |
380 } | 380 } |
381 | 381 |
382 #endif | 382 #endif |
383 | 383 |
OLD | NEW |