Chromium Code Reviews| 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 "SkMorphologyImageFilter.h" | 8 #include "SkMorphologyImageFilter.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 | 131 |
| 132 bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc p rocX, | 132 bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc p rocX, |
| 133 SkMorphologyImageFilter::Proc p rocY, | 133 SkMorphologyImageFilter::Proc p rocY, |
| 134 Proxy* proxy, | 134 Proxy* proxy, |
| 135 const SkBitmap& source, | 135 const SkBitmap& source, |
| 136 const Context& ctx, | 136 const Context& ctx, |
| 137 SkBitmap* dst, | 137 SkBitmap* dst, |
| 138 SkIPoint* offset) const { | 138 SkIPoint* offset) const { |
| 139 SkBitmap src = source; | 139 SkBitmap src = source; |
| 140 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 140 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 141 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcO ffset)) { | 141 if (this->getInput(0) && |
| 142 !this->getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset)) { | |
| 142 return false; | 143 return false; |
| 143 } | 144 } |
| 144 | 145 |
| 145 if (src.colorType() != kN32_SkColorType) { | 146 if (src.colorType() != kN32_SkColorType) { |
| 146 return false; | 147 return false; |
| 147 } | 148 } |
| 148 | 149 |
| 149 SkIRect bounds; | 150 SkIRect bounds; |
| 150 if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &bounds, &src)) { | 151 if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &bounds, &src)) { |
| 151 return false; | 152 return false; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 dilateXProc = dilate<kX>; | 222 dilateXProc = dilate<kX>; |
| 222 } | 223 } |
| 223 Proc dilateYProc = SkMorphologyGetPlatformProc(kDilateY_SkMorphologyProcType ); | 224 Proc dilateYProc = SkMorphologyGetPlatformProc(kDilateY_SkMorphologyProcType ); |
| 224 if (!dilateYProc) { | 225 if (!dilateYProc) { |
| 225 dilateYProc = dilate<kY>; | 226 dilateYProc = dilate<kY>; |
| 226 } | 227 } |
| 227 return this->filterImageGeneric(dilateXProc, dilateYProc, proxy, source, ctx , dst, offset); | 228 return this->filterImageGeneric(dilateXProc, dilateYProc, proxy, source, ctx , dst, offset); |
| 228 } | 229 } |
| 229 | 230 |
| 230 void SkMorphologyImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { | 231 void SkMorphologyImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { |
| 231 if (getInput(0)) { | 232 if (this->getInput(0)) { |
| 232 getInput(0)->computeFastBounds(src, dst); | 233 this->getInput(0)->computeFastBounds(src, dst); |
| 233 } else { | 234 } else { |
| 234 *dst = src; | 235 *dst = src; |
| 235 } | 236 } |
| 236 dst->outset(SkIntToScalar(fRadius.width()), SkIntToScalar(fRadius.height())) ; | 237 dst->outset(SkIntToScalar(fRadius.width()), SkIntToScalar(fRadius.height())) ; |
| 237 } | 238 } |
| 238 | 239 |
| 239 bool SkMorphologyImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, | 240 bool SkMorphologyImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, |
| 240 SkIRect* dst) const { | 241 SkIRect* dst) const { |
| 241 SkIRect bounds = src; | 242 SkIRect bounds = src; |
| 242 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()), | 243 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()), |
| 243 SkIntToScalar(this->radius().height())); | 244 SkIntToScalar(this->radius().height())); |
| 244 ctm.mapVectors(&radius, 1); | 245 ctm.mapVectors(&radius, 1); |
| 245 bounds.outset(SkScalarCeilToInt(radius.x()), SkScalarCeilToInt(radius.y())); | 246 bounds.outset(SkScalarCeilToInt(radius.x()), SkScalarCeilToInt(radius.y())); |
| 246 if (getInput(0) && !getInput(0)->filterBounds(bounds, ctm, &bounds)) { | 247 if (this->getInput(0) && !this->getInput(0)->filterBounds(bounds, ctm, &boun ds)) { |
| 247 return false; | 248 return false; |
| 248 } | 249 } |
| 249 *dst = bounds; | 250 *dst = bounds; |
| 250 return true; | 251 return true; |
| 251 } | 252 } |
| 252 | 253 |
| 253 SkFlattenable* SkErodeImageFilter::CreateProc(SkReadBuffer& buffer) { | 254 SkFlattenable* SkErodeImageFilter::CreateProc(SkReadBuffer& buffer) { |
| 254 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 255 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
| 255 const int width = buffer.readInt(); | 256 const int width = buffer.readInt(); |
| 256 const int height = buffer.readInt(); | 257 const int height = buffer.readInt(); |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 SkIntToScalar(srcTexture->height()))); | 664 SkIntToScalar(srcTexture->height()))); |
| 664 | 665 |
| 665 SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height()); | 666 SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height()); |
| 666 GrSurfaceDesc desc; | 667 GrSurfaceDesc desc; |
| 667 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 668 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 668 desc.fWidth = rect.width(); | 669 desc.fWidth = rect.width(); |
| 669 desc.fHeight = rect.height(); | 670 desc.fHeight = rect.height(); |
| 670 desc.fConfig = kSkia8888_GrPixelConfig; | 671 desc.fConfig = kSkia8888_GrPixelConfig; |
| 671 SkIRect srcRect = rect; | 672 SkIRect srcRect = rect; |
| 672 | 673 |
| 673 GrDrawContext* drawContext = context->drawContext(); | |
| 674 if (!drawContext) { | |
| 675 return false; | |
| 676 } | |
| 677 | |
| 678 if (radius.fWidth > 0) { | 674 if (radius.fWidth > 0) { |
| 679 GrTexture* texture = context->textureProvider()->refScratchTexture( | 675 GrTexture* dst = context->textureProvider()->refScratchTexture( |
|
brucedawson
2015/07/23 17:52:12
'dst' is a confusing variable name to use here bec
| |
| 680 desc, GrTextureProvider::kApprox_ScratchTexMatch); | 676 desc, GrTextureProvider::kApprox_ScratchTexMatch); |
| 681 if (NULL == texture) { | 677 if (NULL == dst) { |
| 682 return false; | 678 return false; |
| 683 } | 679 } |
| 684 apply_morphology_pass(drawContext, texture->asRenderTarget(), clip, srcT exture, | 680 GrDrawContext* dstDrawContext = context->drawContext(); |
| 681 if (!dstDrawContext) { | |
| 682 return false; | |
| 683 } | |
| 684 | |
| 685 apply_morphology_pass(dstDrawContext, dst->asRenderTarget(), clip, srcTe xture, | |
| 685 srcRect, dstRect, radius.fWidth, morphType, | 686 srcRect, dstRect, radius.fWidth, morphType, |
| 686 Gr1DKernelEffect::kX_Direction); | 687 Gr1DKernelEffect::kX_Direction); |
| 687 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, | 688 SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, |
| 688 dstRect.width(), radius.fHeight); | 689 dstRect.width(), radius.fHeight); |
| 689 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT ype ? | 690 GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphT ype ? |
| 690 SK_ColorWHITE : | 691 SK_ColorWHITE : |
| 691 SK_ColorTRANSPARENT; | 692 SK_ColorTRANSPARENT; |
| 692 drawContext->clear(texture->asRenderTarget(), &clearRect, clearColor, fa lse); | 693 dstDrawContext->clear(dst->asRenderTarget(), &clearRect, clearColor, fal se); |
| 693 srcTexture.reset(texture); | 694 |
| 695 srcTexture.reset(dst); | |
| 694 srcRect = dstRect; | 696 srcRect = dstRect; |
| 695 } | 697 } |
| 696 if (radius.fHeight > 0) { | 698 if (radius.fHeight > 0) { |
| 697 GrTexture* texture = context->textureProvider()->refScratchTexture(desc, | 699 GrTexture* dst = context->textureProvider()->refScratchTexture(desc, |
|
brucedawson
2015/07/23 17:52:11
Ditto. FWIW.
| |
| 698 GrTextureProvider::kApprox_ScratchTexMatch); | 700 GrTextureProvider::kApprox_ScratchTexMatch); |
| 699 if (NULL == texture) { | 701 if (NULL == dst) { |
| 700 return false; | 702 return false; |
| 701 } | 703 } |
| 702 apply_morphology_pass(drawContext, texture->asRenderTarget(), clip, srcT exture, | 704 GrDrawContext* dstDrawContext = context->drawContext(); |
| 705 if (!dstDrawContext) { | |
| 706 return false; | |
| 707 } | |
| 708 | |
| 709 apply_morphology_pass(dstDrawContext, dst->asRenderTarget(), clip, srcTe xture, | |
| 703 srcRect, dstRect, radius.fHeight, morphType, | 710 srcRect, dstRect, radius.fHeight, morphType, |
| 704 Gr1DKernelEffect::kY_Direction); | 711 Gr1DKernelEffect::kY_Direction); |
| 705 srcTexture.reset(texture); | 712 |
| 713 srcTexture.reset(dst); | |
| 706 } | 714 } |
| 707 SkImageFilter::WrapTexture(srcTexture, rect.width(), rect.height(), dst); | 715 SkImageFilter::WrapTexture(srcTexture, rect.width(), rect.height(), dst); |
|
brucedawson
2015/07/23 17:52:12
This appears to be the only one of the seven refer
| |
| 708 return true; | 716 return true; |
| 709 } | 717 } |
| 710 | 718 |
| 711 }; | 719 }; |
| 712 | 720 |
| 713 bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate, | 721 bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate, |
| 714 Proxy* proxy, | 722 Proxy* proxy, |
| 715 const SkBitmap& src, | 723 const SkBitmap& src, |
| 716 const Context& ctx, | 724 const Context& ctx, |
| 717 SkBitmap* result, | 725 SkBitmap* result, |
| 718 SkIPoint* offset) const { | 726 SkIPoint* offset) const { |
| 719 SkBitmap input = src; | 727 SkBitmap input = src; |
| 720 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 728 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 721 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) { | 729 if (this->getInput(0) && |
| 730 !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffse t)) { | |
| 722 return false; | 731 return false; |
| 723 } | 732 } |
| 724 SkIRect bounds; | 733 SkIRect bounds; |
| 725 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &bounds, &input)) { | 734 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &bounds, &input)) { |
| 726 return false; | 735 return false; |
| 727 } | 736 } |
| 728 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()), | 737 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()), |
| 729 SkIntToScalar(this->radius().height())); | 738 SkIntToScalar(this->radius().height())); |
| 730 ctx.ctm().mapVectors(&radius, 1); | 739 ctx.ctm().mapVectors(&radius, 1); |
| 731 int width = SkScalarFloorToInt(radius.fX); | 740 int width = SkScalarFloorToInt(radius.fX); |
| 732 int height = SkScalarFloorToInt(radius.fY); | 741 int height = SkScalarFloorToInt(radius.fY); |
| 733 | 742 |
| 734 if (width < 0 || height < 0) { | 743 if (width < 0 || height < 0) { |
| 735 return false; | 744 return false; |
| 736 } | 745 } |
| 737 | 746 |
| 738 SkIRect srcBounds = bounds; | 747 SkIRect srcBounds = bounds; |
| 739 srcBounds.offset(-srcOffset); | 748 srcBounds.offset(-srcOffset); |
| 740 if (width == 0 && height == 0) { | 749 if (width == 0 && height == 0) { |
| 741 input.extractSubset(result, srcBounds); | 750 input.extractSubset(result, srcBounds); |
| 742 offset->fX = bounds.left(); | 751 offset->fX = bounds.left(); |
| 743 offset->fY = bounds.top(); | 752 offset->fY = bounds.top(); |
| 744 return true; | 753 return true; |
| 745 } | 754 } |
| 746 | 755 |
| 747 GrMorphologyEffect::MorphologyType type = dilate ? GrMorphologyEffect::kDila te_MorphologyType : GrMorphologyEffect::kErode_MorphologyType; | 756 GrMorphologyEffect::MorphologyType type = dilate ? GrMorphologyEffect::kDila te_MorphologyType |
| 748 if (!apply_morphology(input, srcBounds, type, | 757 : GrMorphologyEffect::kErod e_MorphologyType; |
| 749 SkISize::Make(width, height), result)) { | 758 if (!apply_morphology(input, srcBounds, type, SkISize::Make(width, height), result)) { |
| 750 return false; | 759 return false; |
| 751 } | 760 } |
| 752 offset->fX = bounds.left(); | 761 offset->fX = bounds.left(); |
| 753 offset->fY = bounds.top(); | 762 offset->fY = bounds.top(); |
| 754 return true; | 763 return true; |
| 755 } | 764 } |
| 756 | 765 |
| 757 bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, cons t Context& ctx, | 766 bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, cons t Context& ctx, |
| 758 SkBitmap* result, SkIPoint* offset) con st { | 767 SkBitmap* result, SkIPoint* offset) con st { |
| 759 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); | 768 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); |
| 760 } | 769 } |
| 761 | 770 |
| 762 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx, | 771 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx, |
| 763 SkBitmap* result, SkIPoint* offset) cons t { | 772 SkBitmap* result, SkIPoint* offset) cons t { |
| 764 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); | 773 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); |
| 765 } | 774 } |
| 766 | 775 |
| 767 #endif | 776 #endif |
| OLD | NEW |