OLD | NEW |
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 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height()); | 1241 SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height()); |
1242 | 1242 |
1243 GrContext* context = src->getContext(); | 1243 GrContext* context = src->getContext(); |
1244 | 1244 |
1245 SkScalar xformedSigma = this->computeXformedSigma(ctm); | 1245 SkScalar xformedSigma = this->computeXformedSigma(ctm); |
1246 SkASSERT(xformedSigma > 0); | 1246 SkASSERT(xformedSigma > 0); |
1247 | 1247 |
1248 // If we're doing a normal blur, we can clobber the pathTexture in the | 1248 // If we're doing a normal blur, we can clobber the pathTexture in the |
1249 // gaussianBlur. Otherwise, we need to save it for later compositing. | 1249 // gaussianBlur. Otherwise, we need to save it for later compositing. |
1250 bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle); | 1250 bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle); |
1251 *result = SkGpuBlurUtils::GaussianBlur(context, src, isNormalBlur && canOver
writeSrc, | 1251 sk_sp<GrDrawContext> drawContext(SkGpuBlurUtils::GaussianBlur(context, src, |
1252 clipRect, nullptr, | 1252 isNormalBlur &
& canOverwriteSrc, |
1253 xformedSigma, xformedSigma); | 1253 clipRect, null
ptr, |
1254 if (nullptr == *result) { | 1254 xformedSigma,
xformedSigma)); |
| 1255 if (!drawContext) { |
1255 return false; | 1256 return false; |
1256 } | 1257 } |
1257 | 1258 |
1258 if (!isNormalBlur) { | 1259 if (!isNormalBlur) { |
1259 GrPaint paint; | 1260 GrPaint paint; |
1260 SkMatrix matrix; | 1261 SkMatrix matrix; |
1261 matrix.setIDiv(src->width(), src->height()); | 1262 matrix.setIDiv(src->width(), src->height()); |
1262 // Blend pathTexture over blurTexture. | 1263 // Blend pathTexture over blurTexture. |
1263 paint.addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(src, ma
trix))->unref(); | 1264 paint.addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(src, ma
trix))->unref(); |
1264 if (kInner_SkBlurStyle == fBlurStyle) { | 1265 if (kInner_SkBlurStyle == fBlurStyle) { |
1265 // inner: dst = dst * src | 1266 // inner: dst = dst * src |
1266 paint.setCoverageSetOpXPFactory(SkRegion::kIntersect_Op); | 1267 paint.setCoverageSetOpXPFactory(SkRegion::kIntersect_Op); |
1267 } else if (kSolid_SkBlurStyle == fBlurStyle) { | 1268 } else if (kSolid_SkBlurStyle == fBlurStyle) { |
1268 // solid: dst = src + dst - src * dst | 1269 // solid: dst = src + dst - src * dst |
1269 // = src + (1 - src) * dst | 1270 // = src + (1 - src) * dst |
1270 paint.setCoverageSetOpXPFactory(SkRegion::kUnion_Op); | 1271 paint.setCoverageSetOpXPFactory(SkRegion::kUnion_Op); |
1271 } else if (kOuter_SkBlurStyle == fBlurStyle) { | 1272 } else if (kOuter_SkBlurStyle == fBlurStyle) { |
1272 // outer: dst = dst * (1 - src) | 1273 // outer: dst = dst * (1 - src) |
1273 // = 0 * src + (1 - src) * dst | 1274 // = 0 * src + (1 - src) * dst |
1274 paint.setCoverageSetOpXPFactory(SkRegion::kDifference_Op); | 1275 paint.setCoverageSetOpXPFactory(SkRegion::kDifference_Op); |
1275 } else { | 1276 } else { |
1276 paint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); | 1277 paint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); |
1277 } | 1278 } |
1278 | 1279 |
1279 sk_sp<GrDrawContext> drawContext( | |
1280 context->drawContext(sk_ref_sp((*result)->as
RenderTarget()))); | |
1281 if (!drawContext) { | |
1282 return false; | |
1283 } | |
1284 | |
1285 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), clipRect
); | 1280 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), clipRect
); |
1286 } | 1281 } |
1287 | 1282 |
| 1283 *result = drawContext->asTexture().release(); |
1288 return true; | 1284 return true; |
1289 } | 1285 } |
1290 | 1286 |
1291 #endif // SK_SUPPORT_GPU | 1287 #endif // SK_SUPPORT_GPU |
1292 | 1288 |
1293 | 1289 |
1294 #ifndef SK_IGNORE_TO_STRING | 1290 #ifndef SK_IGNORE_TO_STRING |
1295 void SkBlurMaskFilterImpl::toString(SkString* str) const { | 1291 void SkBlurMaskFilterImpl::toString(SkString* str) const { |
1296 str->append("SkBlurMaskFilterImpl: ("); | 1292 str->append("SkBlurMaskFilterImpl: ("); |
1297 | 1293 |
(...skipping 18 matching lines...) Expand all Loading... |
1316 } else { | 1312 } else { |
1317 str->append("None"); | 1313 str->append("None"); |
1318 } | 1314 } |
1319 str->append("))"); | 1315 str->append("))"); |
1320 } | 1316 } |
1321 #endif | 1317 #endif |
1322 | 1318 |
1323 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) | 1319 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
1324 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) | 1320 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
1325 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1321 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |