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 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 GrRenderTarget* rt, |
52 GrPaint* grp, | 52 GrPaint* grp, |
53 const GrClip&, | |
54 const SkMatrix& viewMatrix, | 53 const SkMatrix& viewMatrix, |
55 const SkStrokeRec& strokeRec, | 54 const SkStrokeRec& strokeRec, |
56 const SkPath& path) const SK_OVERRIDE; | 55 const SkPath& path) const SK_OVERRIDE; |
57 virtual bool directFilterRRectMaskGPU(GrContext* context, | 56 virtual bool directFilterRRectMaskGPU(GrContext* context, |
58 GrRenderTarget* rt, | 57 GrRenderTarget* rt, |
59 GrPaint* grp, | 58 GrPaint* grp, |
60 const GrClip&, | |
61 const SkMatrix& viewMatrix, | 59 const SkMatrix& viewMatrix, |
62 const SkStrokeRec& strokeRec, | 60 const SkStrokeRec& strokeRec, |
63 const SkRRect& rrect) const SK_OVERRID
E; | 61 const SkRRect& rrect) const SK_OVERRID
E; |
64 | 62 |
65 virtual bool filterMaskGPU(GrTexture* src, | 63 virtual bool filterMaskGPU(GrTexture* src, |
66 const SkMatrix& ctm, | 64 const SkMatrix& ctm, |
67 const SkRect& maskRect, | 65 const SkRect& maskRect, |
68 GrTexture** result, | 66 GrTexture** result, |
69 bool canOverwriteSrc) const SK_OVERRIDE; | 67 bool canOverwriteSrc) const SK_OVERRIDE; |
70 #endif | 68 #endif |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 float sigma = random->nextRangeF(3,8); | 823 float sigma = random->nextRangeF(3,8); |
826 float width = random->nextRangeF(200,300); | 824 float width = random->nextRangeF(200,300); |
827 float height = random->nextRangeF(200,300); | 825 float height = random->nextRangeF(200,300); |
828 return GrRectBlurEffect::Create(context, SkRect::MakeWH(width, height), sigm
a); | 826 return GrRectBlurEffect::Create(context, SkRect::MakeWH(width, height), sigm
a); |
829 } | 827 } |
830 | 828 |
831 | 829 |
832 bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context, | 830 bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context, |
833 GrRenderTarget* rt, | 831 GrRenderTarget* rt, |
834 GrPaint* grp, | 832 GrPaint* grp, |
835 const GrClip& clip, | |
836 const SkMatrix& viewMatrix, | 833 const SkMatrix& viewMatrix, |
837 const SkStrokeRec& strokeRec, | 834 const SkStrokeRec& strokeRec, |
838 const SkPath& path) const { | 835 const SkPath& path) const { |
839 if (fBlurStyle != kNormal_SkBlurStyle) { | 836 if (fBlurStyle != kNormal_SkBlurStyle) { |
840 return false; | 837 return false; |
841 } | 838 } |
842 | 839 |
843 SkRect rect; | 840 SkRect rect; |
844 if (!path.isRect(&rect)) { | 841 if (!path.isRect(&rect)) { |
845 return false; | 842 return false; |
(...skipping 13 matching lines...) Expand all Loading... |
859 if (!fp) { | 856 if (!fp) { |
860 return false; | 857 return false; |
861 } | 858 } |
862 | 859 |
863 grp->addCoverageProcessor(fp); | 860 grp->addCoverageProcessor(fp); |
864 | 861 |
865 SkMatrix inverse; | 862 SkMatrix inverse; |
866 if (!viewMatrix.invert(&inverse)) { | 863 if (!viewMatrix.invert(&inverse)) { |
867 return false; | 864 return false; |
868 } | 865 } |
869 context->drawNonAARectWithLocalMatrix(rt, clip, *grp, SkMatrix::I(), rect, i
nverse); | 866 context->drawNonAARectWithLocalMatrix(rt, *grp, SkMatrix::I(), rect, inverse
); |
870 return true; | 867 return true; |
871 } | 868 } |
872 | 869 |
873 class GrRRectBlurEffect : public GrFragmentProcessor { | 870 class GrRRectBlurEffect : public GrFragmentProcessor { |
874 public: | 871 public: |
875 | 872 |
876 static GrFragmentProcessor* Create(GrContext* context, float sigma, const Sk
RRect&); | 873 static GrFragmentProcessor* Create(GrContext* context, float sigma, const Sk
RRect&); |
877 | 874 |
878 virtual ~GrRRectBlurEffect() {}; | 875 virtual ~GrRRectBlurEffect() {}; |
879 const char* name() const SK_OVERRIDE { return "GrRRectBlur"; } | 876 const char* name() const SK_OVERRIDE { return "GrRRectBlur"; } |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 GrGLRRectBlurEffect::GenKey(*this, caps, b); | 1113 GrGLRRectBlurEffect::GenKey(*this, caps, b); |
1117 } | 1114 } |
1118 | 1115 |
1119 GrGLFragmentProcessor* GrRRectBlurEffect::createGLInstance() const { | 1116 GrGLFragmentProcessor* GrRRectBlurEffect::createGLInstance() const { |
1120 return SkNEW_ARGS(GrGLRRectBlurEffect, (*this)); | 1117 return SkNEW_ARGS(GrGLRRectBlurEffect, (*this)); |
1121 } | 1118 } |
1122 | 1119 |
1123 bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context, | 1120 bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context, |
1124 GrRenderTarget* rt, | 1121 GrRenderTarget* rt, |
1125 GrPaint* grp, | 1122 GrPaint* grp, |
1126 const GrClip& clip, | |
1127 const SkMatrix& viewMatrix, | 1123 const SkMatrix& viewMatrix, |
1128 const SkStrokeRec& strokeRec
, | 1124 const SkStrokeRec& strokeRec
, |
1129 const SkRRect& rrect) const
{ | 1125 const SkRRect& rrect) const
{ |
1130 if (fBlurStyle != kNormal_SkBlurStyle) { | 1126 if (fBlurStyle != kNormal_SkBlurStyle) { |
1131 return false; | 1127 return false; |
1132 } | 1128 } |
1133 | 1129 |
1134 if (!strokeRec.isFillStyle()) { | 1130 if (!strokeRec.isFillStyle()) { |
1135 return false; | 1131 return false; |
1136 } | 1132 } |
1137 | 1133 |
1138 SkRect proxy_rect = rrect.rect(); | 1134 SkRect proxy_rect = rrect.rect(); |
1139 SkMatrix ctm = viewMatrix; | 1135 SkMatrix ctm = viewMatrix; |
1140 SkScalar xformedSigma = this->computeXformedSigma(ctm); | 1136 SkScalar xformedSigma = this->computeXformedSigma(ctm); |
1141 float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f); | 1137 float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f); |
1142 proxy_rect.outset(extra, extra); | 1138 proxy_rect.outset(extra, extra); |
1143 | 1139 |
1144 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectBlurEffect::Create(context, xfor
medSigma, rrect)); | 1140 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectBlurEffect::Create(context, xfor
medSigma, rrect)); |
1145 if (!fp) { | 1141 if (!fp) { |
1146 return false; | 1142 return false; |
1147 } | 1143 } |
1148 | 1144 |
1149 grp->addCoverageProcessor(fp); | 1145 grp->addCoverageProcessor(fp); |
1150 | 1146 |
1151 SkMatrix inverse; | 1147 SkMatrix inverse; |
1152 if (!viewMatrix.invert(&inverse)) { | 1148 if (!viewMatrix.invert(&inverse)) { |
1153 return false; | 1149 return false; |
1154 } | 1150 } |
1155 context->drawNonAARectWithLocalMatrix(rt, clip, *grp, SkMatrix::I(), proxy_r
ect, inverse); | 1151 context->drawNonAARectWithLocalMatrix(rt, *grp, SkMatrix::I(), proxy_rect, i
nverse); |
1156 return true; | 1152 return true; |
1157 } | 1153 } |
1158 | 1154 |
1159 bool SkBlurMaskFilterImpl::canFilterMaskGPU(const SkRect& srcBounds, | 1155 bool SkBlurMaskFilterImpl::canFilterMaskGPU(const SkRect& srcBounds, |
1160 const SkIRect& clipBounds, | 1156 const SkIRect& clipBounds, |
1161 const SkMatrix& ctm, | 1157 const SkMatrix& ctm, |
1162 SkRect* maskRect) const { | 1158 SkRect* maskRect) const { |
1163 SkScalar xformedSigma = this->computeXformedSigma(ctm); | 1159 SkScalar xformedSigma = this->computeXformedSigma(ctm); |
1164 if (xformedSigma <= 0) { | 1160 if (xformedSigma <= 0) { |
1165 return false; | 1161 return false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 | 1193 |
1198 bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src, | 1194 bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src, |
1199 const SkMatrix& ctm, | 1195 const SkMatrix& ctm, |
1200 const SkRect& maskRect, | 1196 const SkRect& maskRect, |
1201 GrTexture** result, | 1197 GrTexture** result, |
1202 bool canOverwriteSrc) const { | 1198 bool canOverwriteSrc) const { |
1203 SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height()); | 1199 SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height()); |
1204 | 1200 |
1205 GrContext* context = src->getContext(); | 1201 GrContext* context = src->getContext(); |
1206 | 1202 |
| 1203 GrContext::AutoWideOpenIdentityDraw awo(context); |
| 1204 |
1207 SkScalar xformedSigma = this->computeXformedSigma(ctm); | 1205 SkScalar xformedSigma = this->computeXformedSigma(ctm); |
1208 SkASSERT(xformedSigma > 0); | 1206 SkASSERT(xformedSigma > 0); |
1209 | 1207 |
1210 // 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 |
1211 // gaussianBlur. Otherwise, we need to save it for later compositing. | 1209 // gaussianBlur. Otherwise, we need to save it for later compositing. |
1212 bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle); | 1210 bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle); |
1213 *result = SkGpuBlurUtils::GaussianBlur(context, src, isNormalBlur && canOver
writeSrc, | 1211 *result = SkGpuBlurUtils::GaussianBlur(context, src, isNormalBlur && canOver
writeSrc, |
1214 clipRect, false, xformedSigma, xforme
dSigma); | 1212 clipRect, false, xformedSigma, xforme
dSigma); |
1215 if (NULL == *result) { | 1213 if (NULL == *result) { |
1216 return false; | 1214 return false; |
(...skipping 10 matching lines...) Expand all Loading... |
1227 paint.setCoverageSetOpXPFactory(SkRegion::kIntersect_Op); | 1225 paint.setCoverageSetOpXPFactory(SkRegion::kIntersect_Op); |
1228 } else if (kSolid_SkBlurStyle == fBlurStyle) { | 1226 } else if (kSolid_SkBlurStyle == fBlurStyle) { |
1229 // solid: dst = src + dst - src * dst | 1227 // solid: dst = src + dst - src * dst |
1230 // = src + (1 - src) * dst | 1228 // = src + (1 - src) * dst |
1231 paint.setCoverageSetOpXPFactory(SkRegion::kUnion_Op); | 1229 paint.setCoverageSetOpXPFactory(SkRegion::kUnion_Op); |
1232 } else if (kOuter_SkBlurStyle == fBlurStyle) { | 1230 } else if (kOuter_SkBlurStyle == fBlurStyle) { |
1233 // outer: dst = dst * (1 - src) | 1231 // outer: dst = dst * (1 - src) |
1234 // = 0 * src + (1 - src) * dst | 1232 // = 0 * src + (1 - src) * dst |
1235 paint.setCoverageSetOpXPFactory(SkRegion::kDifference_Op); | 1233 paint.setCoverageSetOpXPFactory(SkRegion::kDifference_Op); |
1236 } | 1234 } |
1237 context->drawRect((*result)->asRenderTarget(), GrClip::WideOpen(), paint
, SkMatrix::I(), | 1235 context->drawRect((*result)->asRenderTarget(), paint, SkMatrix::I(), cli
pRect); |
1238 clipRect); | |
1239 } | 1236 } |
1240 | 1237 |
1241 return true; | 1238 return true; |
1242 } | 1239 } |
1243 | 1240 |
1244 #endif // SK_SUPPORT_GPU | 1241 #endif // SK_SUPPORT_GPU |
1245 | 1242 |
1246 | 1243 |
1247 #ifndef SK_IGNORE_TO_STRING | 1244 #ifndef SK_IGNORE_TO_STRING |
1248 void SkBlurMaskFilterImpl::toString(SkString* str) const { | 1245 void SkBlurMaskFilterImpl::toString(SkString* str) const { |
(...skipping 20 matching lines...) Expand all Loading... |
1269 } else { | 1266 } else { |
1270 str->append("None"); | 1267 str->append("None"); |
1271 } | 1268 } |
1272 str->append("))"); | 1269 str->append("))"); |
1273 } | 1270 } |
1274 #endif | 1271 #endif |
1275 | 1272 |
1276 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) | 1273 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
1277 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) | 1274 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
1278 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1275 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |