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

Unified Diff: bench/BezierBench.cpp

Issue 558163005: thick stroke Beziers (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix bench Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gm/beziers.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/BezierBench.cpp
diff --git a/bench/BezierBench.cpp b/bench/BezierBench.cpp
new file mode 100755
index 0000000000000000000000000000000000000000..ec83d958bbd5920088cdff0f770826d4ff051261
--- /dev/null
+++ b/bench/BezierBench.cpp
@@ -0,0 +1,101 @@
+/*
+ * 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 "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(NULL, 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(const 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); )
« no previous file with comments | « no previous file | gm/beziers.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698