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