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

Unified Diff: bench/benchmain.cpp

Issue 151843002: Allow GMs ato be used as benchmarks. Make convex_poly_clip opt in. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: cleanup Created 6 years, 11 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
Index: bench/benchmain.cpp
diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp
index 12c982037ea090bc72c62b9f9ad46ecc4691b644..6ee841a9568493bac53b2b4b079c476e813a31c7 100644
--- a/bench/benchmain.cpp
+++ b/bench/benchmain.cpp
@@ -14,6 +14,7 @@
#include "SkColorPriv.h"
#include "SkCommandLineFlags.h"
#include "SkDeferredCanvas.h"
+#include "SkGMBench.h"
#include "SkGraphics.h"
#include "SkImageEncoder.h"
#include "SkOSFile.h"
@@ -32,6 +33,56 @@ class GrContext;
#include <limits>
+class AutoUnrefArray {
reed1 2014/02/03 13:20:42 Does this need a new class from scratch? Can you u
bsalomon 2014/02/03 14:02:45 Done. Inherited in order to override the destructo
+public:
+ AutoUnrefArray() {}
+ ~AutoUnrefArray() {
+ int count = fObjs.count();
+ for (int i = 0; i < count; ++i) {
+ fObjs[i]->unref();
+ }
+ }
+ const SkRefCnt*& push_back() { return *fObjs.append(); }
+
+private:
+ SkTDArray<const SkRefCnt*> fObjs;
+};
+
+class GMBenchFactory : public SkBenchmarkFactory {
+public:
+ GMBenchFactory(const skiagm::GMRegistry* gmreg)
+ : fGMFactory(gmreg->factory())
+ , fSelfRegistry(this) {
+ }
+
+ virtual SkBenchmark* operator()() const SK_OVERRIDE {
+ skiagm::GM* gm = fGMFactory(NULL);
+ return new SkGMBench(gm);
+ }
+
+private:
+ skiagm::GMRegistry::Factory fGMFactory;
+ BenchRegistry fSelfRegistry;
+};
+
+static void register_gm_benches() {
+ static bool gOnce;
+ static AutoUnrefArray gUnreffer;
+
+ if (!gOnce) {
+ const skiagm::GMRegistry* gmreg = skiagm::GMRegistry::Head();
+ while (gmreg) {
+ skiagm::GM* gm = gmreg->factory()(NULL);
+ if (NULL != gm && skiagm::GM::kAsBench_Flag & gm->getFlags()) {
+ gUnreffer.push_back() = SkNEW_ARGS(GMBenchFactory, (gmreg));
+ }
+ SkDELETE(gm);
+ gmreg = gmreg->next();
+ }
+ gOnce = true;
+ }
+}
+
enum BenchMode {
kNormal_BenchMode,
kDeferred_BenchMode,
@@ -63,7 +114,7 @@ public:
if (fBench) {
BenchRegistry::Factory f = fBench->factory();
fBench = fBench->next();
- return f();
+ return (*f)();
}
return NULL;
}
@@ -295,6 +346,7 @@ static bool HasConverged(double prevPerLoop, double currPerLoop, double currRaw)
int tool_main(int argc, char** argv);
int tool_main(int argc, char** argv) {
+ register_gm_benches();
SkCommandLineFlags::Parse(argc, argv);
#if SK_ENABLE_INST_COUNT
if (FLAGS_leaks) {
« bench/SkGMBench.cpp ('K') | « bench/SkGMBench.cpp ('k') | gm/convexpolyclip.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698