2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
14 class StrokeBench : public Benchmark {
16 StrokeBench(const SkPath& path, const SkPaint& paint, const char pathType[], SkScalar res)
17 : fPath(path), fPaint(paint), fRes(res)
19 fName.printf("build_stroke_%s_%g_%d_%d",
20 pathType, paint.getStrokeWidth(), paint.getStrokeJoin(), paint.getStrokeCap());
24 bool isSuitableFor(Backend backend) override {
25 return backend == kNonRendering_Backend;
28 const char* onGetName() override { return fName.c_str(); }
30 void onDraw(int loops, SkCanvas* canvas) override {
31 SkPaint paint(fPaint);
32 this->setupPaint(&paint);
34 for (int outer = 0; outer < 10; ++outer) {
35 for (int i = 0; i < loops; ++i) {
37 paint.getFillPath(fPath, &result, nullptr, fRes);
47 typedef Benchmark INHERITED;
50 ///////////////////////////////////////////////////////////////////////////////
52 static const int N = 100;
53 static const SkScalar X = 100;
54 static const SkScalar Y = 100;
56 static SkPoint rand_pt(SkRandom& rand) {
57 return SkPoint::Make(rand.nextSScalar1() * X, rand.nextSScalar1() * Y);
60 static SkPath line_path_maker() {
63 path.moveTo(rand_pt(rand));
64 for (int i = 0; i < N; ++i) {
65 path.lineTo(rand_pt(rand));
69 static SkPath quad_path_maker() {
72 path.moveTo(rand_pt(rand));
73 for (int i = 0; i < N; ++i) {
74 path.quadTo(rand_pt(rand), rand_pt(rand));
78 static SkPath conic_path_maker() {
81 path.moveTo(rand_pt(rand));
82 for (int i = 0; i < N; ++i) {
83 path.conicTo(rand_pt(rand), rand_pt(rand), rand.nextUScalar1());
87 static SkPath cubic_path_maker() {
90 path.moveTo(rand_pt(rand));
91 for (int i = 0; i < N; ++i) {
92 path.cubicTo(rand_pt(rand), rand_pt(rand), rand_pt(rand));
97 static SkPaint paint_maker() {
99 paint.setStyle(SkPaint::kStroke_Style);
100 paint.setStrokeWidth(X / 10);
101 paint.setStrokeJoin(SkPaint::kMiter_Join);
102 paint.setStrokeCap(SkPaint::kSquare_Cap);
106 DEF_BENCH(return new StrokeBench(line_path_maker(), paint_maker(), "line_1", 1);)
107 DEF_BENCH(return new StrokeBench(quad_path_maker(), paint_maker(), "quad_1", 1);)
108 DEF_BENCH(return new StrokeBench(conic_path_maker(), paint_maker(), "conic_1", 1);)
109 DEF_BENCH(return new StrokeBench(cubic_path_maker(), paint_maker(), "cubic_1", 1);)
111 DEF_BENCH(return new StrokeBench(line_path_maker(), paint_maker(), "line_4", 4);)
112 DEF_BENCH(return new StrokeBench(quad_path_maker(), paint_maker(), "quad_4", 4);)
113 DEF_BENCH(return new StrokeBench(conic_path_maker(), paint_maker(), "conic_4", 4);)
114 DEF_BENCH(return new StrokeBench(cubic_path_maker(), paint_maker(), "cubic_4", 4);)
116 DEF_BENCH(return new StrokeBench(line_path_maker(), paint_maker(), "line_.25", .25f);)
117 DEF_BENCH(return new StrokeBench(quad_path_maker(), paint_maker(), "quad_.25", .25f);)
118 DEF_BENCH(return new StrokeBench(conic_path_maker(), paint_maker(), "conic_.25", .25f);)
119 DEF_BENCH(return new StrokeBench(cubic_path_maker(), paint_maker(), "cubic_.25", .25f);)