Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: bench/HairlinePathBench.cpp

Issue 19238003: Add bench for hairline paths (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2011 Google Inc.
bsalomon 2013/07/15 17:42:56 2013
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "SkBenchmark.h"
8 #include "SkCanvas.h"
9 #include "SkPaint.h"
10 #include "SkShader.h"
11 #include "SkString.h"
12
13 #define HYPERBOLA 2.0f
tfarina 2013/07/16 02:03:16 can these be const floats instead?
14 #define ELLIPSE 0.5f
15
16 static const int points[] = {
17 10, 10, 15, 5, 20, 20
tfarina 2013/07/16 02:03:16 indent 4 spaces only?
18 };
tfarina 2013/07/16 02:03:16 mv to first column?
19
20 class HairlinePathBench : public SkBenchmark {
21 SkPaint fPaint;
bsalomon 2013/07/15 17:42:56 Move these down to private below?
22 SkString fName;
23 enum { N = SkBENCHLOOP(1000) };
24 public:
25 HairlinePathBench(void* param) : INHERITED(param) {
26 fPaint.setStyle(SkPaint::kStroke_Style);
27 fPaint.setStrokeWidth(SkIntToScalar(0));
28 }
29
tfarina 2013/07/16 02:03:16 virtual destructor?
30 virtual void appendName(SkString*) = 0;
bsalomon 2013/07/15 17:42:56 do these need to be public?
31 virtual void makePath(SkPath*) = 0;
32 virtual int complexity() { return 0; }
tfarina 2013/07/16 02:03:16 const?
33
34 protected:
35 virtual const char* onGetName() SK_OVERRIDE {
36 fName.printf("path_hairline_");
37 this->appendName(&fName);
38 return fName.c_str();
39 }
40
41 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
42 SkPaint paint(fPaint);
43 this->setupPaint(&paint);
44
45 SkPath path;
46 this->makePath(&path);
47
48 int count = N;
49 for (int i = 0; i < count; i++) {
50 canvas->drawPath(path, paint);
51 }
52 }
53
54 private:
55 typedef SkBenchmark INHERITED;
56 };
57
58 class LinePathBench : public HairlinePathBench {
59 public:
60 LinePathBench(void* param) : INHERITED(param) {}
61
62 virtual void appendName(SkString* name) SK_OVERRIDE {
63 name->append("line");
64 }
65 virtual void makePath(SkPath* path) SK_OVERRIDE {
66 path->moveTo(SkIntToScalar(points[0]), SkIntToScalar(points[1]));
67 path->lineTo(SkIntToScalar(points[2]), SkIntToScalar(points[3]));
68 path->lineTo(SkIntToScalar(points[4]), SkIntToScalar(points[5]));
69 }
70 private:
71 typedef HairlinePathBench INHERITED;
72 };
73
74 class QuadPathBench : public HairlinePathBench {
75 public:
76 QuadPathBench(void* param) : INHERITED(param) {}
77
78 virtual void appendName(SkString* name) SK_OVERRIDE {
79 name->append("quad");
80 }
81 virtual void makePath(SkPath* path) SK_OVERRIDE {
82 path->moveTo(SkIntToScalar(points[0]), SkIntToScalar(points[1]));
83 path->quadTo(SkIntToScalar(points[2]), SkIntToScalar(points[3]),
84 SkIntToScalar(points[4]), SkIntToScalar(points[5]));
85 }
86 private:
87 typedef HairlinePathBench INHERITED;
88 };
89
90 class ConicPathBench : public HairlinePathBench {
91 public:
92 ConicPathBench(void* param, const SkScalar weight) : INHERITED(param), fWeig ht(weight) {}
tfarina 2013/07/16 02:03:16 can we try to keep these in 80 columns (I know we
bsalomon 2013/07/16 12:57:17 Skia's rough limit is 100 cols.
93
94 virtual void appendName(SkString* name) SK_OVERRIDE {
95 name->append("conic");
96 if (fWeight == HYPERBOLA) {
tfarina 2013/07/16 02:03:16 I think in skia people do comparisons in the rever
97 name->append("_hyperbola");
98 } else if (fWeight == ELLIPSE) {
99 name->append("_ellipse");
100 };
tfarina 2013/07/16 02:03:16 micronit: no need of ; here
101 }
102 virtual void makePath(SkPath* path) SK_OVERRIDE {
103 path->moveTo(SkIntToScalar(points[0]), SkIntToScalar(points[1]));
104 path->conicTo(SkIntToScalar(points[2]), SkIntToScalar(points[3]),
105 SkIntToScalar(points[4]), SkIntToScalar(points[5]),
106 fWeight);
107 }
108 private:
109 SkScalar fWeight;
110 typedef HairlinePathBench INHERITED;
111 };
112
113 DEF_BENCH( return new LinePathBench(p); )
114 DEF_BENCH( return new QuadPathBench(p); )
115 DEF_BENCH( return new ConicPathBench(p, ELLIPSE); ) // ellipse weight 0.5
116 DEF_BENCH( return new ConicPathBench(p, HYPERBOLA); ) // hyperbola weight 2.0
OLDNEW
« no previous file with comments | « no previous file | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698