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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SkMatrix localMatrix = SkMatrix::MakeTrans(srcOffset.x(), srcOffset.y()); | 62 SkMatrix localMatrix = SkMatrix::MakeTrans(srcOffset.x(), srcOffset.y()); |
63 drawContext->drawNonAARectWithLocalMatrix(clip, paint, SkMatrix::I(), dstRec
t, localMatrix); | 63 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), dstRect, lo
calMatrix); |
64 } | 64 } |
65 | 65 |
66 static void convolve_gaussian_2d(GrDrawContext* drawContext, | 66 static void convolve_gaussian_2d(GrDrawContext* drawContext, |
67 const GrClip& clip, | 67 const GrClip& clip, |
68 const SkRect& srcRect, | 68 const SkRect& srcRect, |
69 GrTexture* texture, | 69 GrTexture* texture, |
70 int radiusX, | 70 int radiusX, |
71 int radiusY, | 71 int radiusY, |
72 SkScalar sigmaX, | 72 SkScalar sigmaX, |
73 SkScalar sigmaY, | 73 SkScalar sigmaY, |
74 bool useBounds, | 74 bool useBounds, |
75 SkIRect bounds) { | 75 SkIRect bounds) { |
76 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | 76 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
77 SkMatrix localMatrix = SkMatrix::MakeTrans(srcRect.x(), srcRect.y()); | 77 SkMatrix localMatrix = SkMatrix::MakeTrans(srcRect.x(), srcRect.y()); |
78 SkISize size = SkISize::Make(2 * radiusX + 1, 2 * radiusY + 1); | 78 SkISize size = SkISize::Make(2 * radiusX + 1, 2 * radiusY + 1); |
79 SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY); | 79 SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY); |
80 GrPaint paint; | 80 GrPaint paint; |
81 SkAutoTUnref<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::CreateGaus
sian( | 81 SkAutoTUnref<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::CreateGaus
sian( |
82 texture, bounds, size, 1.0, 0.0, kernelOffset, | 82 texture, bounds, size, 1.0, 0.0, kernelOffset, |
83 useBounds ? GrTextureDomain::kClamp_Mode : GrTextureDomain::kIgnore_
Mode, | 83 useBounds ? GrTextureDomain::kClamp_Mode : GrTextureDomain::kIgnore_
Mode, |
84 true, sigmaX, sigmaY)); | 84 true, sigmaX, sigmaY)); |
85 paint.addColorFragmentProcessor(conv); | 85 paint.addColorFragmentProcessor(conv); |
86 drawContext->drawNonAARectWithLocalMatrix(clip, paint, SkMatrix::I(), dstRec
t, localMatrix); | 86 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), dstRect, lo
calMatrix); |
87 } | 87 } |
88 | 88 |
89 static void convolve_gaussian(GrDrawContext* drawContext, | 89 static void convolve_gaussian(GrDrawContext* drawContext, |
90 const GrClip& clip, | 90 const GrClip& clip, |
91 const SkRect& srcRect, | 91 const SkRect& srcRect, |
92 GrTexture* texture, | 92 GrTexture* texture, |
93 Gr1DKernelEffect::Direction direction, | 93 Gr1DKernelEffect::Direction direction, |
94 int radius, | 94 int radius, |
95 float sigma, | 95 float sigma, |
96 bool cropToSrcRect) { | 96 bool cropToSrcRect) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 paint.addColorTextureProcessor(srcTexture, matrix, params); | 215 paint.addColorTextureProcessor(srcTexture, matrix, params); |
216 } | 216 } |
217 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, | 217 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, |
218 i < scaleFactorY ? 0.5f : 1.0f); | 218 i < scaleFactorY ? 0.5f : 1.0f); |
219 | 219 |
220 SkAutoTUnref<GrDrawContext> dstDrawContext( | 220 SkAutoTUnref<GrDrawContext> dstDrawContext( |
221 context->drawContext(dstTexture->as
RenderTarget())); | 221 context->drawContext(dstTexture->as
RenderTarget())); |
222 if (!dstDrawContext) { | 222 if (!dstDrawContext) { |
223 return nullptr; | 223 return nullptr; |
224 } | 224 } |
225 dstDrawContext->drawNonAARectToRect(clip, paint, SkMatrix::I(), dstRect,
srcRect); | 225 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcR
ect); |
226 | 226 |
227 srcDrawContext.swap(dstDrawContext); | 227 srcDrawContext.swap(dstDrawContext); |
228 srcRect = dstRect; | 228 srcRect = dstRect; |
229 srcTexture = dstTexture; | 229 srcTexture = dstTexture; |
230 SkTSwap(dstTexture, tempTexture); | 230 SkTSwap(dstTexture, tempTexture); |
231 } | 231 } |
232 | 232 |
233 const SkIRect srcIRect = srcRect.roundOut(); | 233 const SkIRect srcIRect = srcRect.roundOut(); |
234 | 234 |
235 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i
s faster to just | 235 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i
s faster to just |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 paint.addColorTextureProcessor(srcTexture, matrix, params); | 338 paint.addColorTextureProcessor(srcTexture, matrix, params); |
339 | 339 |
340 SkRect dstRect(srcRect); | 340 SkRect dstRect(srcRect); |
341 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); | 341 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); |
342 | 342 |
343 SkAutoTUnref<GrDrawContext> dstDrawContext( | 343 SkAutoTUnref<GrDrawContext> dstDrawContext( |
344 context->drawContext(dstTexture->asRenderTarget(
))); | 344 context->drawContext(dstTexture->asRenderTarget(
))); |
345 if (!dstDrawContext) { | 345 if (!dstDrawContext) { |
346 return nullptr; | 346 return nullptr; |
347 } | 347 } |
348 dstDrawContext->drawNonAARectToRect(clip, paint, SkMatrix::I(), dstRect,
srcRect); | 348 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcR
ect); |
349 | 349 |
350 srcDrawContext.swap(dstDrawContext); | 350 srcDrawContext.swap(dstDrawContext); |
351 srcRect = dstRect; | 351 srcRect = dstRect; |
352 srcTexture = dstTexture; | 352 srcTexture = dstTexture; |
353 SkTSwap(dstTexture, tempTexture); | 353 SkTSwap(dstTexture, tempTexture); |
354 } | 354 } |
355 | 355 |
356 return SkRef(srcTexture); | 356 return SkRef(srcTexture); |
357 } | 357 } |
358 #endif | 358 #endif |
359 | 359 |
360 } | 360 } |
OLD | NEW |