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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SkAutoTUnref<GrFragmentProcessor> conv(GrConvolutionEffect::CreateGaussian( | 59 SkAutoTUnref<GrFragmentProcessor> conv(GrConvolutionEffect::CreateGaussian( |
60 texture, direction, radius, sigma, useBounds, bounds)); | 60 texture, direction, radius, sigma, useBounds, bounds)); |
61 paint.addColorFragmentProcessor(conv); | 61 paint.addColorFragmentProcessor(conv); |
| 62 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
62 SkMatrix localMatrix = SkMatrix::MakeTrans(srcOffset.x(), srcOffset.y()); | 63 SkMatrix localMatrix = SkMatrix::MakeTrans(srcOffset.x(), srcOffset.y()); |
63 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), dstRect, lo
calMatrix); | 64 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), dstRect, lo
calMatrix); |
64 } | 65 } |
65 | 66 |
66 static void convolve_gaussian_2d(GrDrawContext* drawContext, | 67 static void convolve_gaussian_2d(GrDrawContext* drawContext, |
67 const GrClip& clip, | 68 const GrClip& clip, |
68 const SkRect& srcRect, | 69 const SkRect& srcRect, |
69 GrTexture* texture, | 70 GrTexture* texture, |
70 int radiusX, | 71 int radiusX, |
71 int radiusY, | 72 int radiusY, |
(...skipping 10 matching lines...) Expand all Loading... |
82 srcBounds->roundOut(&bounds); | 83 srcBounds->roundOut(&bounds); |
83 } else { | 84 } else { |
84 bounds.setEmpty(); | 85 bounds.setEmpty(); |
85 } | 86 } |
86 | 87 |
87 SkAutoTUnref<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::CreateGaus
sian( | 88 SkAutoTUnref<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::CreateGaus
sian( |
88 texture, bounds, size, 1.0, 0.0, kernelOffset, | 89 texture, bounds, size, 1.0, 0.0, kernelOffset, |
89 srcBounds ? GrTextureDomain::kDecal_Mode : GrTextureDomain::kIgnore_
Mode, | 90 srcBounds ? GrTextureDomain::kDecal_Mode : GrTextureDomain::kIgnore_
Mode, |
90 true, sigmaX, sigmaY)); | 91 true, sigmaX, sigmaY)); |
91 paint.addColorFragmentProcessor(conv); | 92 paint.addColorFragmentProcessor(conv); |
| 93 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
92 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), dstRect, lo
calMatrix); | 94 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), dstRect, lo
calMatrix); |
93 } | 95 } |
94 | 96 |
95 static void convolve_gaussian(GrDrawContext* drawContext, | 97 static void convolve_gaussian(GrDrawContext* drawContext, |
96 const GrClip& clip, | 98 const GrClip& clip, |
97 const SkRect& srcRect, | 99 const SkRect& srcRect, |
98 GrTexture* texture, | 100 GrTexture* texture, |
99 Gr1DKernelEffect::Direction direction, | 101 Gr1DKernelEffect::Direction direction, |
100 int radius, | 102 int radius, |
101 float sigma, | 103 float sigma, |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 domain, | 242 domain, |
241 GrTextureDomain::kDecal_Mode, | 243 GrTextureDomain::kDecal_Mode, |
242 GrTextureParams::kBilerp_FilterMode)); | 244 GrTextureParams::kBilerp_FilterMode)); |
243 paint.addColorFragmentProcessor(fp); | 245 paint.addColorFragmentProcessor(fp); |
244 srcRect.offset(-srcOffset); | 246 srcRect.offset(-srcOffset); |
245 srcOffset.set(0, 0); | 247 srcOffset.set(0, 0); |
246 } else { | 248 } else { |
247 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k
Bilerp_FilterMode); | 249 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k
Bilerp_FilterMode); |
248 paint.addColorTextureProcessor(srcTexture, matrix, params); | 250 paint.addColorTextureProcessor(srcTexture, matrix, params); |
249 } | 251 } |
| 252 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
250 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, | 253 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, |
251 i < scaleFactorY ? 0.5f : 1.0f); | 254 i < scaleFactorY ? 0.5f : 1.0f); |
252 | 255 |
253 SkAutoTUnref<GrDrawContext> dstDrawContext( | 256 SkAutoTUnref<GrDrawContext> dstDrawContext( |
254 context->drawContext(dstTexture->as
RenderTarget())); | 257 context->drawContext(dstTexture->as
RenderTarget())); |
255 if (!dstDrawContext) { | 258 if (!dstDrawContext) { |
256 return nullptr; | 259 return nullptr; |
257 } | 260 } |
258 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcR
ect); | 261 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcR
ect); |
259 | 262 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, | 370 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, |
368 1, srcIRect.height()); | 371 1, srcIRect.height()); |
369 srcDrawContext->clear(&clearRect, 0x0, false); | 372 srcDrawContext->clear(&clearRect, 0x0, false); |
370 SkMatrix matrix; | 373 SkMatrix matrix; |
371 matrix.setIDiv(srcTexture->width(), srcTexture->height()); | 374 matrix.setIDiv(srcTexture->width(), srcTexture->height()); |
372 | 375 |
373 GrPaint paint; | 376 GrPaint paint; |
374 // FIXME: this should be mitchell, not bilinear. | 377 // FIXME: this should be mitchell, not bilinear. |
375 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile
rp_FilterMode); | 378 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile
rp_FilterMode); |
376 paint.addColorTextureProcessor(srcTexture, matrix, params); | 379 paint.addColorTextureProcessor(srcTexture, matrix, params); |
| 380 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
377 | 381 |
378 SkRect dstRect(srcRect); | 382 SkRect dstRect(srcRect); |
379 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); | 383 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); |
380 | 384 |
381 SkAutoTUnref<GrDrawContext> dstDrawContext( | 385 SkAutoTUnref<GrDrawContext> dstDrawContext( |
382 context->drawContext(dstTexture->asRenderTarget(
))); | 386 context->drawContext(dstTexture->asRenderTarget(
))); |
383 if (!dstDrawContext) { | 387 if (!dstDrawContext) { |
384 return nullptr; | 388 return nullptr; |
385 } | 389 } |
386 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcR
ect); | 390 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcR
ect); |
387 | 391 |
388 srcDrawContext.swap(dstDrawContext); | 392 srcDrawContext.swap(dstDrawContext); |
389 srcRect = dstRect; | 393 srcRect = dstRect; |
390 srcTexture = dstTexture; | 394 srcTexture = dstTexture; |
391 SkTSwap(dstTexture, tempTexture); | 395 SkTSwap(dstTexture, tempTexture); |
392 } | 396 } |
393 | 397 |
394 return SkRef(srcTexture); | 398 return SkRef(srcTexture); |
395 } | 399 } |
396 #endif | 400 #endif |
397 | 401 |
398 } | 402 } |
OLD | NEW |