aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench
diff options
context:
space:
mode:
authorGravatar jcgregorio <jcgregorio@google.com>2015-04-16 09:47:36 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-04-16 09:47:36 -0700
commitbdb0bf5f8858043878d8a4fa8130c6c87bef3fd4 (patch)
tree42dff3d1fed8ccabefc7672ed18257e45045d99d /bench
parent6ef68ab2cd0597a6f1141b686f82f64ac1e89ccf (diff)
Revert of remove unused (by clients) SkPathUtils (patchset #1 id:1 of https://codereview.chromium.org/1088383003/)
Reason for revert: This change is causing the DEPS roll to fail: http://build.chromium.org/p/tryserver.chromium.linux/builders/android_chromium_gn_compile_rel/builds/78771/steps/gn/logs/stdio Original issue's description: > remove unused (by clients) SkPathUtils > > BUG=skia: > > Committed: https://skia.googlesource.com/skia/+/aab35d91b8b80acd1902594bbf542083fdfa4bb7 TBR=scroggo@google.com,reed@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/1060703003
Diffstat (limited to 'bench')
-rw-r--r--bench/PathUtilsBench.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/bench/PathUtilsBench.cpp b/bench/PathUtilsBench.cpp
new file mode 100644
index 0000000000..6c8086fb9d
--- /dev/null
+++ b/bench/PathUtilsBench.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2011 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 "SkPathUtils.h"
+#include "SkRandom.h"
+#include "SkString.h"
+#include "SkTime.h"
+
+#define H 16
+#define W 16
+#define STRIDE 2
+
+//this function is redefined for sample, test, and bench. is there anywhere
+// I can put it to avoid code duplcation?
+static void fillRandomBits( int chars, char* bits ){
+ SkRandom rand(SkTime::GetMSecs());
+
+ for (int i = 0; i < chars; ++i){
+ bits[i] = rand.nextU();
+ }
+}
+
+static void path_proc(char* bits, SkPath* path) {
+ SkPathUtils::BitsToPath_Path(path, bits, H, W, STRIDE);
+}
+
+static void region_proc(char* bits, SkPath* path) {
+ SkPathUtils::BitsToPath_Region(path, bits, H, W, STRIDE);
+}
+
+/// Emulates the mix of rects blitted by gmail during scrolling
+class PathUtilsBench : public Benchmark {
+ typedef void (*Proc)(char*, SkPath*);
+
+ Proc fProc;
+ SkString fName;
+ char* bits[H * STRIDE];
+
+public:
+ PathUtilsBench(Proc proc, const char name[]) {
+ fProc = proc;
+ fName.printf("pathUtils_%s", name);
+
+
+ }
+
+protected:
+ virtual const char* onGetName() { return fName.c_str(); }
+
+ virtual void onDraw(const int loops, SkCanvas* canvas) {
+
+ for (int i = 0; i < loops; ++i){
+ //create a random 16x16 bitmap
+ fillRandomBits(H * STRIDE, (char*) &bits);
+
+ //use passed function pointer to handle it
+ SkPath path;
+ fProc( (char*) &bits, &path);
+ }
+ }
+
+private:
+ typedef Benchmark INHERITED;
+};
+
+DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (path_proc, "path")); )
+DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (region_proc, "region")); )