Chromium Code Reviews| Index: bench/HairlinePathBench.cpp |
| diff --git a/bench/HairlinePathBench.cpp b/bench/HairlinePathBench.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5830128950af83d389de69115b7716ed631a6c62 |
| --- /dev/null |
| +++ b/bench/HairlinePathBench.cpp |
| @@ -0,0 +1,116 @@ |
| +/* |
| + * Copyright 2011 Google Inc. |
|
bsalomon
2013/07/15 17:42:56
2013
|
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| +#include "SkBenchmark.h" |
| +#include "SkCanvas.h" |
| +#include "SkPaint.h" |
| +#include "SkShader.h" |
| +#include "SkString.h" |
| + |
| +#define HYPERBOLA 2.0f |
|
tfarina
2013/07/16 02:03:16
can these be const floats instead?
|
| +#define ELLIPSE 0.5f |
| + |
| +static const int points[] = { |
| + 10, 10, 15, 5, 20, 20 |
|
tfarina
2013/07/16 02:03:16
indent 4 spaces only?
|
| + }; |
|
tfarina
2013/07/16 02:03:16
mv to first column?
|
| + |
| +class HairlinePathBench : public SkBenchmark { |
| + SkPaint fPaint; |
|
bsalomon
2013/07/15 17:42:56
Move these down to private below?
|
| + SkString fName; |
| + enum { N = SkBENCHLOOP(1000) }; |
| +public: |
| + HairlinePathBench(void* param) : INHERITED(param) { |
| + fPaint.setStyle(SkPaint::kStroke_Style); |
| + fPaint.setStrokeWidth(SkIntToScalar(0)); |
| + } |
| + |
|
tfarina
2013/07/16 02:03:16
virtual destructor?
|
| + virtual void appendName(SkString*) = 0; |
|
bsalomon
2013/07/15 17:42:56
do these need to be public?
|
| + virtual void makePath(SkPath*) = 0; |
| + virtual int complexity() { return 0; } |
|
tfarina
2013/07/16 02:03:16
const?
|
| + |
| +protected: |
| + virtual const char* onGetName() SK_OVERRIDE { |
| + fName.printf("path_hairline_"); |
| + this->appendName(&fName); |
| + return fName.c_str(); |
| + } |
| + |
| + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| + SkPaint paint(fPaint); |
| + this->setupPaint(&paint); |
| + |
| + SkPath path; |
| + this->makePath(&path); |
| + |
| + int count = N; |
| + for (int i = 0; i < count; i++) { |
| + canvas->drawPath(path, paint); |
| + } |
| + } |
| + |
| +private: |
| + typedef SkBenchmark INHERITED; |
| +}; |
| + |
| +class LinePathBench : public HairlinePathBench { |
| +public: |
| + LinePathBench(void* param) : INHERITED(param) {} |
| + |
| + virtual void appendName(SkString* name) SK_OVERRIDE { |
| + name->append("line"); |
| + } |
| + virtual void makePath(SkPath* path) SK_OVERRIDE { |
| + path->moveTo(SkIntToScalar(points[0]), SkIntToScalar(points[1])); |
| + path->lineTo(SkIntToScalar(points[2]), SkIntToScalar(points[3])); |
| + path->lineTo(SkIntToScalar(points[4]), SkIntToScalar(points[5])); |
| + } |
| +private: |
| + typedef HairlinePathBench INHERITED; |
| +}; |
| + |
| +class QuadPathBench : public HairlinePathBench { |
| +public: |
| + QuadPathBench(void* param) : INHERITED(param) {} |
| + |
| + virtual void appendName(SkString* name) SK_OVERRIDE { |
| + name->append("quad"); |
| + } |
| + virtual void makePath(SkPath* path) SK_OVERRIDE { |
| + path->moveTo(SkIntToScalar(points[0]), SkIntToScalar(points[1])); |
| + path->quadTo(SkIntToScalar(points[2]), SkIntToScalar(points[3]), |
| + SkIntToScalar(points[4]), SkIntToScalar(points[5])); |
| + } |
| +private: |
| + typedef HairlinePathBench INHERITED; |
| +}; |
| + |
| +class ConicPathBench : public HairlinePathBench { |
| +public: |
| + ConicPathBench(void* param, const SkScalar weight) : INHERITED(param), fWeight(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.
|
| + |
| + virtual void appendName(SkString* name) SK_OVERRIDE { |
| + name->append("conic"); |
| + if (fWeight == HYPERBOLA) { |
|
tfarina
2013/07/16 02:03:16
I think in skia people do comparisons in the rever
|
| + name->append("_hyperbola"); |
| + } else if (fWeight == ELLIPSE) { |
| + name->append("_ellipse"); |
| + }; |
|
tfarina
2013/07/16 02:03:16
micronit: no need of ; here
|
| + } |
| + virtual void makePath(SkPath* path) SK_OVERRIDE { |
| + path->moveTo(SkIntToScalar(points[0]), SkIntToScalar(points[1])); |
| + path->conicTo(SkIntToScalar(points[2]), SkIntToScalar(points[3]), |
| + SkIntToScalar(points[4]), SkIntToScalar(points[5]), |
| + fWeight); |
| + } |
| +private: |
| + SkScalar fWeight; |
| + typedef HairlinePathBench INHERITED; |
| +}; |
| + |
| +DEF_BENCH( return new LinePathBench(p); ) |
| +DEF_BENCH( return new QuadPathBench(p); ) |
| +DEF_BENCH( return new ConicPathBench(p, ELLIPSE); ) // ellipse weight 0.5 |
| +DEF_BENCH( return new ConicPathBench(p, HYPERBOLA); ) // hyperbola weight 2.0 |