| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 179 } |
| 180 | 180 |
| 181 namespace SkGpuBlurUtils { | 181 namespace SkGpuBlurUtils { |
| 182 | 182 |
| 183 sk_sp<GrDrawContext> GaussianBlur(GrContext* context, | 183 sk_sp<GrDrawContext> GaussianBlur(GrContext* context, |
| 184 GrTexture* origSrc, | 184 GrTexture* origSrc, |
| 185 sk_sp<SkColorSpace> colorSpace, | 185 sk_sp<SkColorSpace> colorSpace, |
| 186 const SkIRect& dstBounds, | 186 const SkIRect& dstBounds, |
| 187 const SkIRect* srcBounds, | 187 const SkIRect* srcBounds, |
| 188 float sigmaX, | 188 float sigmaX, |
| 189 float sigmaY) { | 189 float sigmaY, |
| 190 SkBackingFit fit) { |
| 190 SkASSERT(context); | 191 SkASSERT(context); |
| 191 SkIRect clearRect; | 192 SkIRect clearRect; |
| 192 int scaleFactorX, radiusX; | 193 int scaleFactorX, radiusX; |
| 193 int scaleFactorY, radiusY; | 194 int scaleFactorY, radiusY; |
| 194 int maxTextureSize = context->caps()->maxTextureSize(); | 195 int maxTextureSize = context->caps()->maxTextureSize(); |
| 195 sigmaX = adjust_sigma(sigmaX, maxTextureSize, &scaleFactorX, &radiusX); | 196 sigmaX = adjust_sigma(sigmaX, maxTextureSize, &scaleFactorX, &radiusX); |
| 196 sigmaY = adjust_sigma(sigmaY, maxTextureSize, &scaleFactorY, &radiusY); | 197 sigmaY = adjust_sigma(sigmaY, maxTextureSize, &scaleFactorY, &radiusY); |
| 197 SkASSERT(sigmaX || sigmaY); | 198 SkASSERT(sigmaX || sigmaY); |
| 198 | 199 |
| 199 SkIPoint srcOffset = SkIPoint::Make(-dstBounds.x(), -dstBounds.y()); | 200 SkIPoint srcOffset = SkIPoint::Make(-dstBounds.x(), -dstBounds.y()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 219 SkASSERT(kBGRA_8888_GrPixelConfig == srcTexture->config() || | 220 SkASSERT(kBGRA_8888_GrPixelConfig == srcTexture->config() || |
| 220 kRGBA_8888_GrPixelConfig == srcTexture->config() || | 221 kRGBA_8888_GrPixelConfig == srcTexture->config() || |
| 221 kSRGBA_8888_GrPixelConfig == srcTexture->config() || | 222 kSRGBA_8888_GrPixelConfig == srcTexture->config() || |
| 222 kSBGRA_8888_GrPixelConfig == srcTexture->config() || | 223 kSBGRA_8888_GrPixelConfig == srcTexture->config() || |
| 223 kAlpha_8_GrPixelConfig == srcTexture->config()); | 224 kAlpha_8_GrPixelConfig == srcTexture->config()); |
| 224 | 225 |
| 225 const int width = dstBounds.width(); | 226 const int width = dstBounds.width(); |
| 226 const int height = dstBounds.height(); | 227 const int height = dstBounds.height(); |
| 227 const GrPixelConfig config = srcTexture->config(); | 228 const GrPixelConfig config = srcTexture->config(); |
| 228 | 229 |
| 229 sk_sp<GrDrawContext> dstDrawContext(context->makeDrawContext(SkBackingFit::k
Approx, | 230 sk_sp<GrDrawContext> dstDrawContext(context->makeDrawContext(fit, |
| 230 width, height,
config, colorSpace, | 231 width, height,
config, colorSpace, |
| 231 0, kDefault_GrS
urfaceOrigin)); | 232 0, kDefault_GrS
urfaceOrigin)); |
| 232 if (!dstDrawContext) { | 233 if (!dstDrawContext) { |
| 233 return nullptr; | 234 return nullptr; |
| 234 } | 235 } |
| 235 | 236 |
| 236 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i
s faster to just | 237 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i
s faster to just |
| 237 // launch a single non separable kernel vs two launches | 238 // launch a single non separable kernel vs two launches |
| 238 if (sigmaX > 0.0f && sigmaY > 0.0f && | 239 if (sigmaX > 0.0f && sigmaY > 0.0f && |
| 239 (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) { | 240 (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) { |
| 240 // We shouldn't be scaling because this is a small size blur | 241 // We shouldn't be scaling because this is a small size blur |
| 241 SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); | 242 SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); |
| 242 | 243 |
| 243 convolve_gaussian_2d(dstDrawContext.get(), clip, localDstBounds, srcOffs
et, | 244 convolve_gaussian_2d(dstDrawContext.get(), clip, localDstBounds, srcOffs
et, |
| 244 srcTexture.get(), radiusX, radiusY, sigmaX, sigmaY,
srcBounds); | 245 srcTexture.get(), radiusX, radiusY, sigmaX, sigmaY,
srcBounds); |
| 245 | 246 |
| 246 return dstDrawContext; | 247 return dstDrawContext; |
| 247 } | 248 } |
| 248 | 249 |
| 249 sk_sp<GrDrawContext> tmpDrawContext(context->makeDrawContext(SkBackingFit::k
Approx, | 250 sk_sp<GrDrawContext> tmpDrawContext(context->makeDrawContext(fit, |
| 250 width, height,
config, colorSpace, | 251 width, height,
config, colorSpace, |
| 251 0, kDefault_GrS
urfaceOrigin)); | 252 0, kDefault_GrS
urfaceOrigin)); |
| 252 if (!tmpDrawContext) { | 253 if (!tmpDrawContext) { |
| 253 return nullptr; | 254 return nullptr; |
| 254 } | 255 } |
| 255 | 256 |
| 256 sk_sp<GrDrawContext> srcDrawContext; | 257 sk_sp<GrDrawContext> srcDrawContext; |
| 257 | 258 |
| 258 SkASSERT(SkIsPow2(scaleFactorX) && SkIsPow2(scaleFactorY)); | 259 SkASSERT(SkIsPow2(scaleFactorX) && SkIsPow2(scaleFactorY)); |
| 259 | 260 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 dstDrawContext.swap(tmpDrawContext); | 372 dstDrawContext.swap(tmpDrawContext); |
| 372 } | 373 } |
| 373 | 374 |
| 374 return srcDrawContext; | 375 return srcDrawContext; |
| 375 } | 376 } |
| 376 | 377 |
| 377 } | 378 } |
| 378 | 379 |
| 379 #endif | 380 #endif |
| 380 | 381 |
| OLD | NEW |