aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/SkBenchmark.h
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-02-03 14:48:17 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-02-03 14:48:17 +0000
commit6adce6783c5d7cbef276d04cc08a2b19789a0156 (patch)
tree6a8c5152d4e90321e0d0ca8311d5077dac330fe7 /bench/SkBenchmark.h
parentccfe7b8ae7fd6cc1be4aa7836c4c81db31034d16 (diff)
Allow GMs to be used as benchmarks. Make convex_poly_clip opt in.
R=reed@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/151843002 git-svn-id: http://skia.googlecode.com/svn/trunk@13279 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench/SkBenchmark.h')
-rw-r--r--bench/SkBenchmark.h19
1 files changed, 15 insertions, 4 deletions
diff --git a/bench/SkBenchmark.h b/bench/SkBenchmark.h
index bf44d2cc97..f1e317da60 100644
--- a/bench/SkBenchmark.h
+++ b/bench/SkBenchmark.h
@@ -13,9 +13,13 @@
#include "SkString.h"
#include "SkTRegistry.h"
-#define DEF_BENCH(code) \
-static SkBenchmark* SK_MACRO_APPEND_LINE(F_)() { code; } \
-static BenchRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_));
+#define DEF_BENCH(code) \
+namespace { \
+class SK_MACRO_APPEND_LINE(F_CLASS) : public SkBenchmarkFactory { \
+ virtual SkBenchmark* operator()() const SK_OVERRIDE { code; } \
+} SK_MACRO_APPEND_LINE(g_F_); \
+BenchRegistry SK_MACRO_APPEND_LINE(g_R_)(&SK_MACRO_APPEND_LINE(g_F_)); \
+}
/*
* With the above macros, you can register benches as follows (at the bottom
@@ -132,6 +136,13 @@ private:
typedef SkRefCnt INHERITED;
};
-typedef SkTRegistry<SkBenchmark*(*)()> BenchRegistry;
+class SkBenchmarkFactory : public SkRefCnt {
+public:
+ // Creates a new SkBenchmark that is owned by the caller on each call.
+ virtual SkBenchmark* operator()() const = 0;
+ virtual ~SkBenchmarkFactory() {}
+};
+
+typedef SkTRegistry<SkBenchmarkFactory*> BenchRegistry;
#endif