aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-12-17 18:56:29 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-12-17 18:56:29 +0000
commit6d87557278052c131957e5d6e093d3a675162d22 (patch)
treea7cab14931cd8818b7f7aafba7c169bca994fb24 /src/core
parent33352d9623f982252aa539741ea38dbc545449b8 (diff)
3on/3off dashing optimization
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkDraw.cpp80
1 files changed, 61 insertions, 19 deletions
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index e1fa366fa7..77c20a9ba4 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -661,37 +661,79 @@ void SkDraw::drawPoints(SkCanvas::PointMode mode, size_t count,
// most likely a dashed line - see if it is one of the ones
// we can accelerate
SkStrokeRec rec(paint);
- SkPathEffect::PointData dst;
+ SkPathEffect::PointData pointData;
SkPath path;
path.moveTo(pts[0]);
path.lineTo(pts[1]);
- if (paint.getPathEffect()->asPoints(&dst, path, rec, *fMatrix) &&
- SK_Scalar1 == dst.fSize.fX && SK_Scalar1 == dst.fSize.fY &&
- !(SkPathEffect::PointData::kUsePath_PointFlag & dst.fFlags)) {
+ if (paint.getPathEffect()->asPoints(&pointData, path, rec, *fMatrix)) {
+ // 'asPoints' managed to find some fast path
+
SkPaint newP(paint);
newP.setPathEffect(NULL);
newP.setStyle(SkPaint::kFill_Style);
- if (SkPathEffect::PointData::kCircles_PointFlag & dst.fFlags) {
- newP.setStrokeCap(SkPaint::kRound_Cap);
- } else {
- newP.setStrokeCap(SkPaint::kButt_Cap);
+ if (!pointData.fFirst.isEmpty()) {
+ if (fDevice) {
+ fDevice->drawPath(*this, pointData.fFirst, newP);
+ } else {
+ this->drawPath(pointData.fFirst, newP);
+ }
}
- if (fDevice) {
- fDevice->drawPoints(*this,
- SkCanvas::kPoints_PointMode,
- dst.fNumPoints,
- dst.fPoints,
- newP);
+
+ if (!pointData.fLast.isEmpty()) {
+ if (fDevice) {
+ fDevice->drawPath(*this, pointData.fLast, newP);
+ } else {
+ this->drawPath(pointData.fLast, newP);
+ }
+ }
+
+ if (pointData.fSize.fX == pointData.fSize.fY) {
+ // The rest of the dashed line can just be drawn as points
+ SkASSERT(pointData.fSize.fX == SkScalarHalf(newP.getStrokeWidth()));
+
+ if (SkPathEffect::PointData::kCircles_PointFlag & pointData.fFlags) {
+ newP.setStrokeCap(SkPaint::kRound_Cap);
+ } else {
+ newP.setStrokeCap(SkPaint::kButt_Cap);
+ }
+
+ if (fDevice) {
+ fDevice->drawPoints(*this,
+ SkCanvas::kPoints_PointMode,
+ pointData.fNumPoints,
+ pointData.fPoints,
+ newP);
+ } else {
+ this->drawPoints(SkCanvas::kPoints_PointMode,
+ pointData.fNumPoints,
+ pointData.fPoints,
+ newP,
+ forceUseDevice);
+ }
+ break;
} else {
- this->drawPoints(SkCanvas::kPoints_PointMode,
- dst.fNumPoints,
- dst.fPoints,
- newP,
- forceUseDevice);
+ // The rest of the dashed line must be drawn as rects
+ SkASSERT(!(SkPathEffect::PointData::kCircles_PointFlag &
+ pointData.fFlags));
+
+ SkRect r;
+
+ for (int i = 0; i < pointData.fNumPoints; ++i) {
+ r.set(pointData.fPoints[i].fX - pointData.fSize.fX,
+ pointData.fPoints[i].fY - pointData.fSize.fY,
+ pointData.fPoints[i].fX + pointData.fSize.fX,
+ pointData.fPoints[i].fY + pointData.fSize.fY);
+ if (fDevice) {
+ fDevice->drawRect(*this, r, newP);
+ } else {
+ this->drawRect(r, newP);
+ }
+ }
}
+
break;
}
}