| 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 #include "SkImageFilterCacheKey.h" | 9 #include "SkImageFilterCacheKey.h" |
| 10 | 10 |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 return false; | 407 return false; |
| 408 } | 408 } |
| 409 GrTexture* srcTexture = input.getTexture(); | 409 GrTexture* srcTexture = input.getTexture(); |
| 410 SkIRect bounds; | 410 SkIRect bounds; |
| 411 if (!this->applyCropRectDeprecated(ctx, proxy, input, &srcOffset, &bounds, &
input)) { | 411 if (!this->applyCropRectDeprecated(ctx, proxy, input, &srcOffset, &bounds, &
input)) { |
| 412 return false; | 412 return false; |
| 413 } | 413 } |
| 414 GrContext* context = srcTexture->getContext(); | 414 GrContext* context = srcTexture->getContext(); |
| 415 | 415 |
| 416 GrSurfaceDesc desc; | 416 GrSurfaceDesc desc; |
| 417 desc.fFlags = kRenderTarget_GrSurfaceFlag, | 417 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 418 desc.fWidth = bounds.width(); | 418 desc.fWidth = bounds.width(); |
| 419 desc.fHeight = bounds.height(); | 419 desc.fHeight = bounds.height(); |
| 420 desc.fConfig = kRGBA_8888_GrPixelConfig; | 420 desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 421 | 421 |
| 422 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(
desc)); | 422 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(
desc)); |
| 423 if (!dst) { | 423 if (!dst) { |
| 424 return false; | 424 return false; |
| 425 } | 425 } |
| 426 | 426 |
| 427 GrFragmentProcessor* fp; | 427 GrFragmentProcessor* fp; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 445 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, src
Rect); | 445 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, src
Rect); |
| 446 | 446 |
| 447 GrWrapTextureInBitmap(dst, bounds.width(), bounds.height(), false, r
esult); | 447 GrWrapTextureInBitmap(dst, bounds.width(), bounds.height(), false, r
esult); |
| 448 return true; | 448 return true; |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 #endif | 451 #endif |
| 452 return false; | 452 return false; |
| 453 } | 453 } |
| 454 | 454 |
| 455 #if SK_SUPPORT_GPU |
| 456 sk_sp<SkSpecialImage> SkImageFilter::DrawWithFP(GrContext* context, |
| 457 sk_sp<GrFragmentProcessor> fp, |
| 458 const SkIRect& bounds, |
| 459 SkImageFilter::Proxy* proxy) { |
| 460 GrPaint paint; |
| 461 paint.addColorFragmentProcessor(fp.get()); |
| 462 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 463 |
| 464 GrSurfaceDesc desc; |
| 465 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 466 desc.fWidth = bounds.width(); |
| 467 desc.fHeight = bounds.height(); |
| 468 desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 469 |
| 470 sk_sp<GrTexture> dst(context->textureProvider()->createApproxTexture(desc)); |
| 471 if (!dst) { |
| 472 return nullptr; |
| 473 } |
| 474 |
| 475 sk_sp<GrDrawContext> drawContext(context->drawContext(dst->asRenderTarget())
); |
| 476 if (!drawContext) { |
| 477 return nullptr; |
| 478 } |
| 479 |
| 480 SkRect srcRect = SkRect::Make(bounds); |
| 481 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
| 482 GrClip clip(dstRect); |
| 483 drawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect); |
| 484 |
| 485 return SkSpecialImage::MakeFromGpu(proxy, |
| 486 SkIRect::MakeWH(bounds.width(), bounds.he
ight()), |
| 487 kNeedNewImageUniqueID_SpecialImage, |
| 488 dst.get()); |
| 489 |
| 490 } |
| 491 #endif |
| 492 |
| 455 bool SkImageFilter::asAColorFilter(SkColorFilter** filterPtr) const { | 493 bool SkImageFilter::asAColorFilter(SkColorFilter** filterPtr) const { |
| 456 SkASSERT(nullptr != filterPtr); | 494 SkASSERT(nullptr != filterPtr); |
| 457 if (!this->isColorFilterNode(filterPtr)) { | 495 if (!this->isColorFilterNode(filterPtr)) { |
| 458 return false; | 496 return false; |
| 459 } | 497 } |
| 460 if (nullptr != this->getInput(0) || (*filterPtr)->affectsTransparentBlack())
{ | 498 if (nullptr != this->getInput(0) || (*filterPtr)->affectsTransparentBlack())
{ |
| 461 (*filterPtr)->unref(); | 499 (*filterPtr)->unref(); |
| 462 return false; | 500 return false; |
| 463 } | 501 } |
| 464 return true; | 502 return true; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 561 |
| 524 src->draw(canvas, offX, offY, nullptr); | 562 src->draw(canvas, offX, offY, nullptr); |
| 525 | 563 |
| 526 return surf->makeImageSnapshot(); | 564 return surf->makeImageSnapshot(); |
| 527 } | 565 } |
| 528 | 566 |
| 529 sk_sp<SkSpecialImage> SkImageFilter::applyCropRect(const Context& ctx, | 567 sk_sp<SkSpecialImage> SkImageFilter::applyCropRect(const Context& ctx, |
| 530 SkSpecialImage* src, | 568 SkSpecialImage* src, |
| 531 SkIPoint* srcOffset, | 569 SkIPoint* srcOffset, |
| 532 SkIRect* bounds) const { | 570 SkIRect* bounds) const { |
| 533 SkIRect srcBounds; | 571 const SkIRect srcBounds = SkIRect::MakeXYWH(srcOffset->x(), srcOffset->y(), |
| 534 srcBounds = SkIRect::MakeXYWH(srcOffset->fX, srcOffset->fY, src->width(), sr
c->height()); | 572 src->width(), src->height()); |
| 535 | 573 |
| 536 SkIRect dstBounds = this->onFilterNodeBounds(srcBounds, ctx.ctm(), kForward_
MapDirection); | 574 SkIRect dstBounds = this->onFilterNodeBounds(srcBounds, ctx.ctm(), kForward_
MapDirection); |
| 537 fCropRect.applyTo(dstBounds, ctx.ctm(), this->affectsTransparentBlack(), bou
nds); | 575 fCropRect.applyTo(dstBounds, ctx.ctm(), this->affectsTransparentBlack(), bou
nds); |
| 538 if (!bounds->intersect(ctx.clipBounds())) { | 576 if (!bounds->intersect(ctx.clipBounds())) { |
| 539 return nullptr; | 577 return nullptr; |
| 540 } | 578 } |
| 541 | 579 |
| 542 if (srcBounds.contains(*bounds)) { | 580 if (srcBounds.contains(*bounds)) { |
| 543 return sk_sp<SkSpecialImage>(SkRef(src)); | 581 return sk_sp<SkSpecialImage>(SkRef(src)); |
| 544 } else { | 582 } else { |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 dev = SkBitmapDevice::Create(cinfo.fInfo, surfaceProps); | 867 dev = SkBitmapDevice::Create(cinfo.fInfo, surfaceProps); |
| 830 } | 868 } |
| 831 return dev; | 869 return dev; |
| 832 } | 870 } |
| 833 | 871 |
| 834 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const
SkBitmap& src, | 872 bool SkImageFilter::DeviceProxy::filterImage(const SkImageFilter* filter, const
SkBitmap& src, |
| 835 const SkImageFilter::Context& ctx, | 873 const SkImageFilter::Context& ctx, |
| 836 SkBitmap* result, SkIPoint* offset) { | 874 SkBitmap* result, SkIPoint* offset) { |
| 837 return fDevice->filterImage(filter, src, ctx, result, offset); | 875 return fDevice->filterImage(filter, src, ctx, result, offset); |
| 838 } | 876 } |
| OLD | NEW |