зеркало из https://github.com/mozilla/moz-skia.git
add makedash_ variants to measure applying the dash (not drawing it)
git-svn-id: http://skia.googlecode.com/svn/trunk@4000 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
90cb9b325c
Коммит
ea6f6832dd
|
@ -106,7 +106,7 @@ public:
|
|||
: INHERITED(param, intervals, count, width) {
|
||||
fName.append("_rect");
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
virtual void handlePath(SkCanvas* canvas, const SkPath& path,
|
||||
const SkPaint& paint, int N) SK_OVERRIDE {
|
||||
|
@ -119,14 +119,14 @@ protected:
|
|||
rect.fTop = pts[0].fY - paint.getStrokeWidth() / 2;
|
||||
rect.fRight = rect.fLeft + SkIntToScalar(fWidth);
|
||||
rect.fBottom = rect.fTop + paint.getStrokeWidth();
|
||||
|
||||
|
||||
SkPaint p(paint);
|
||||
p.setStyle(SkPaint::kFill_Style);
|
||||
p.setPathEffect(NULL);
|
||||
|
||||
|
||||
int count = SkScalarRoundToInt((pts[1].fX - pts[0].fX) / (2*fWidth));
|
||||
SkScalar dx = SkIntToScalar(2 * fWidth);
|
||||
|
||||
|
||||
for (int i = 0; i < N*10; ++i) {
|
||||
SkRect r = rect;
|
||||
for (int j = 0; j < count; ++j) {
|
||||
|
@ -141,6 +141,80 @@ private:
|
|||
typedef DashBench INHERITED;
|
||||
};
|
||||
|
||||
static void make_unit_star(SkPath* path, int n) {
|
||||
SkScalar rad = -SK_ScalarPI / 2;
|
||||
const SkScalar drad = (n >> 1) * SK_ScalarPI * 2 / n;
|
||||
|
||||
path->moveTo(0, -SK_Scalar1);
|
||||
for (int i = 1; i < n; i++) {
|
||||
rad += drad;
|
||||
SkScalar cosV, sinV = SkScalarSinCos(rad, &cosV);
|
||||
path->lineTo(cosV, sinV);
|
||||
}
|
||||
path->close();
|
||||
}
|
||||
|
||||
static void make_poly(SkPath* path) {
|
||||
make_unit_star(path, 9);
|
||||
SkMatrix matrix;
|
||||
matrix.setScale(SkIntToScalar(100), SkIntToScalar(100));
|
||||
path->transform(matrix);
|
||||
}
|
||||
|
||||
static void make_quad(SkPath* path) {
|
||||
SkScalar x0 = SkIntToScalar(10);
|
||||
SkScalar y0 = SkIntToScalar(10);
|
||||
path->moveTo(x0, y0);
|
||||
path->quadTo(x0, y0 + 400 * SK_Scalar1,
|
||||
x0 + 600 * SK_Scalar1, y0 + 400 * SK_Scalar1);
|
||||
}
|
||||
|
||||
static void make_cubic(SkPath* path) {
|
||||
SkScalar x0 = SkIntToScalar(10);
|
||||
SkScalar y0 = SkIntToScalar(10);
|
||||
path->moveTo(x0, y0);
|
||||
path->cubicTo(x0, y0 + 400 * SK_Scalar1,
|
||||
x0 + 600 * SK_Scalar1, y0 + 400 * SK_Scalar1,
|
||||
x0 + 600 * SK_Scalar1, y0);
|
||||
}
|
||||
|
||||
class MakeDashBench : public SkBenchmark {
|
||||
SkString fName;
|
||||
SkPath fPath;
|
||||
SkAutoTUnref<SkPathEffect> fPE;
|
||||
|
||||
enum {
|
||||
N = SkBENCHLOOP(400)
|
||||
};
|
||||
|
||||
public:
|
||||
MakeDashBench(void* param, void (*proc)(SkPath*), const char name[]) : INHERITED(param) {
|
||||
fName.printf("makedash_%s", name);
|
||||
proc(&fPath);
|
||||
|
||||
SkScalar vals[] = { SkIntToScalar(4), SkIntToScalar(4) };
|
||||
fPE.reset(new SkDashPathEffect(vals, 2, 0));
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual const char* onGetName() SK_OVERRIDE {
|
||||
return fName.c_str();
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
||||
SkPath dst;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
SkScalar width = 0;
|
||||
|
||||
fPE->filterPath(&dst, fPath, &width);
|
||||
dst.rewind();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
typedef SkBenchmark INHERITED;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const SkScalar gDots[] = { SK_Scalar1, SK_Scalar1 };
|
||||
|
@ -151,10 +225,14 @@ static SkBenchmark* gF0(void* p) { return new DashBench(p, PARAM(gDots), 0); }
|
|||
static SkBenchmark* gF1(void* p) { return new DashBench(p, PARAM(gDots), 1); }
|
||||
static SkBenchmark* gF2(void* p) { return new DashBench(p, PARAM(gDots), 1, true); }
|
||||
static SkBenchmark* gF3(void* p) { return new DashBench(p, PARAM(gDots), 4); }
|
||||
static SkBenchmark* gF4(void* p) { return new RectDashBench(p, PARAM(gDots), 4); }
|
||||
static SkBenchmark* gF4(void* p) { return new MakeDashBench(p, make_poly, "poly"); }
|
||||
static SkBenchmark* gF5(void* p) { return new MakeDashBench(p, make_quad, "quad"); }
|
||||
static SkBenchmark* gF6(void* p) { return new MakeDashBench(p, make_cubic, "cubic"); }
|
||||
|
||||
static BenchRegistry gR0(gF0);
|
||||
static BenchRegistry gR1(gF1);
|
||||
static BenchRegistry gR2(gF2);
|
||||
static BenchRegistry gR3(gF3);
|
||||
static BenchRegistry gR4(gF4);
|
||||
static BenchRegistry gR5(gF5);
|
||||
static BenchRegistry gR6(gF6);
|
||||
|
|
Загрузка…
Ссылка в новой задаче