Add drawPoints dash bench

https://codereview.appspot.com/6866053/



git-svn-id: http://skia.googlecode.com/svn/trunk@6678 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
robertphillips@google.com 2012-12-05 19:07:21 +00:00
parent f6c7e72c2c
commit 935ad02682
4 changed files with 97 additions and 13 deletions

View File

@ -220,7 +220,6 @@ private:
*/
class DashLineBench : public SkBenchmark {
SkString fName;
SkPath fPath;
SkScalar fStrokeWidth;
bool fIsRound;
SkAutoTUnref<SkPathEffect> fPE;
@ -260,6 +259,58 @@ private:
typedef SkBenchmark INHERITED;
};
class DrawPointsDashingBench : public SkBenchmark {
SkString fName;
int fStrokeWidth;
bool fdoAA;
SkAutoTUnref<SkPathEffect> fPathEffect;
enum {
N = SkBENCHLOOP(480)
};
public:
DrawPointsDashingBench(void* param, int dashLength, int strokeWidth, bool doAA)
: INHERITED(param) {
fName.printf("drawpointsdash_%d_%d%s", dashLength, strokeWidth, doAA ? "_aa" : "_bw");
fStrokeWidth = strokeWidth;
fdoAA = doAA;
SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength) };
fPathEffect.reset(new SkDashPathEffect(vals, 2, SK_Scalar1, false));
}
protected:
virtual const char* onGetName() SK_OVERRIDE {
return fName.c_str();
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkPaint p;
this->setupPaint(&p);
p.setColor(SK_ColorBLACK);
p.setStyle(SkPaint::kStroke_Style);
p.setStrokeWidth(SkIntToScalar(fStrokeWidth));
p.setPathEffect(fPathEffect);
p.setAntiAlias(fdoAA);
SkPoint pts[2] = {
{ SkIntToScalar(10), 0 },
{ SkIntToScalar(640), 0 }
};
for (int i = 0; i < N; ++i) {
pts[0].fY = pts[1].fY = SkIntToScalar(i % 480);
canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p);
}
}
private:
typedef SkBenchmark INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
static const SkScalar gDots[] = { SK_Scalar1, SK_Scalar1 };
@ -280,6 +331,13 @@ static SkBenchmark* gF701(void* p) { return new DashLineBench(p, 0, true); }
static SkBenchmark* gF711(void* p) { return new DashLineBench(p, SK_Scalar1, true); }
static SkBenchmark* gF721(void* p) { return new DashLineBench(p, 2 * SK_Scalar1, true); }
static SkBenchmark* gF8(void* p) { return new DrawPointsDashingBench(p, 1, 1, false); }
static SkBenchmark* gF9(void* p) { return new DrawPointsDashingBench(p, 1, 1, true); }
static SkBenchmark* gF10(void* p) { return new DrawPointsDashingBench(p, 3, 1, false); }
static SkBenchmark* gF11(void* p) { return new DrawPointsDashingBench(p, 3, 1, true); }
static SkBenchmark* gF12(void* p) { return new DrawPointsDashingBench(p, 5, 5, false); }
static SkBenchmark* gF13(void* p) { return new DrawPointsDashingBench(p, 5, 5, true); }
static BenchRegistry gR0(gF0);
static BenchRegistry gR1(gF1);
static BenchRegistry gR2(gF2);
@ -293,3 +351,10 @@ static BenchRegistry gR720(gF720);
static BenchRegistry gR701(gF701);
static BenchRegistry gR711(gF711);
static BenchRegistry gR721(gF721);
static BenchRegistry gR8(gF8);
static BenchRegistry gR9(gF9);
static BenchRegistry gR10(gF10);
static BenchRegistry gR11(gF11);
static BenchRegistry gR12(gF12);
static BenchRegistry gR13(gF13);

View File

@ -141,12 +141,16 @@ public:
class PointData {
public:
PointData()
: fFlags(0) {
: fFlags(0)
, fPoints(NULL)
, fNumPoints(0) {
fSize.set(SK_Scalar1, SK_Scalar1);
// 'asPoints' needs to initialize/fill-in 'fClipRect' if it sets
// the kUseClip flag
};
~PointData() {};
~PointData() {
delete [] fPoints;
}
// TODO: consider using passed-in flags to limit the work asPoints does.
// For example, a kNoPath flag could indicate don't bother generating
@ -161,7 +165,8 @@ public:
uint32_t fFlags; // flags that impact the drawing of the points
// TODO: consider replacing the TDArray with either SkData or a ptr/len field
SkTDArray<SkPoint> fPoints; // the center point of each generated point
SkPoint* fPoints; // the center point of each generated point
int fNumPoints; // number of points in fPoints
SkVector fSize; // the size to draw the points
SkRect fClipRect; // clip required to draw the points (if kUseClip is set)
SkPath fPath; // 'stamp' to be used at each point (if kUsePath is set)

View File

@ -672,18 +672,26 @@ void SkDraw::drawPoints(SkCanvas::PointMode mode, size_t count,
!(SkPathEffect::PointData::kUsePath_PointFlag & dst.fFlags)) {
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);
}
this->drawPoints(SkCanvas::kPoints_PointMode,
dst.fPoints.count(),
dst.fPoints.begin(),
newP,
forceUseDevice);
if (fDevice) {
fDevice->drawPoints(*this,
SkCanvas::kPoints_PointMode,
dst.fNumPoints,
dst.fPoints,
newP);
} else {
this->drawPoints(SkCanvas::kPoints_PointMode,
dst.fNumPoints,
dst.fPoints,
newP,
forceUseDevice);
}
break;
}
}

View File

@ -281,11 +281,13 @@ bool SkDashPathEffect::asPoints(PointData* results,
tangent.scale(SkScalarInvert(length));
SkScalar ptCount = SkScalarDiv(length, SkIntToScalar(2));
results->fPoints.setReserve(SkScalarCeilToInt(ptCount));
SkScalar ptCount = SkScalarDiv(length-1, SkIntToScalar(2));
results->fNumPoints = SkScalarCeilToInt(ptCount);
results->fPoints = new SkPoint[results->fNumPoints];
// +1 b.c. fInitialDashLength is zero so the initial segment will be skipped
int index = fInitialDashIndex+1;
int iCurPt = 0;
for (SkScalar distance = SK_ScalarHalf; distance < length; distance += SK_Scalar1) {
SkASSERT(index <= fCount);
@ -293,11 +295,15 @@ bool SkDashPathEffect::asPoints(PointData* results,
if (0 == index) {
SkScalar x0 = pts[0].fX + SkScalarMul(tangent.fX, distance);
SkScalar y0 = pts[0].fY + SkScalarMul(tangent.fY, distance);
results->fPoints.append()->set(x0, y0);
SkASSERT(iCurPt < results->fNumPoints);
results->fPoints[iCurPt].set(x0, y0);
++iCurPt;
}
index ^= 1; // 0 -> 1 -> 0 ...
}
SkASSERT(iCurPt == results->fNumPoints);
}
return true;