| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 direction, radius, sigma, true, bounds); | 175 direction, radius, sigma, true, bounds); |
| 176 convolve_gaussian_1d(drawContext, clip, midRect, srcOffset, texture, | 176 convolve_gaussian_1d(drawContext, clip, midRect, srcOffset, texture, |
| 177 direction, radius, sigma, false, bounds); | 177 direction, radius, sigma, false, bounds); |
| 178 } | 178 } |
| 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 bool gammaCorrect, | 186 bool gammaCorrect, |
| 186 const SkIRect& dstBounds, | 187 const SkIRect& dstBounds, |
| 187 const SkIRect* srcBounds, | 188 const SkIRect* srcBounds, |
| 188 float sigmaX, | 189 float sigmaX, |
| 189 float sigmaY) { | 190 float sigmaY) { |
| 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(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 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 const SkSurfaceProps props(gammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag
: 0, | 230 const SkSurfaceProps props(gammaCorrect ? SkSurfaceProps::kGammaCorrect_Flag
: 0, |
| 230 SkSurfaceProps::kLegacyFontHost_InitType); | 231 SkSurfaceProps::kLegacyFontHost_InitType); |
| 231 | 232 |
| 232 sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(SkBackingFit::kA
pprox, | 233 sk_sp<GrDrawContext> dstDrawContext(context->newDrawContext(SkBackingFit::kA
pprox, |
| 233 width, height, c
onfig, | 234 width, height, c
onfig, colorSpace, |
| 234 0, kDefault_GrSu
rfaceOrigin, | 235 0, kDefault_GrSu
rfaceOrigin, |
| 235 &props)); | 236 &props)); |
| 236 if (!dstDrawContext) { | 237 if (!dstDrawContext) { |
| 237 return nullptr; | 238 return nullptr; |
| 238 } | 239 } |
| 239 | 240 |
| 240 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i
s faster to just | 241 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i
s faster to just |
| 241 // launch a single non separable kernel vs two launches | 242 // launch a single non separable kernel vs two launches |
| 242 if (sigmaX > 0.0f && sigmaY > 0.0f && | 243 if (sigmaX > 0.0f && sigmaY > 0.0f && |
| 243 (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) { | 244 (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) { |
| 244 // We shouldn't be scaling because this is a small size blur | 245 // We shouldn't be scaling because this is a small size blur |
| 245 SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); | 246 SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); |
| 246 | 247 |
| 247 convolve_gaussian_2d(dstDrawContext.get(), clip, localDstBounds, srcOffs
et, | 248 convolve_gaussian_2d(dstDrawContext.get(), clip, localDstBounds, srcOffs
et, |
| 248 srcTexture.get(), radiusX, radiusY, sigmaX, sigmaY,
srcBounds); | 249 srcTexture.get(), radiusX, radiusY, sigmaX, sigmaY,
srcBounds); |
| 249 | 250 |
| 250 return dstDrawContext; | 251 return dstDrawContext; |
| 251 } | 252 } |
| 252 | 253 |
| 253 sk_sp<GrDrawContext> tmpDrawContext(context->newDrawContext(SkBackingFit::kA
pprox, | 254 sk_sp<GrDrawContext> tmpDrawContext(context->newDrawContext(SkBackingFit::kA
pprox, |
| 254 width, height, c
onfig, | 255 width, height, c
onfig, colorSpace, |
| 255 0, kDefault_GrSu
rfaceOrigin, | 256 0, kDefault_GrSu
rfaceOrigin, |
| 256 &props)); | 257 &props)); |
| 257 if (!tmpDrawContext) { | 258 if (!tmpDrawContext) { |
| 258 return nullptr; | 259 return nullptr; |
| 259 } | 260 } |
| 260 | 261 |
| 261 sk_sp<GrDrawContext> srcDrawContext; | 262 sk_sp<GrDrawContext> srcDrawContext; |
| 262 | 263 |
| 263 SkASSERT(SkIsPow2(scaleFactorX) && SkIsPow2(scaleFactorY)); | 264 SkASSERT(SkIsPow2(scaleFactorX) && SkIsPow2(scaleFactorY)); |
| 264 | 265 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 dstDrawContext.swap(tmpDrawContext); | 377 dstDrawContext.swap(tmpDrawContext); |
| 377 } | 378 } |
| 378 | 379 |
| 379 return srcDrawContext; | 380 return srcDrawContext; |
| 380 } | 381 } |
| 381 | 382 |
| 382 } | 383 } |
| 383 | 384 |
| 384 #endif | 385 #endif |
| 385 | 386 |
| OLD | NEW |