OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
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 "SkImageFilter.h" | 8 #include "SkImageFilter.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 this->onFilterImage(proxy, src, context, result, offset)) { | 258 this->onFilterImage(proxy, src, context, result, offset)) { |
259 if (context.cache()) { | 259 if (context.cache()) { |
260 context.cache()->set(key, *result, *offset); | 260 context.cache()->set(key, *result, *offset); |
261 } | 261 } |
262 return true; | 262 return true; |
263 } | 263 } |
264 return false; | 264 return false; |
265 } | 265 } |
266 | 266 |
267 bool SkImageFilter::filterInput(int index, Proxy* proxy, const SkBitmap& src, | 267 bool SkImageFilter::filterInput(int index, Proxy* proxy, const SkBitmap& src, |
268 const Context& origCtx, | 268 const Context& ctx, |
269 SkBitmap* result, SkIPoint* offset, | 269 SkBitmap* result, SkIPoint* offset) const { |
270 bool relaxSizeConstraint) const { | |
271 SkImageFilter* input = this->getInput(index); | 270 SkImageFilter* input = this->getInput(index); |
272 if (!input) { | 271 if (!input) { |
273 return true; | 272 return true; |
274 } | 273 } |
275 | |
276 SizeConstraint constraint = origCtx.sizeConstraint(); | |
277 if (relaxSizeConstraint && (kExact_SizeConstraint == constraint)) { | |
278 constraint = kApprox_SizeConstraint; | |
279 } | |
280 Context ctx(origCtx.ctm(), origCtx.clipBounds(), origCtx.cache(), constraint
); | |
281 | |
282 return input->filterImage(proxy, src, this->mapContext(ctx), result, offset)
; | 274 return input->filterImage(proxy, src, this->mapContext(ctx), result, offset)
; |
283 } | 275 } |
284 | 276 |
285 bool SkImageFilter::filterBounds(const SkIRect& src, const SkMatrix& ctm, | 277 bool SkImageFilter::filterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRec
t* dst) const { |
286 SkIRect* dst) const { | |
287 SkASSERT(dst); | 278 SkASSERT(dst); |
288 return this->onFilterBounds(src, ctm, dst); | 279 return this->onFilterBounds(src, ctm, dst); |
289 } | 280 } |
290 | 281 |
291 void SkImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { | 282 void SkImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { |
292 if (0 == fInputCount) { | 283 if (0 == fInputCount) { |
293 *dst = src; | 284 *dst = src; |
294 return; | 285 return; |
295 } | 286 } |
296 if (this->getInput(0)) { | 287 if (this->getInput(0)) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 SkRect srcRect = SkRect::Make(bounds); | 337 SkRect srcRect = SkRect::Make(bounds); |
347 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | 338 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
348 GrContext* context = srcTexture->getContext(); | 339 GrContext* context = srcTexture->getContext(); |
349 | 340 |
350 GrSurfaceDesc desc; | 341 GrSurfaceDesc desc; |
351 desc.fFlags = kRenderTarget_GrSurfaceFlag, | 342 desc.fFlags = kRenderTarget_GrSurfaceFlag, |
352 desc.fWidth = bounds.width(); | 343 desc.fWidth = bounds.width(); |
353 desc.fHeight = bounds.height(); | 344 desc.fHeight = bounds.height(); |
354 desc.fConfig = kRGBA_8888_GrPixelConfig; | 345 desc.fConfig = kRGBA_8888_GrPixelConfig; |
355 | 346 |
356 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createTexture(desc, | 347 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(
desc)); |
357 GrTextureProvider::FromImageFilter(ctx.siz
eConstraint()))); | |
358 if (!dst) { | 348 if (!dst) { |
359 return false; | 349 return false; |
360 } | 350 } |
361 | 351 |
362 // setup new clip | 352 // setup new clip |
363 GrClip clip(dstRect); | 353 GrClip clip(dstRect); |
364 | 354 |
365 GrFragmentProcessor* fp; | 355 GrFragmentProcessor* fp; |
366 offset->fX = bounds.left(); | 356 offset->fX = bounds.left(); |
367 offset->fY = bounds.top(); | 357 offset->fY = bounds.top(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 } | 471 } |
482 | 472 |
483 | 473 |
484 SkImageFilter::Context SkImageFilter::mapContext(const Context& ctx) const { | 474 SkImageFilter::Context SkImageFilter::mapContext(const Context& ctx) const { |
485 #ifdef SK_SUPPORT_SRC_BOUNDS_BLOAT_FOR_IMAGEFILTERS | 475 #ifdef SK_SUPPORT_SRC_BOUNDS_BLOAT_FOR_IMAGEFILTERS |
486 return ctx; | 476 return ctx; |
487 #else | 477 #else |
488 SkIRect clipBounds; | 478 SkIRect clipBounds; |
489 this->onFilterNodeBounds(ctx.clipBounds(), ctx.ctm(), &clipBounds, | 479 this->onFilterNodeBounds(ctx.clipBounds(), ctx.ctm(), &clipBounds, |
490 MapDirection::kReverse_MapDirection); | 480 MapDirection::kReverse_MapDirection); |
491 return Context(ctx.ctm(), clipBounds, ctx.cache(), ctx.sizeConstraint()); | 481 return Context(ctx.ctm(), clipBounds, ctx.cache()); |
492 #endif | 482 #endif |
493 } | 483 } |
494 | 484 |
495 bool SkImageFilter::asFragmentProcessor(GrFragmentProcessor**, GrTexture*, | 485 bool SkImageFilter::asFragmentProcessor(GrFragmentProcessor**, GrTexture*, |
496 const SkMatrix&, const SkIRect&) const { | 486 const SkMatrix&, const SkIRect&) const { |
497 return false; | 487 return false; |
498 } | 488 } |
499 | 489 |
500 SkImageFilter* SkImageFilter::CreateMatrixFilter(const SkMatrix& matrix, | 490 SkImageFilter* SkImageFilter::CreateMatrixFilter(const SkMatrix& matrix, |
501 SkFilterQuality filterQuality, | 491 SkFilterQuality filterQuality, |
(...skipping 10 matching lines...) Expand all Loading... |
512 | 502 |
513 #if SK_SUPPORT_GPU | 503 #if SK_SUPPORT_GPU |
514 | 504 |
515 void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBit
map* result) { | 505 void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBit
map* result) { |
516 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 506 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
517 result->setInfo(info); | 507 result->setInfo(info); |
518 result->setPixelRef(new SkGrPixelRef(info, texture))->unref(); | 508 result->setPixelRef(new SkGrPixelRef(info, texture))->unref(); |
519 } | 509 } |
520 | 510 |
521 bool SkImageFilter::filterInputGPU(int index, SkImageFilter::Proxy* proxy, | 511 bool SkImageFilter::filterInputGPU(int index, SkImageFilter::Proxy* proxy, |
522 const SkBitmap& src, const Context& origCtx, | 512 const SkBitmap& src, const Context& ctx, |
523 SkBitmap* result, SkIPoint* offset) const { | 513 SkBitmap* result, SkIPoint* offset) const { |
524 SkImageFilter* input = this->getInput(index); | 514 SkImageFilter* input = this->getInput(index); |
525 if (!input) { | 515 if (!input) { |
526 return true; | 516 return true; |
527 } | 517 } |
528 // Ensure that GrContext calls under filterImage and filterImageGPU below wi
ll see an identity | 518 // Ensure that GrContext calls under filterImage and filterImageGPU below wi
ll see an identity |
529 // matrix with no clip and that the matrix, clip, and render target set befo
re this function was | 519 // matrix with no clip and that the matrix, clip, and render target set befo
re this function was |
530 // called are restored before we return to the caller. | 520 // called are restored before we return to the caller. |
531 GrContext* context = src.getTexture()->getContext(); | 521 GrContext* context = src.getTexture()->getContext(); |
532 | |
533 Context ctx(origCtx.ctm(), origCtx.clipBounds(), origCtx.cache(), kApprox_Si
zeConstraint); | |
534 | |
535 if (input->filterImage(proxy, src, this->mapContext(ctx), result, offset)) { | 522 if (input->filterImage(proxy, src, this->mapContext(ctx), result, offset)) { |
536 if (!result->getTexture()) { | 523 if (!result->getTexture()) { |
537 const SkImageInfo info = result->info(); | 524 const SkImageInfo info = result->info(); |
538 if (kUnknown_SkColorType == info.colorType()) { | 525 if (kUnknown_SkColorType == info.colorType()) { |
539 return false; | 526 return false; |
540 } | 527 } |
541 SkAutoTUnref<GrTexture> resultTex( | 528 SkAutoTUnref<GrTexture> resultTex( |
542 GrRefCachedBitmapTexture(context, *result, GrTextureParams::Clam
pNoFilter())); | 529 GrRefCachedBitmapTexture(context, *result, GrTextureParams::Clam
pNoFilter())); |
543 if (!resultTex) { | 530 if (!resultTex) { |
544 return false; | 531 return false; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 } | 677 } |
691 return dev; | 678 return dev; |
692 } | 679 } |
693 | 680 |
694 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const
SkBitmap& src, | 681 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const
SkBitmap& src, |
695 const SkImageFilter::Context& ctx, | 682 const SkImageFilter::Context& ctx, |
696 SkBitmap* result, SkIPoint* offset) { | 683 SkBitmap* result, SkIPoint* offset) { |
697 return fDevice->filterImage(filter, src, ctx, result, offset); | 684 return fDevice->filterImage(filter, src, ctx, result, offset); |
698 } | 685 } |
699 | 686 |
OLD | NEW |