forked from revery-ui/esy-skia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BezierBench.cpp
102 lines (89 loc) · 2.97 KB
/
BezierBench.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Benchmark.h"
#include "SkCanvas.h"
#include "SkPaint.h"
#include "SkPath.h"
#include "SkString.h"
struct BezierRec {
SkCanvas* fCanvas;
SkPaint fPaint;
SkPath fQuad;
SkPath fCubic;
};
typedef const char* (*DrawProc)(const BezierRec*, int);
static const char* draw_quad(const BezierRec* rec, int count) {
if (rec) {
SkCanvas* canvas = rec->fCanvas;
const SkPaint& paint = rec->fPaint;
const SkPath& path = rec->fQuad;
for (int i = 0; i < count; ++i) {
canvas->drawPath(path, paint);
}
}
return "quad";
}
static const char* draw_cubic(const BezierRec* rec, int count) {
if (rec) {
SkCanvas* canvas = rec->fCanvas;
const SkPaint& paint = rec->fPaint;
const SkPath& path = rec->fCubic;
for (int i = 0; i < count; ++i) {
canvas->drawPath(path, paint);
}
}
return "cubic";
}
class BezierBench : public Benchmark {
SkString fName;
SkPaint::Cap fCap;
SkPaint::Join fJoin;
BezierRec fRec;
DrawProc fProc;
SkScalar fWidth;
public:
BezierBench(SkPaint::Cap c, SkPaint::Join j, SkScalar w, DrawProc proc) {
static const char* gCapName[] = {
"butt", "round", "square"
};
static const char* gJoinName[] = {
"miter", "round", "bevel"
};
fCap = c;
fJoin = j;
fProc = proc;
fWidth = SkIntToScalar(w);
fName.printf("draw_stroke_bezier_%s_%s_%s_%g", proc(nullptr, 0), gCapName[c], gJoinName[j], w);
fRec.fQuad.moveTo(20, 20);
fRec.fQuad.quadTo(60, 20, 60, 60);
fRec.fQuad.quadTo(20, 60, 20, 100);
fRec.fCubic.moveTo(20, 20);
fRec.fCubic.cubicTo(40, 20, 60, 40, 60, 60);
fRec.fCubic.cubicTo(40, 60, 20, 80, 20, 100);
}
protected:
virtual const char* onGetName() {
return fName.c_str();
}
virtual void onDraw(int loops, SkCanvas* canvas) {
fRec.fCanvas = canvas;
this->setupPaint(&fRec.fPaint);
fRec.fPaint.setStyle(SkPaint::kStroke_Style);
fRec.fPaint.setStrokeCap(fCap);
fRec.fPaint.setStrokeJoin(fJoin);
fRec.fPaint.setStrokeWidth(fWidth);
fProc(&fRec, loops);
}
private:
typedef Benchmark INHERITED;
};
DEF_BENCH( return new BezierBench(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2, draw_quad); )
DEF_BENCH( return new BezierBench(SkPaint::kSquare_Cap, SkPaint::kBevel_Join, 10, draw_quad); )
DEF_BENCH( return new BezierBench(SkPaint::kRound_Cap, SkPaint::kMiter_Join, 50, draw_quad); )
DEF_BENCH( return new BezierBench(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2, draw_cubic); )
DEF_BENCH( return new BezierBench(SkPaint::kSquare_Cap, SkPaint::kBevel_Join, 10, draw_cubic); )
DEF_BENCH( return new BezierBench(SkPaint::kRound_Cap, SkPaint::kMiter_Join, 50, draw_cubic); )