diff options
author | 2012-01-18 20:34:00 +0000 | |
---|---|---|
committer | 2012-01-18 20:34:00 +0000 | |
commit | dd1be60702b3622f49d97651e31d13eaf2175cf8 (patch) | |
tree | ac2d2b26d2c9f6054acefd627efb64d6f1c93c09 /src/core | |
parent | 376cd1f919cf79dd4f481da063bdd6b656df4279 (diff) |
Pull xfer mode test out of generic draw-as-hairline test. Use coverage rather than alpha to draw hairlines < 1pix wide in GPU.
Review URL: http://codereview.appspot.com/5528112/
git-svn-id: http://skia.googlecode.com/svn/trunk@3070 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkDraw.cpp | 49 | ||||
-rw-r--r-- | src/core/SkDrawProcs.h | 11 |
2 files changed, 32 insertions, 28 deletions
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index d1b291fd11..23a6d59944 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -860,14 +860,14 @@ static bool xfermodeSupportsCoverageAsAlpha(SkXfermode* xfer) { } bool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix, - SkAlpha* newAlpha) { - SkASSERT(newAlpha); + SkScalar* coverage) { + SkASSERT(coverage); if (SkPaint::kStroke_Style != paint.getStyle()) { return false; } SkScalar strokeWidth = paint.getStrokeWidth(); if (0 == strokeWidth) { - *newAlpha = paint.getAlpha(); + *coverage = SK_Scalar1; return true; } @@ -877,9 +877,6 @@ bool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix, if (!paint.isAntiAlias()) { return false; } - if (!xfermodeSupportsCoverageAsAlpha(paint.getXfermode())) { - return false; - } if (matrix.hasPerspective()) { return false; } @@ -891,16 +888,7 @@ bool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix, SkScalar len0 = fast_len(dst[0]); SkScalar len1 = fast_len(dst[1]); if (len0 <= SK_Scalar1 && len1 <= SK_Scalar1) { - SkScalar modulate = SkScalarAve(len0, len1); -#if 0 - *newAlpha = SkToU8(SkScalarRoundToInt(modulate * paint.getAlpha())); -#else - // this is the old technique, which we preserve for now so we don't - // change previous results (testing) - // the new way seems fine, its just (a tiny bit) different - int scale = (int)SkScalarMul(modulate, 256); - *newAlpha = paint.getAlpha() * scale >> 8; -#endif + *coverage = SkScalarAve(len0, len1); return true; } return false; @@ -947,12 +935,29 @@ void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint, SkTLazy<SkPaint> lazyPaint; { - SkAlpha newAlpha; - if (SkDrawTreatAsHairline(origPaint, *matrix, &newAlpha)) { - lazyPaint.set(origPaint); - lazyPaint.get()->setAlpha(newAlpha); - lazyPaint.get()->setStrokeWidth(0); - paint = lazyPaint.get(); + SkScalar coverage; + if (SkDrawTreatAsHairline(origPaint, *matrix, &coverage)) { + if (SK_Scalar1 == coverage) { + lazyPaint.set(origPaint); + lazyPaint.get()->setStrokeWidth(0); + paint = lazyPaint.get(); + } else if (xfermodeSupportsCoverageAsAlpha(origPaint.getXfermode())) { + U8CPU newAlpha; +#if 0 + newAlpha = SkToU8(SkScalarRoundToInt(coverage * + origPaint.getAlpha())); +#else + // this is the old technique, which we preserve for now so + // we don't change previous results (testing) + // the new way seems fine, its just (a tiny bit) different + int scale = (int)SkScalarMul(coverage, 256); + newAlpha = origPaint.getAlpha() * scale >> 8; +#endif + lazyPaint.set(origPaint); + lazyPaint.get()->setStrokeWidth(0); + lazyPaint.get()->setAlpha(newAlpha); + paint = lazyPaint.get(); + } } } diff --git a/src/core/SkDrawProcs.h b/src/core/SkDrawProcs.h index 33b870d2c8..2e26ecf44a 100644 --- a/src/core/SkDrawProcs.h +++ b/src/core/SkDrawProcs.h @@ -35,13 +35,12 @@ struct SkDrawProcs { }; /** - * If the current paint is set to stroke, has a compatible xfermode, and the - * stroke-width when applied to the matrix is <= 1.0, then this returns true, - * and sets newAlpha (simulating a stroke by drawing a hairline + newAlpha). - * If any of these conditions are false, then this returns false and modulate - * is ignored. + * If the current paint is set to stroke and the stroke-width when applied to + * the matrix is <= 1.0, then this returns true, and sets coverage (simulating + * a stroke by drawing a hairline with partial coverage). If any of these + * conditions are false, then this returns false and coverage is ignored. */ -bool SkDrawTreatAsHairline(const SkPaint&, const SkMatrix&, SkAlpha* newAlpha); +bool SkDrawTreatAsHairline(const SkPaint&, const SkMatrix&, SkScalar* coverage); #endif |