Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: src/effects/SkBlurMaskFilter.cpp

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

Powered by Google App Engine
This is Rietveld 408576698