aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkDraw.cpp
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-01-18 20:34:00 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-01-18 20:34:00 +0000
commitdd1be60702b3622f49d97651e31d13eaf2175cf8 (patch)
treeac2d2b26d2c9f6054acefd627efb64d6f1c93c09 /src/core/SkDraw.cpp
parent376cd1f919cf79dd4f481da063bdd6b656df4279 (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/SkDraw.cpp')
-rw-r--r--src/core/SkDraw.cpp49
1 files changed, 27 insertions, 22 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();
+ }
}
}