| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&, | 43 virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&, |
| 44 SkIPoint* margin) const SK_OVERRIDE; | 44 SkIPoint* margin) const SK_OVERRIDE; |
| 45 | 45 |
| 46 #if SK_SUPPORT_GPU | 46 #if SK_SUPPORT_GPU |
| 47 virtual bool canFilterMaskGPU(const SkRect& devBounds, | 47 virtual bool canFilterMaskGPU(const SkRect& devBounds, |
| 48 const SkIRect& clipBounds, | 48 const SkIRect& clipBounds, |
| 49 const SkMatrix& ctm, | 49 const SkMatrix& ctm, |
| 50 SkRect* maskRect) const SK_OVERRIDE; | 50 SkRect* maskRect) const SK_OVERRIDE; |
| 51 virtual bool directFilterMaskGPU(GrContext* context, | 51 virtual bool directFilterMaskGPU(GrContext* context, |
| 52 GrPaint* grp, | 52 GrPaint* grp, |
| 53 const SkMatrix& viewMatrix, |
| 53 const SkStrokeRec& strokeRec, | 54 const SkStrokeRec& strokeRec, |
| 54 const SkPath& path) const SK_OVERRIDE; | 55 const SkPath& path) const SK_OVERRIDE; |
| 55 virtual bool directFilterRRectMaskGPU(GrContext* context, | 56 virtual bool directFilterRRectMaskGPU(GrContext* context, |
| 56 GrPaint* grp, | 57 GrPaint* grp, |
| 58 const SkMatrix& viewMatrix, |
| 57 const SkStrokeRec& strokeRec, | 59 const SkStrokeRec& strokeRec, |
| 58 const SkRRect& rrect) const SK_OVERRID
E; | 60 const SkRRect& rrect) const SK_OVERRID
E; |
| 59 | 61 |
| 60 virtual bool filterMaskGPU(GrTexture* src, | 62 virtual bool filterMaskGPU(GrTexture* src, |
| 61 const SkMatrix& ctm, | 63 const SkMatrix& ctm, |
| 62 const SkRect& maskRect, | 64 const SkRect& maskRect, |
| 63 GrTexture** result, | 65 GrTexture** result, |
| 64 bool canOverwriteSrc) const SK_OVERRIDE; | 66 bool canOverwriteSrc) const SK_OVERRIDE; |
| 65 #endif | 67 #endif |
| 66 | 68 |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 GrTexture**) { | 830 GrTexture**) { |
| 829 float sigma = random->nextRangeF(3,8); | 831 float sigma = random->nextRangeF(3,8); |
| 830 float width = random->nextRangeF(200,300); | 832 float width = random->nextRangeF(200,300); |
| 831 float height = random->nextRangeF(200,300); | 833 float height = random->nextRangeF(200,300); |
| 832 return GrRectBlurEffect::Create(context, SkRect::MakeWH(width, height), sigm
a); | 834 return GrRectBlurEffect::Create(context, SkRect::MakeWH(width, height), sigm
a); |
| 833 } | 835 } |
| 834 | 836 |
| 835 | 837 |
| 836 bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context, | 838 bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context, |
| 837 GrPaint* grp, | 839 GrPaint* grp, |
| 840 const SkMatrix& viewMatrix, |
| 838 const SkStrokeRec& strokeRec, | 841 const SkStrokeRec& strokeRec, |
| 839 const SkPath& path) const { | 842 const SkPath& path) const { |
| 840 if (fBlurStyle != kNormal_SkBlurStyle) { | 843 if (fBlurStyle != kNormal_SkBlurStyle) { |
| 841 return false; | 844 return false; |
| 842 } | 845 } |
| 843 | 846 |
| 844 SkRect rect; | 847 SkRect rect; |
| 845 if (!path.isRect(&rect)) { | 848 if (!path.isRect(&rect)) { |
| 846 return false; | 849 return false; |
| 847 } | 850 } |
| 848 | 851 |
| 849 if (!strokeRec.isFillStyle()) { | 852 if (!strokeRec.isFillStyle()) { |
| 850 return false; | 853 return false; |
| 851 } | 854 } |
| 852 | 855 |
| 853 SkMatrix ctm = context->getMatrix(); | 856 SkMatrix ctm = viewMatrix; |
| 854 SkScalar xformedSigma = this->computeXformedSigma(ctm); | 857 SkScalar xformedSigma = this->computeXformedSigma(ctm); |
| 855 | 858 |
| 856 int pad=SkScalarCeilToInt(6*xformedSigma)/2; | 859 int pad=SkScalarCeilToInt(6*xformedSigma)/2; |
| 857 rect.outset(SkIntToScalar(pad), SkIntToScalar(pad)); | 860 rect.outset(SkIntToScalar(pad), SkIntToScalar(pad)); |
| 858 | 861 |
| 859 SkAutoTUnref<GrFragmentProcessor> fp(GrRectBlurEffect::Create(context, rect,
xformedSigma)); | 862 SkAutoTUnref<GrFragmentProcessor> fp(GrRectBlurEffect::Create(context, rect,
xformedSigma)); |
| 860 if (!fp) { | 863 if (!fp) { |
| 861 return false; | 864 return false; |
| 862 } | 865 } |
| 863 | 866 |
| 864 GrContext::AutoMatrix am; | 867 if (!grp->localCoordChangeInverse(viewMatrix)) { |
| 865 if (!am.setIdentity(context, grp)) { | 868 return false; |
| 866 return false; | |
| 867 } | 869 } |
| 868 | 870 |
| 869 grp->addCoverageProcessor(fp); | 871 grp->addCoverageProcessor(fp); |
| 870 | 872 |
| 871 context->drawRect(*grp, rect); | 873 context->drawRect(*grp, SkMatrix::I(), rect); |
| 872 return true; | 874 return true; |
| 873 } | 875 } |
| 874 | 876 |
| 875 class GrRRectBlurEffect : public GrFragmentProcessor { | 877 class GrRRectBlurEffect : public GrFragmentProcessor { |
| 876 public: | 878 public: |
| 877 | 879 |
| 878 static GrFragmentProcessor* Create(GrContext* context, float sigma, const Sk
RRect&); | 880 static GrFragmentProcessor* Create(GrContext* context, float sigma, const Sk
RRect&); |
| 879 | 881 |
| 880 virtual ~GrRRectBlurEffect() {}; | 882 virtual ~GrRRectBlurEffect() {}; |
| 881 virtual const char* name() const SK_OVERRIDE { return "GrRRectBlur"; } | 883 virtual const char* name() const SK_OVERRIDE { return "GrRRectBlur"; } |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 void GrRRectBlurEffect::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBu
ilder* b) const { | 1117 void GrRRectBlurEffect::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBu
ilder* b) const { |
| 1116 GrGLRRectBlurEffect::GenKey(*this, caps, b); | 1118 GrGLRRectBlurEffect::GenKey(*this, caps, b); |
| 1117 } | 1119 } |
| 1118 | 1120 |
| 1119 GrGLFragmentProcessor* GrRRectBlurEffect::createGLInstance() const { | 1121 GrGLFragmentProcessor* GrRRectBlurEffect::createGLInstance() const { |
| 1120 return SkNEW_ARGS(GrGLRRectBlurEffect, (*this)); | 1122 return SkNEW_ARGS(GrGLRRectBlurEffect, (*this)); |
| 1121 } | 1123 } |
| 1122 | 1124 |
| 1123 bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context, | 1125 bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context, |
| 1124 GrPaint* grp, | 1126 GrPaint* grp, |
| 1127 const SkMatrix& viewMatrix, |
| 1125 const SkStrokeRec& strokeRec
, | 1128 const SkStrokeRec& strokeRec
, |
| 1126 const SkRRect& rrect) const
{ | 1129 const SkRRect& rrect) const
{ |
| 1127 if (fBlurStyle != kNormal_SkBlurStyle) { | 1130 if (fBlurStyle != kNormal_SkBlurStyle) { |
| 1128 return false; | 1131 return false; |
| 1129 } | 1132 } |
| 1130 | 1133 |
| 1131 if (!strokeRec.isFillStyle()) { | 1134 if (!strokeRec.isFillStyle()) { |
| 1132 return false; | 1135 return false; |
| 1133 } | 1136 } |
| 1134 | 1137 |
| 1135 SkRect proxy_rect = rrect.rect(); | 1138 SkRect proxy_rect = rrect.rect(); |
| 1136 SkMatrix ctm = context->getMatrix(); | 1139 SkMatrix ctm = viewMatrix; |
| 1137 SkScalar xformedSigma = this->computeXformedSigma(ctm); | 1140 SkScalar xformedSigma = this->computeXformedSigma(ctm); |
| 1138 float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f); | 1141 float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f); |
| 1139 proxy_rect.outset(extra, extra); | 1142 proxy_rect.outset(extra, extra); |
| 1140 | 1143 |
| 1141 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectBlurEffect::Create(context, xfor
medSigma, rrect)); | 1144 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectBlurEffect::Create(context, xfor
medSigma, rrect)); |
| 1142 if (!fp) { | 1145 if (!fp) { |
| 1143 return false; | 1146 return false; |
| 1144 } | 1147 } |
| 1145 | 1148 |
| 1146 GrContext::AutoMatrix am; | 1149 if (!grp->localCoordChangeInverse(viewMatrix)) { |
| 1147 if (!am.setIdentity(context, grp)) { | 1150 return false; |
| 1148 return false; | |
| 1149 } | 1151 } |
| 1150 | 1152 |
| 1151 grp->addCoverageProcessor(fp); | 1153 grp->addCoverageProcessor(fp); |
| 1152 | 1154 |
| 1153 context->drawRect(*grp, proxy_rect); | 1155 context->drawRect(*grp, SkMatrix::I(), proxy_rect); |
| 1154 return true; | 1156 return true; |
| 1155 } | 1157 } |
| 1156 | 1158 |
| 1157 bool SkBlurMaskFilterImpl::canFilterMaskGPU(const SkRect& srcBounds, | 1159 bool SkBlurMaskFilterImpl::canFilterMaskGPU(const SkRect& srcBounds, |
| 1158 const SkIRect& clipBounds, | 1160 const SkIRect& clipBounds, |
| 1159 const SkMatrix& ctm, | 1161 const SkMatrix& ctm, |
| 1160 SkRect* maskRect) const { | 1162 SkRect* maskRect) const { |
| 1161 SkScalar xformedSigma = this->computeXformedSigma(ctm); | 1163 SkScalar xformedSigma = this->computeXformedSigma(ctm); |
| 1162 if (xformedSigma <= 0) { | 1164 if (xformedSigma <= 0) { |
| 1163 return false; | 1165 return false; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 // If we're doing a normal blur, we can clobber the pathTexture in the | 1210 // If we're doing a normal blur, we can clobber the pathTexture in the |
| 1209 // gaussianBlur. Otherwise, we need to save it for later compositing. | 1211 // gaussianBlur. Otherwise, we need to save it for later compositing. |
| 1210 bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle); | 1212 bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle); |
| 1211 *result = SkGpuBlurUtils::GaussianBlur(context, src, isNormalBlur && canOver
writeSrc, | 1213 *result = SkGpuBlurUtils::GaussianBlur(context, src, isNormalBlur && canOver
writeSrc, |
| 1212 clipRect, false, xformedSigma, xforme
dSigma); | 1214 clipRect, false, xformedSigma, xforme
dSigma); |
| 1213 if (NULL == *result) { | 1215 if (NULL == *result) { |
| 1214 return false; | 1216 return false; |
| 1215 } | 1217 } |
| 1216 | 1218 |
| 1217 if (!isNormalBlur) { | 1219 if (!isNormalBlur) { |
| 1218 context->setIdentityMatrix(); | |
| 1219 GrPaint paint; | 1220 GrPaint paint; |
| 1220 SkMatrix matrix; | 1221 SkMatrix matrix; |
| 1221 matrix.setIDiv(src->width(), src->height()); | 1222 matrix.setIDiv(src->width(), src->height()); |
| 1222 // Blend pathTexture over blurTexture. | 1223 // Blend pathTexture over blurTexture. |
| 1223 GrContext::AutoRenderTarget art(context, (*result)->asRenderTarget()); | 1224 GrContext::AutoRenderTarget art(context, (*result)->asRenderTarget()); |
| 1224 paint.addColorProcessor(GrSimpleTextureEffect::Create(src, matrix))->unr
ef(); | 1225 paint.addColorProcessor(GrSimpleTextureEffect::Create(src, matrix))->unr
ef(); |
| 1225 if (kInner_SkBlurStyle == fBlurStyle) { | 1226 if (kInner_SkBlurStyle == fBlurStyle) { |
| 1226 // inner: dst = dst * src | 1227 // inner: dst = dst * src |
| 1227 paint.setPorterDuffXPFactory(kDC_GrBlendCoeff, kZero_GrBlendCoeff); | 1228 paint.setPorterDuffXPFactory(kDC_GrBlendCoeff, kZero_GrBlendCoeff); |
| 1228 } else if (kSolid_SkBlurStyle == fBlurStyle) { | 1229 } else if (kSolid_SkBlurStyle == fBlurStyle) { |
| 1229 // solid: dst = src + dst - src * dst | 1230 // solid: dst = src + dst - src * dst |
| 1230 // = (1 - dst) * src + 1 * dst | 1231 // = (1 - dst) * src + 1 * dst |
| 1231 paint.setPorterDuffXPFactory(kIDC_GrBlendCoeff, kOne_GrBlendCoeff); | 1232 paint.setPorterDuffXPFactory(kIDC_GrBlendCoeff, kOne_GrBlendCoeff); |
| 1232 } else if (kOuter_SkBlurStyle == fBlurStyle) { | 1233 } else if (kOuter_SkBlurStyle == fBlurStyle) { |
| 1233 // outer: dst = dst * (1 - src) | 1234 // outer: dst = dst * (1 - src) |
| 1234 // = 0 * src + (1 - src) * dst | 1235 // = 0 * src + (1 - src) * dst |
| 1235 paint.setPorterDuffXPFactory(kZero_GrBlendCoeff, kISC_GrBlendCoeff); | 1236 paint.setPorterDuffXPFactory(kZero_GrBlendCoeff, kISC_GrBlendCoeff); |
| 1236 } | 1237 } |
| 1237 context->drawRect(paint, clipRect); | 1238 context->drawRect(paint, SkMatrix::I(), clipRect); |
| 1238 } | 1239 } |
| 1239 | 1240 |
| 1240 return true; | 1241 return true; |
| 1241 } | 1242 } |
| 1242 | 1243 |
| 1243 #endif // SK_SUPPORT_GPU | 1244 #endif // SK_SUPPORT_GPU |
| 1244 | 1245 |
| 1245 | 1246 |
| 1246 #ifndef SK_IGNORE_TO_STRING | 1247 #ifndef SK_IGNORE_TO_STRING |
| 1247 void SkBlurMaskFilterImpl::toString(SkString* str) const { | 1248 void SkBlurMaskFilterImpl::toString(SkString* str) const { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1268 } else { | 1269 } else { |
| 1269 str->append("None"); | 1270 str->append("None"); |
| 1270 } | 1271 } |
| 1271 str->append("))"); | 1272 str->append("))"); |
| 1272 } | 1273 } |
| 1273 #endif | 1274 #endif |
| 1274 | 1275 |
| 1275 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) | 1276 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
| 1276 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) | 1277 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
| 1277 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1278 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |