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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, | 224 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, |
225 i < scaleFactorY ? 0.5f : 1.0f); | 225 i < scaleFactorY ? 0.5f : 1.0f); |
226 | 226 |
227 SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext()); | 227 SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext()); |
228 if (!dstDrawContext) { | 228 if (!dstDrawContext) { |
229 return nullptr; | 229 return nullptr; |
230 } | 230 } |
231 dstDrawContext->drawNonAARectToRect(dstTexture->asRenderTarget(), clip,
paint, | 231 dstDrawContext->drawNonAARectToRect(dstTexture->asRenderTarget(), clip,
paint, |
232 SkMatrix::I(), dstRect, srcRect); | 232 SkMatrix::I(), dstRect, srcRect); |
233 | 233 |
234 srcDrawContext.swap(&dstDrawContext); | 234 srcDrawContext.swap(dstDrawContext); |
235 srcRect = dstRect; | 235 srcRect = dstRect; |
236 srcTexture = dstTexture; | 236 srcTexture = dstTexture; |
237 SkTSwap(dstTexture, tempTexture); | 237 SkTSwap(dstTexture, tempTexture); |
238 } | 238 } |
239 | 239 |
240 const SkIRect srcIRect = srcRect.roundOut(); | 240 const SkIRect srcIRect = srcRect.roundOut(); |
241 | 241 |
242 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i
s faster to just | 242 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i
s faster to just |
243 // launch a single non separable kernel vs two launches | 243 // launch a single non separable kernel vs two launches |
244 if (sigmaX > 0.0f && sigmaY > 0.0f && | 244 if (sigmaX > 0.0f && sigmaY > 0.0f && |
245 (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) { | 245 (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) { |
246 // We shouldn't be scaling because this is a small size blur | 246 // We shouldn't be scaling because this is a small size blur |
247 SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); | 247 SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); |
248 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | 248 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
249 | 249 |
250 SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext()); | 250 SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext()); |
251 if (!dstDrawContext) { | 251 if (!dstDrawContext) { |
252 return nullptr; | 252 return nullptr; |
253 } | 253 } |
254 convolve_gaussian_2d(dstDrawContext, dstTexture->asRenderTarget(), clip,
srcRect, dstRect, | 254 convolve_gaussian_2d(dstDrawContext, dstTexture->asRenderTarget(), clip,
srcRect, dstRect, |
255 srcTexture, radiusX, radiusY, sigmaX, sigmaY, cropT
oRect, srcIRect); | 255 srcTexture, radiusX, radiusY, sigmaX, sigmaY, cropT
oRect, srcIRect); |
256 | 256 |
257 srcDrawContext.swap(&dstDrawContext); | 257 srcDrawContext.swap(dstDrawContext); |
258 srcRect = dstRect; | 258 srcRect = dstRect; |
259 srcTexture = dstTexture; | 259 srcTexture = dstTexture; |
260 SkTSwap(dstTexture, tempTexture); | 260 SkTSwap(dstTexture, tempTexture); |
261 | 261 |
262 } else { | 262 } else { |
263 if (sigmaX > 0.0f) { | 263 if (sigmaX > 0.0f) { |
264 if (scaleFactorX > 1) { | 264 if (scaleFactorX > 1) { |
265 // TODO: if we pass in the source draw context we don't need thi
s here | 265 // TODO: if we pass in the source draw context we don't need thi
s here |
266 if (!srcDrawContext) { | 266 if (!srcDrawContext) { |
267 srcDrawContext.reset(context->drawContext()); | 267 srcDrawContext.reset(context->drawContext()); |
(...skipping 11 matching lines...) Expand all Loading... |
279 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | 279 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
280 | 280 |
281 SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext()); | 281 SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext()); |
282 if (!dstDrawContext) { | 282 if (!dstDrawContext) { |
283 return nullptr; | 283 return nullptr; |
284 } | 284 } |
285 convolve_gaussian(dstDrawContext, dstTexture->asRenderTarget(), clip
, srcRect, dstRect, | 285 convolve_gaussian(dstDrawContext, dstTexture->asRenderTarget(), clip
, srcRect, dstRect, |
286 srcTexture, Gr1DKernelEffect::kX_Direction, radius
X, sigmaX, | 286 srcTexture, Gr1DKernelEffect::kX_Direction, radius
X, sigmaX, |
287 cropToRect); | 287 cropToRect); |
288 | 288 |
289 srcDrawContext.swap(&dstDrawContext); | 289 srcDrawContext.swap(dstDrawContext); |
290 srcTexture = dstTexture; | 290 srcTexture = dstTexture; |
291 srcRect = dstRect; | 291 srcRect = dstRect; |
292 SkTSwap(dstTexture, tempTexture); | 292 SkTSwap(dstTexture, tempTexture); |
293 } | 293 } |
294 | 294 |
295 if (sigmaY > 0.0f) { | 295 if (sigmaY > 0.0f) { |
296 if (scaleFactorY > 1 || sigmaX > 0.0f) { | 296 if (scaleFactorY > 1 || sigmaX > 0.0f) { |
297 // TODO: if we pass in the source draw context we don't need thi
s here | 297 // TODO: if we pass in the source draw context we don't need thi
s here |
298 if (!srcDrawContext) { | 298 if (!srcDrawContext) { |
299 srcDrawContext.reset(context->drawContext()); | 299 srcDrawContext.reset(context->drawContext()); |
(...skipping 12 matching lines...) Expand all Loading... |
312 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | 312 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
313 | 313 |
314 SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext()); | 314 SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext()); |
315 if (!dstDrawContext) { | 315 if (!dstDrawContext) { |
316 return nullptr; | 316 return nullptr; |
317 } | 317 } |
318 convolve_gaussian(dstDrawContext, dstTexture->asRenderTarget(), clip
, srcRect, | 318 convolve_gaussian(dstDrawContext, dstTexture->asRenderTarget(), clip
, srcRect, |
319 dstRect, srcTexture, Gr1DKernelEffect::kY_Directio
n, radiusY, sigmaY, | 319 dstRect, srcTexture, Gr1DKernelEffect::kY_Directio
n, radiusY, sigmaY, |
320 cropToRect); | 320 cropToRect); |
321 | 321 |
322 srcDrawContext.swap(&dstDrawContext); | 322 srcDrawContext.swap(dstDrawContext); |
323 srcTexture = dstTexture; | 323 srcTexture = dstTexture; |
324 srcRect = dstRect; | 324 srcRect = dstRect; |
325 SkTSwap(dstTexture, tempTexture); | 325 SkTSwap(dstTexture, tempTexture); |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 if (scaleFactorX > 1 || scaleFactorY > 1) { | 329 if (scaleFactorX > 1 || scaleFactorY > 1) { |
330 SkASSERT(srcDrawContext); | 330 SkASSERT(srcDrawContext); |
331 | 331 |
332 // Clear one pixel to the right and below, to accommodate bilinear | 332 // Clear one pixel to the right and below, to accommodate bilinear |
(...skipping 15 matching lines...) Expand all Loading... |
348 SkRect dstRect(srcRect); | 348 SkRect dstRect(srcRect); |
349 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); | 349 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); |
350 | 350 |
351 SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext()); | 351 SkAutoTUnref<GrDrawContext> dstDrawContext(context->drawContext()); |
352 if (!dstDrawContext) { | 352 if (!dstDrawContext) { |
353 return nullptr; | 353 return nullptr; |
354 } | 354 } |
355 dstDrawContext->drawNonAARectToRect(dstTexture->asRenderTarget(), clip,
paint, | 355 dstDrawContext->drawNonAARectToRect(dstTexture->asRenderTarget(), clip,
paint, |
356 SkMatrix::I(), dstRect, srcRect); | 356 SkMatrix::I(), dstRect, srcRect); |
357 | 357 |
358 srcDrawContext.swap(&dstDrawContext); | 358 srcDrawContext.swap(dstDrawContext); |
359 srcRect = dstRect; | 359 srcRect = dstRect; |
360 srcTexture = dstTexture; | 360 srcTexture = dstTexture; |
361 SkTSwap(dstTexture, tempTexture); | 361 SkTSwap(dstTexture, tempTexture); |
362 } | 362 } |
363 | 363 |
364 return SkRef(srcTexture); | 364 return SkRef(srcTexture); |
365 } | 365 } |
366 #endif | 366 #endif |
367 | 367 |
368 } | 368 } |
OLD | NEW |