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

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

Issue 2243133002: Pull handling of blurred circles out of GrRRectBlurEffect::Make (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clean up Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBlurMaskFilter.h" 8 #include "SkBlurMaskFilter.h"
9 #include "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkGpuBlurUtils.h" 10 #include "SkGpuBlurUtils.h"
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 size.f Height), 1046 size.f Height),
1047 nullptr, 1047 nullptr,
1048 sigma, sigma, SkBackin gFit::kExact)); 1048 sigma, sigma, SkBackin gFit::kExact));
1049 if (!dc2) { 1049 if (!dc2) {
1050 return nullptr; 1050 return nullptr;
1051 } 1051 }
1052 1052
1053 return dc2->asTexture(); 1053 return dc2->asTexture();
1054 } 1054 }
1055 1055
1056 sk_sp<GrFragmentProcessor> GrRRectBlurEffect::Make(GrContext* context, float sig ma, 1056 sk_sp<GrFragmentProcessor> GrRRectBlurEffect::Make(GrContext* context,
1057 const SkRRect& rrect) { 1057 float xformedSigma,
1058 if (rrect.isCircle()) { 1058 const SkRRect& devRRect) {
1059 return GrCircleBlurFragmentProcessor::Make(context->textureProvider(), 1059 SkASSERT(!devRRect.isCircle()); // Should've been caught up-stream
1060 rrect.rect(), sigma);
1061 }
1062 1060
1063 // TODO: loosen this up 1061 // TODO: loosen this up
1064 if (!rrect.isSimpleCircular()) { 1062 if (!devRRect.isSimpleCircular()) {
1065 return nullptr; 1063 return nullptr;
1066 } 1064 }
1067 1065
1068 // Make sure we can successfully ninepatch this rrect -- the blur sigma has to be 1066 // Make sure we can successfully ninepatch this rrect -- the blur sigma has to be
1069 // sufficiently small relative to both the size of the corner radius and the 1067 // sufficiently small relative to both the size of the corner radius and the
1070 // width (and height) of the rrect. 1068 // width (and height) of the rrect.
1071 1069
1072 unsigned int blurRadius = 3*SkScalarCeilToInt(sigma-1/6.0f); 1070 unsigned int blurRadius = 3*SkScalarCeilToInt(xformedSigma-1/6.0f);
1073 unsigned int cornerRadius = SkScalarCeilToInt(rrect.getSimpleRadii().x()); 1071 unsigned int cornerRadius = SkScalarCeilToInt(devRRect.getSimpleRadii().x()) ;
1074 if (cornerRadius + blurRadius > rrect.width()/2 || 1072 if (cornerRadius + blurRadius > devRRect.width()/2 ||
1075 cornerRadius + blurRadius > rrect.height()/2) { 1073 cornerRadius + blurRadius > devRRect.height()/2) {
1076 return nullptr; 1074 return nullptr;
1077 } 1075 }
1078 1076
1079 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); 1077 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
1080 GrUniqueKey key; 1078 GrUniqueKey key;
1081 GrUniqueKey::Builder builder(&key, kDomain, 2); 1079 GrUniqueKey::Builder builder(&key, kDomain, 2);
1082 builder[0] = blurRadius; 1080 builder[0] = blurRadius;
1083 builder[1] = cornerRadius; 1081 builder[1] = cornerRadius;
1084 builder.finish(); 1082 builder.finish();
1085 1083
1086 sk_sp<GrTexture> blurNinePatchTexture( 1084 sk_sp<GrTexture> blurNinePatchTexture(
1087 context->textureProvider()->findAndRefTextureByU niqueKey(key)); 1085 context->textureProvider()->findAndRefTextureByU niqueKey(key));
1088 1086
1089 if (!blurNinePatchTexture) { 1087 if (!blurNinePatchTexture) {
1090 blurNinePatchTexture = make_rrect_blur_mask(context, rrect, sigma, true) ; 1088 blurNinePatchTexture = make_rrect_blur_mask(context, devRRect, xformedSi gma, true);
1091 if (!blurNinePatchTexture) { 1089 if (!blurNinePatchTexture) {
1092 return nullptr; 1090 return nullptr;
1093 } 1091 }
1094 context->textureProvider()->assignUniqueKeyToTexture(key, blurNinePatchT exture.get()); 1092 context->textureProvider()->assignUniqueKeyToTexture(key, blurNinePatchT exture.get());
1095 } 1093 }
1096 return sk_sp<GrFragmentProcessor>(new GrRRectBlurEffect(sigma, rrect, blurNi nePatchTexture.get())); 1094 return sk_sp<GrFragmentProcessor>(new GrRRectBlurEffect(xformedSigma, devRRe ct,
1095 blurNinePatchTexture .get()));
1097 } 1096 }
1098 1097
1099 void GrRRectBlurEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { 1098 void GrRRectBlurEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const {
1100 inout->mulByUnknownSingleComponent(); 1099 inout->mulByUnknownSingleComponent();
1101 } 1100 }
1102 1101
1103 GrRRectBlurEffect::GrRRectBlurEffect(float sigma, const SkRRect& rrect, GrTextur e *ninePatchTexture) 1102 GrRRectBlurEffect::GrRRectBlurEffect(float sigma, const SkRRect& rrect, GrTextur e *ninePatchTexture)
1104 : fRRect(rrect), 1103 : fRRect(rrect),
1105 fSigma(sigma), 1104 fSigma(sigma),
1106 fNinePatchAccess(ninePatchTexture) { 1105 fNinePatchAccess(ninePatchTexture) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 if (fBlurStyle != kNormal_SkBlurStyle) { 1242 if (fBlurStyle != kNormal_SkBlurStyle) {
1244 return false; 1243 return false;
1245 } 1244 }
1246 1245
1247 if (!strokeRec.isFillStyle()) { 1246 if (!strokeRec.isFillStyle()) {
1248 return false; 1247 return false;
1249 } 1248 }
1250 1249
1251 SkScalar xformedSigma = this->computeXformedSigma(viewMatrix); 1250 SkScalar xformedSigma = this->computeXformedSigma(viewMatrix);
1252 1251
1252 if (devRRect.isCircle()) {
1253 sk_sp<GrFragmentProcessor> fp(GrCircleBlurFragmentProcessor::Make(
1254 context- >textureProvider(),
1255 devRRect .rect(),
1256 xformedS igma));
1257 if (!fp) {
1258 return false;
1259 }
1260
1261 GrPaint newPaint(*grp);
1262 newPaint.addCoverageFragmentProcessor(std::move(fp));
1263 newPaint.setAntiAlias(false);
1264
1265 SkRect srcProxyRect = srcRRect.rect();
1266 srcProxyRect.outset(3.0f*fSigma, 3.0f*fSigma);
1267
1268 drawContext->drawRect(clip, newPaint, viewMatrix, srcProxyRect);
1269 return true;
1270 }
1271
1253 sk_sp<GrFragmentProcessor> fp(GrRRectBlurEffect::Make(context, xformedSigma, devRRect)); 1272 sk_sp<GrFragmentProcessor> fp(GrRRectBlurEffect::Make(context, xformedSigma, devRRect));
1254 if (!fp) { 1273 if (!fp) {
1255 return false; 1274 return false;
1256 } 1275 }
1257 1276
1258 GrPaint newPaint(*grp); 1277 GrPaint newPaint(*grp);
1259 newPaint.addCoverageFragmentProcessor(std::move(fp)); 1278 newPaint.addCoverageFragmentProcessor(std::move(fp));
1260 newPaint.setAntiAlias(false); 1279 newPaint.setAntiAlias(false);
1261 1280
1262 if (!this->ignoreXform()) { 1281 if (!this->ignoreXform()) {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 } else { 1447 } else {
1429 str->append("None"); 1448 str->append("None");
1430 } 1449 }
1431 str->append("))"); 1450 str->append("))");
1432 } 1451 }
1433 #endif 1452 #endif
1434 1453
1435 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) 1454 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter)
1436 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) 1455 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl)
1437 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1456 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698