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 30 matching lines...) Expand all Loading... |
41 SkMask::Format getFormat() const SK_OVERRIDE; | 41 SkMask::Format getFormat() const SK_OVERRIDE; |
42 virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&, | 42 virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&, |
43 SkIPoint* margin) const SK_OVERRIDE; | 43 SkIPoint* margin) const SK_OVERRIDE; |
44 | 44 |
45 #if SK_SUPPORT_GPU | 45 #if SK_SUPPORT_GPU |
46 virtual bool canFilterMaskGPU(const SkRect& devBounds, | 46 virtual bool canFilterMaskGPU(const SkRect& devBounds, |
47 const SkIRect& clipBounds, | 47 const SkIRect& clipBounds, |
48 const SkMatrix& ctm, | 48 const SkMatrix& ctm, |
49 SkRect* maskRect) const SK_OVERRIDE; | 49 SkRect* maskRect) const SK_OVERRIDE; |
50 virtual bool directFilterMaskGPU(GrContext* context, | 50 virtual bool directFilterMaskGPU(GrContext* context, |
| 51 GrRenderTarget* rt, |
51 GrPaint* grp, | 52 GrPaint* grp, |
52 const SkMatrix& viewMatrix, | 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, |
| 57 GrRenderTarget* rt, |
56 GrPaint* grp, | 58 GrPaint* grp, |
57 const SkMatrix& viewMatrix, | 59 const SkMatrix& viewMatrix, |
58 const SkStrokeRec& strokeRec, | 60 const SkStrokeRec& strokeRec, |
59 const SkRRect& rrect) const SK_OVERRID
E; | 61 const SkRRect& rrect) const SK_OVERRID
E; |
60 | 62 |
61 virtual bool filterMaskGPU(GrTexture* src, | 63 virtual bool filterMaskGPU(GrTexture* src, |
62 const SkMatrix& ctm, | 64 const SkMatrix& ctm, |
63 const SkRect& maskRect, | 65 const SkRect& maskRect, |
64 GrTexture** result, | 66 GrTexture** result, |
65 bool canOverwriteSrc) const SK_OVERRIDE; | 67 bool canOverwriteSrc) const SK_OVERRIDE; |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 const GrDrawTargetCaps&, | 821 const GrDrawTargetCaps&, |
820 GrTexture**) { | 822 GrTexture**) { |
821 float sigma = random->nextRangeF(3,8); | 823 float sigma = random->nextRangeF(3,8); |
822 float width = random->nextRangeF(200,300); | 824 float width = random->nextRangeF(200,300); |
823 float height = random->nextRangeF(200,300); | 825 float height = random->nextRangeF(200,300); |
824 return GrRectBlurEffect::Create(context, SkRect::MakeWH(width, height), sigm
a); | 826 return GrRectBlurEffect::Create(context, SkRect::MakeWH(width, height), sigm
a); |
825 } | 827 } |
826 | 828 |
827 | 829 |
828 bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context, | 830 bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context, |
| 831 GrRenderTarget* rt, |
829 GrPaint* grp, | 832 GrPaint* grp, |
830 const SkMatrix& viewMatrix, | 833 const SkMatrix& viewMatrix, |
831 const SkStrokeRec& strokeRec, | 834 const SkStrokeRec& strokeRec, |
832 const SkPath& path) const { | 835 const SkPath& path) const { |
833 if (fBlurStyle != kNormal_SkBlurStyle) { | 836 if (fBlurStyle != kNormal_SkBlurStyle) { |
834 return false; | 837 return false; |
835 } | 838 } |
836 | 839 |
837 SkRect rect; | 840 SkRect rect; |
838 if (!path.isRect(&rect)) { | 841 if (!path.isRect(&rect)) { |
(...skipping 14 matching lines...) Expand all Loading... |
853 if (!fp) { | 856 if (!fp) { |
854 return false; | 857 return false; |
855 } | 858 } |
856 | 859 |
857 grp->addCoverageProcessor(fp); | 860 grp->addCoverageProcessor(fp); |
858 | 861 |
859 SkMatrix inverse; | 862 SkMatrix inverse; |
860 if (!viewMatrix.invert(&inverse)) { | 863 if (!viewMatrix.invert(&inverse)) { |
861 return false; | 864 return false; |
862 } | 865 } |
863 context->drawNonAARectWithLocalMatrix(*grp, SkMatrix::I(), rect, inverse); | 866 context->drawNonAARectWithLocalMatrix(rt, *grp, SkMatrix::I(), rect, inverse
); |
864 return true; | 867 return true; |
865 } | 868 } |
866 | 869 |
867 class GrRRectBlurEffect : public GrFragmentProcessor { | 870 class GrRRectBlurEffect : public GrFragmentProcessor { |
868 public: | 871 public: |
869 | 872 |
870 static GrFragmentProcessor* Create(GrContext* context, float sigma, const Sk
RRect&); | 873 static GrFragmentProcessor* Create(GrContext* context, float sigma, const Sk
RRect&); |
871 | 874 |
872 virtual ~GrRRectBlurEffect() {}; | 875 virtual ~GrRRectBlurEffect() {}; |
873 const char* name() const SK_OVERRIDE { return "GrRRectBlur"; } | 876 const char* name() const SK_OVERRIDE { return "GrRRectBlur"; } |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 | 1111 |
1109 void GrRRectBlurEffect::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBu
ilder* b) const { | 1112 void GrRRectBlurEffect::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBu
ilder* b) const { |
1110 GrGLRRectBlurEffect::GenKey(*this, caps, b); | 1113 GrGLRRectBlurEffect::GenKey(*this, caps, b); |
1111 } | 1114 } |
1112 | 1115 |
1113 GrGLFragmentProcessor* GrRRectBlurEffect::createGLInstance() const { | 1116 GrGLFragmentProcessor* GrRRectBlurEffect::createGLInstance() const { |
1114 return SkNEW_ARGS(GrGLRRectBlurEffect, (*this)); | 1117 return SkNEW_ARGS(GrGLRRectBlurEffect, (*this)); |
1115 } | 1118 } |
1116 | 1119 |
1117 bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context, | 1120 bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context, |
| 1121 GrRenderTarget* rt, |
1118 GrPaint* grp, | 1122 GrPaint* grp, |
1119 const SkMatrix& viewMatrix, | 1123 const SkMatrix& viewMatrix, |
1120 const SkStrokeRec& strokeRec
, | 1124 const SkStrokeRec& strokeRec
, |
1121 const SkRRect& rrect) const
{ | 1125 const SkRRect& rrect) const
{ |
1122 if (fBlurStyle != kNormal_SkBlurStyle) { | 1126 if (fBlurStyle != kNormal_SkBlurStyle) { |
1123 return false; | 1127 return false; |
1124 } | 1128 } |
1125 | 1129 |
1126 if (!strokeRec.isFillStyle()) { | 1130 if (!strokeRec.isFillStyle()) { |
1127 return false; | 1131 return false; |
1128 } | 1132 } |
1129 | 1133 |
1130 SkRect proxy_rect = rrect.rect(); | 1134 SkRect proxy_rect = rrect.rect(); |
1131 SkMatrix ctm = viewMatrix; | 1135 SkMatrix ctm = viewMatrix; |
1132 SkScalar xformedSigma = this->computeXformedSigma(ctm); | 1136 SkScalar xformedSigma = this->computeXformedSigma(ctm); |
1133 float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f); | 1137 float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f); |
1134 proxy_rect.outset(extra, extra); | 1138 proxy_rect.outset(extra, extra); |
1135 | 1139 |
1136 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectBlurEffect::Create(context, xfor
medSigma, rrect)); | 1140 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectBlurEffect::Create(context, xfor
medSigma, rrect)); |
1137 if (!fp) { | 1141 if (!fp) { |
1138 return false; | 1142 return false; |
1139 } | 1143 } |
1140 | 1144 |
1141 grp->addCoverageProcessor(fp); | 1145 grp->addCoverageProcessor(fp); |
1142 | 1146 |
1143 SkMatrix inverse; | 1147 SkMatrix inverse; |
1144 if (!viewMatrix.invert(&inverse)) { | 1148 if (!viewMatrix.invert(&inverse)) { |
1145 return false; | 1149 return false; |
1146 } | 1150 } |
1147 context->drawNonAARectWithLocalMatrix(*grp, SkMatrix::I(), proxy_rect, inver
se); | 1151 context->drawNonAARectWithLocalMatrix(rt, *grp, SkMatrix::I(), proxy_rect, i
nverse); |
1148 return true; | 1152 return true; |
1149 } | 1153 } |
1150 | 1154 |
1151 bool SkBlurMaskFilterImpl::canFilterMaskGPU(const SkRect& srcBounds, | 1155 bool SkBlurMaskFilterImpl::canFilterMaskGPU(const SkRect& srcBounds, |
1152 const SkIRect& clipBounds, | 1156 const SkIRect& clipBounds, |
1153 const SkMatrix& ctm, | 1157 const SkMatrix& ctm, |
1154 SkRect* maskRect) const { | 1158 SkRect* maskRect) const { |
1155 SkScalar xformedSigma = this->computeXformedSigma(ctm); | 1159 SkScalar xformedSigma = this->computeXformedSigma(ctm); |
1156 if (xformedSigma <= 0) { | 1160 if (xformedSigma <= 0) { |
1157 return false; | 1161 return false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 | 1193 |
1190 bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src, | 1194 bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src, |
1191 const SkMatrix& ctm, | 1195 const SkMatrix& ctm, |
1192 const SkRect& maskRect, | 1196 const SkRect& maskRect, |
1193 GrTexture** result, | 1197 GrTexture** result, |
1194 bool canOverwriteSrc) const { | 1198 bool canOverwriteSrc) const { |
1195 SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height()); | 1199 SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height()); |
1196 | 1200 |
1197 GrContext* context = src->getContext(); | 1201 GrContext* context = src->getContext(); |
1198 | 1202 |
1199 GrContext::AutoWideOpenIdentityDraw awo(context, NULL); | 1203 GrContext::AutoWideOpenIdentityDraw awo(context); |
1200 | 1204 |
1201 SkScalar xformedSigma = this->computeXformedSigma(ctm); | 1205 SkScalar xformedSigma = this->computeXformedSigma(ctm); |
1202 SkASSERT(xformedSigma > 0); | 1206 SkASSERT(xformedSigma > 0); |
1203 | 1207 |
1204 // If we're doing a normal blur, we can clobber the pathTexture in the | 1208 // If we're doing a normal blur, we can clobber the pathTexture in the |
1205 // gaussianBlur. Otherwise, we need to save it for later compositing. | 1209 // gaussianBlur. Otherwise, we need to save it for later compositing. |
1206 bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle); | 1210 bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle); |
1207 *result = SkGpuBlurUtils::GaussianBlur(context, src, isNormalBlur && canOver
writeSrc, | 1211 *result = SkGpuBlurUtils::GaussianBlur(context, src, isNormalBlur && canOver
writeSrc, |
1208 clipRect, false, xformedSigma, xforme
dSigma); | 1212 clipRect, false, xformedSigma, xforme
dSigma); |
1209 if (NULL == *result) { | 1213 if (NULL == *result) { |
1210 return false; | 1214 return false; |
1211 } | 1215 } |
1212 | 1216 |
1213 if (!isNormalBlur) { | 1217 if (!isNormalBlur) { |
1214 GrPaint paint; | 1218 GrPaint paint; |
1215 SkMatrix matrix; | 1219 SkMatrix matrix; |
1216 matrix.setIDiv(src->width(), src->height()); | 1220 matrix.setIDiv(src->width(), src->height()); |
1217 // Blend pathTexture over blurTexture. | 1221 // Blend pathTexture over blurTexture. |
1218 GrContext::AutoRenderTarget art(context, (*result)->asRenderTarget()); | |
1219 paint.addCoverageProcessor(GrSimpleTextureEffect::Create(src, matrix))->
unref(); | 1222 paint.addCoverageProcessor(GrSimpleTextureEffect::Create(src, matrix))->
unref(); |
1220 if (kInner_SkBlurStyle == fBlurStyle) { | 1223 if (kInner_SkBlurStyle == fBlurStyle) { |
1221 // inner: dst = dst * src | 1224 // inner: dst = dst * src |
1222 paint.setCoverageSetOpXPFactory(SkRegion::kIntersect_Op); | 1225 paint.setCoverageSetOpXPFactory(SkRegion::kIntersect_Op); |
1223 } else if (kSolid_SkBlurStyle == fBlurStyle) { | 1226 } else if (kSolid_SkBlurStyle == fBlurStyle) { |
1224 // solid: dst = src + dst - src * dst | 1227 // solid: dst = src + dst - src * dst |
1225 // = src + (1 - src) * dst | 1228 // = src + (1 - src) * dst |
1226 paint.setCoverageSetOpXPFactory(SkRegion::kUnion_Op); | 1229 paint.setCoverageSetOpXPFactory(SkRegion::kUnion_Op); |
1227 } else if (kOuter_SkBlurStyle == fBlurStyle) { | 1230 } else if (kOuter_SkBlurStyle == fBlurStyle) { |
1228 // outer: dst = dst * (1 - src) | 1231 // outer: dst = dst * (1 - src) |
1229 // = 0 * src + (1 - src) * dst | 1232 // = 0 * src + (1 - src) * dst |
1230 paint.setCoverageSetOpXPFactory(SkRegion::kDifference_Op); | 1233 paint.setCoverageSetOpXPFactory(SkRegion::kDifference_Op); |
1231 } | 1234 } |
1232 context->drawRect(paint, SkMatrix::I(), clipRect); | 1235 context->drawRect((*result)->asRenderTarget(), paint, SkMatrix::I(), cli
pRect); |
1233 } | 1236 } |
1234 | 1237 |
1235 return true; | 1238 return true; |
1236 } | 1239 } |
1237 | 1240 |
1238 #endif // SK_SUPPORT_GPU | 1241 #endif // SK_SUPPORT_GPU |
1239 | 1242 |
1240 | 1243 |
1241 #ifndef SK_IGNORE_TO_STRING | 1244 #ifndef SK_IGNORE_TO_STRING |
1242 void SkBlurMaskFilterImpl::toString(SkString* str) const { | 1245 void SkBlurMaskFilterImpl::toString(SkString* str) const { |
(...skipping 20 matching lines...) Expand all Loading... |
1263 } else { | 1266 } else { |
1264 str->append("None"); | 1267 str->append("None"); |
1265 } | 1268 } |
1266 str->append("))"); | 1269 str->append("))"); |
1267 } | 1270 } |
1268 #endif | 1271 #endif |
1269 | 1272 |
1270 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) | 1273 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
1271 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) | 1274 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
1272 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1275 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |