| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "SkBlurMaskFilter.h" | 9 #include "SkBlurMaskFilter.h" |
| 10 #include "SkBlurMask.h" | 10 #include "SkBlurMask.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&, | 44 bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&, |
| 45 SkIPoint* margin) const override; | 45 SkIPoint* margin) const override; |
| 46 | 46 |
| 47 #if SK_SUPPORT_GPU | 47 #if SK_SUPPORT_GPU |
| 48 bool canFilterMaskGPU(const SkRRect& devRRect, | 48 bool canFilterMaskGPU(const SkRRect& devRRect, |
| 49 const SkIRect& clipBounds, | 49 const SkIRect& clipBounds, |
| 50 const SkMatrix& ctm, | 50 const SkMatrix& ctm, |
| 51 SkRect* maskRect) const override; | 51 SkRect* maskRect) const override; |
| 52 bool directFilterMaskGPU(GrTextureProvider* texProvider, | 52 bool directFilterMaskGPU(GrTextureProvider* texProvider, |
| 53 GrDrawContext* drawContext, | 53 GrDrawContext* drawContext, |
| 54 GrRenderTarget* rt, | |
| 55 GrPaint* grp, | 54 GrPaint* grp, |
| 56 const GrClip&, | 55 const GrClip&, |
| 57 const SkMatrix& viewMatrix, | 56 const SkMatrix& viewMatrix, |
| 58 const SkStrokeRec& strokeRec, | 57 const SkStrokeRec& strokeRec, |
| 59 const SkPath& path) const override; | 58 const SkPath& path) const override; |
| 60 bool directFilterRRectMaskGPU(GrTextureProvider* texProvider, | 59 bool directFilterRRectMaskGPU(GrTextureProvider* texProvider, |
| 61 GrDrawContext* drawContext, | 60 GrDrawContext* drawContext, |
| 62 GrRenderTarget* rt, | |
| 63 GrPaint* grp, | 61 GrPaint* grp, |
| 64 const GrClip&, | 62 const GrClip&, |
| 65 const SkMatrix& viewMatrix, | 63 const SkMatrix& viewMatrix, |
| 66 const SkStrokeRec& strokeRec, | 64 const SkStrokeRec& strokeRec, |
| 67 const SkRRect& rrect) const override; | 65 const SkRRect& rrect) const override; |
| 68 bool filterMaskGPU(GrTexture* src, | 66 bool filterMaskGPU(GrTexture* src, |
| 69 const SkMatrix& ctm, | 67 const SkMatrix& ctm, |
| 70 const SkRect& maskRect, | 68 const SkRect& maskRect, |
| 71 GrTexture** result, | 69 GrTexture** result, |
| 72 bool canOverwriteSrc) const override; | 70 bool canOverwriteSrc) const override; |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 float sigma = d->fRandom->nextRangeF(3,8); | 797 float sigma = d->fRandom->nextRangeF(3,8); |
| 800 float width = d->fRandom->nextRangeF(200,300); | 798 float width = d->fRandom->nextRangeF(200,300); |
| 801 float height = d->fRandom->nextRangeF(200,300); | 799 float height = d->fRandom->nextRangeF(200,300); |
| 802 return GrRectBlurEffect::Create(d->fContext->textureProvider(), SkRect::Make
WH(width, height), | 800 return GrRectBlurEffect::Create(d->fContext->textureProvider(), SkRect::Make
WH(width, height), |
| 803 sigma); | 801 sigma); |
| 804 } | 802 } |
| 805 | 803 |
| 806 | 804 |
| 807 bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrTextureProvider* texProvider, | 805 bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrTextureProvider* texProvider, |
| 808 GrDrawContext* drawContext, | 806 GrDrawContext* drawContext, |
| 809 GrRenderTarget* rt, | |
| 810 GrPaint* grp, | 807 GrPaint* grp, |
| 811 const GrClip& clip, | 808 const GrClip& clip, |
| 812 const SkMatrix& viewMatrix, | 809 const SkMatrix& viewMatrix, |
| 813 const SkStrokeRec& strokeRec, | 810 const SkStrokeRec& strokeRec, |
| 814 const SkPath& path) const { | 811 const SkPath& path) const { |
| 815 SkASSERT(drawContext); | 812 SkASSERT(drawContext); |
| 816 | 813 |
| 817 if (fBlurStyle != kNormal_SkBlurStyle) { | 814 if (fBlurStyle != kNormal_SkBlurStyle) { |
| 818 return false; | 815 return false; |
| 819 } | 816 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 847 return false; | 844 return false; |
| 848 } | 845 } |
| 849 | 846 |
| 850 grp->addCoverageFragmentProcessor(fp); | 847 grp->addCoverageFragmentProcessor(fp); |
| 851 | 848 |
| 852 SkMatrix inverse; | 849 SkMatrix inverse; |
| 853 if (!viewMatrix.invert(&inverse)) { | 850 if (!viewMatrix.invert(&inverse)) { |
| 854 return false; | 851 return false; |
| 855 } | 852 } |
| 856 | 853 |
| 857 drawContext->drawNonAARectWithLocalMatrix(rt, clip, *grp, SkMatrix::I(), rec
t, inverse); | 854 drawContext->drawNonAARectWithLocalMatrix(clip, *grp, SkMatrix::I(), rect, i
nverse); |
| 858 return true; | 855 return true; |
| 859 } | 856 } |
| 860 | 857 |
| 861 ////////////////////////////////////////////////////////////////////////////// | 858 ////////////////////////////////////////////////////////////////////////////// |
| 862 | 859 |
| 863 class GrRRectBlurEffect : public GrFragmentProcessor { | 860 class GrRRectBlurEffect : public GrFragmentProcessor { |
| 864 public: | 861 public: |
| 865 | 862 |
| 866 static const GrFragmentProcessor* Create(GrTextureProvider*, float sigma, co
nst SkRRect&); | 863 static const GrFragmentProcessor* Create(GrTextureProvider*, float sigma, co
nst SkRRect&); |
| 867 | 864 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 void GrRRectBlurEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorK
eyBuilder* b) const { | 1091 void GrRRectBlurEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorK
eyBuilder* b) const { |
| 1095 GrGLRRectBlurEffect::GenKey(*this, caps, b); | 1092 GrGLRRectBlurEffect::GenKey(*this, caps, b); |
| 1096 } | 1093 } |
| 1097 | 1094 |
| 1098 GrGLFragmentProcessor* GrRRectBlurEffect::onCreateGLInstance() const { | 1095 GrGLFragmentProcessor* GrRRectBlurEffect::onCreateGLInstance() const { |
| 1099 return new GrGLRRectBlurEffect(*this); | 1096 return new GrGLRRectBlurEffect(*this); |
| 1100 } | 1097 } |
| 1101 | 1098 |
| 1102 bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrTextureProvider* texProvid
er, | 1099 bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrTextureProvider* texProvid
er, |
| 1103 GrDrawContext* drawContext, | 1100 GrDrawContext* drawContext, |
| 1104 GrRenderTarget* rt, | |
| 1105 GrPaint* grp, | 1101 GrPaint* grp, |
| 1106 const GrClip& clip, | 1102 const GrClip& clip, |
| 1107 const SkMatrix& viewMatrix, | 1103 const SkMatrix& viewMatrix, |
| 1108 const SkStrokeRec& strokeRec
, | 1104 const SkStrokeRec& strokeRec
, |
| 1109 const SkRRect& rrect) const
{ | 1105 const SkRRect& rrect) const
{ |
| 1110 SkASSERT(drawContext); | 1106 SkASSERT(drawContext); |
| 1111 | 1107 |
| 1112 if (fBlurStyle != kNormal_SkBlurStyle) { | 1108 if (fBlurStyle != kNormal_SkBlurStyle) { |
| 1113 return false; | 1109 return false; |
| 1114 } | 1110 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1129 return false; | 1125 return false; |
| 1130 } | 1126 } |
| 1131 | 1127 |
| 1132 grp->addCoverageFragmentProcessor(fp); | 1128 grp->addCoverageFragmentProcessor(fp); |
| 1133 | 1129 |
| 1134 SkMatrix inverse; | 1130 SkMatrix inverse; |
| 1135 if (!viewMatrix.invert(&inverse)) { | 1131 if (!viewMatrix.invert(&inverse)) { |
| 1136 return false; | 1132 return false; |
| 1137 } | 1133 } |
| 1138 | 1134 |
| 1139 drawContext->drawNonAARectWithLocalMatrix(rt, clip, *grp, SkMatrix::I(), pro
xyRect, inverse); | 1135 drawContext->drawNonAARectWithLocalMatrix(clip, *grp, SkMatrix::I(), proxyRe
ct, inverse); |
| 1140 return true; | 1136 return true; |
| 1141 } | 1137 } |
| 1142 | 1138 |
| 1143 bool SkBlurMaskFilterImpl::canFilterMaskGPU(const SkRRect& devRRect, | 1139 bool SkBlurMaskFilterImpl::canFilterMaskGPU(const SkRRect& devRRect, |
| 1144 const SkIRect& clipBounds, | 1140 const SkIRect& clipBounds, |
| 1145 const SkMatrix& ctm, | 1141 const SkMatrix& ctm, |
| 1146 SkRect* maskRect) const { | 1142 SkRect* maskRect) const { |
| 1147 SkScalar xformedSigma = this->computeXformedSigma(ctm); | 1143 SkScalar xformedSigma = this->computeXformedSigma(ctm); |
| 1148 if (xformedSigma <= 0) { | 1144 if (xformedSigma <= 0) { |
| 1149 return false; | 1145 return false; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 } else if (kSolid_SkBlurStyle == fBlurStyle) { | 1211 } else if (kSolid_SkBlurStyle == fBlurStyle) { |
| 1216 // solid: dst = src + dst - src * dst | 1212 // solid: dst = src + dst - src * dst |
| 1217 // = src + (1 - src) * dst | 1213 // = src + (1 - src) * dst |
| 1218 paint.setCoverageSetOpXPFactory(SkRegion::kUnion_Op); | 1214 paint.setCoverageSetOpXPFactory(SkRegion::kUnion_Op); |
| 1219 } else if (kOuter_SkBlurStyle == fBlurStyle) { | 1215 } else if (kOuter_SkBlurStyle == fBlurStyle) { |
| 1220 // outer: dst = dst * (1 - src) | 1216 // outer: dst = dst * (1 - src) |
| 1221 // = 0 * src + (1 - src) * dst | 1217 // = 0 * src + (1 - src) * dst |
| 1222 paint.setCoverageSetOpXPFactory(SkRegion::kDifference_Op); | 1218 paint.setCoverageSetOpXPFactory(SkRegion::kDifference_Op); |
| 1223 } | 1219 } |
| 1224 | 1220 |
| 1225 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext()); | 1221 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext((*result)->
asRenderTarget())); |
| 1226 if (!drawContext) { | 1222 if (!drawContext) { |
| 1227 return false; | 1223 return false; |
| 1228 } | 1224 } |
| 1229 | 1225 |
| 1230 drawContext->drawRect((*result)->asRenderTarget(), GrClip::WideOpen(), | 1226 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), clipRect
); |
| 1231 paint, SkMatrix::I(), clipRect); | |
| 1232 } | 1227 } |
| 1233 | 1228 |
| 1234 return true; | 1229 return true; |
| 1235 } | 1230 } |
| 1236 | 1231 |
| 1237 #endif // SK_SUPPORT_GPU | 1232 #endif // SK_SUPPORT_GPU |
| 1238 | 1233 |
| 1239 | 1234 |
| 1240 #ifndef SK_IGNORE_TO_STRING | 1235 #ifndef SK_IGNORE_TO_STRING |
| 1241 void SkBlurMaskFilterImpl::toString(SkString* str) const { | 1236 void SkBlurMaskFilterImpl::toString(SkString* str) const { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1262 } else { | 1257 } else { |
| 1263 str->append("None"); | 1258 str->append("None"); |
| 1264 } | 1259 } |
| 1265 str->append("))"); | 1260 str->append("))"); |
| 1266 } | 1261 } |
| 1267 #endif | 1262 #endif |
| 1268 | 1263 |
| 1269 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) | 1264 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
| 1270 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) | 1265 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
| 1271 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1266 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |