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

Unified Diff: bench/benchmain.cpp

Issue 178893002: Simplify GM-as-bench code. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 10 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/benchmain.cpp
diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp
index ba9bfcac56d4e1b82bfe44872d5e256a2ab18ba6..6eea11fc149a0d763df45f0cced79757a8501fbc 100644
--- a/bench/benchmain.cpp
+++ b/bench/benchmain.cpp
@@ -35,53 +35,6 @@ class GrContext;
#include <limits>
-// Note that ~SkTDArray is not virtual. This inherits privately to bar using this as a SkTDArray*.
-class RefCntArray : private SkTDArray<SkRefCnt*> {
-public:
- SkRefCnt** append() { return this->INHERITED::append(); }
- ~RefCntArray() { this->unrefAll(); }
-private:
- typedef SkTDArray<SkRefCnt*> INHERITED;
-};
-
-class GMBenchFactory : public SkBenchmarkFactory {
-public:
- GMBenchFactory(const skiagm::GMRegistry* gmreg)
- : fGMFactory(gmreg->factory()) {
- fSelfRegistry = SkNEW_ARGS(BenchRegistry, (this));
- }
-
- virtual ~GMBenchFactory() { SkDELETE(fSelfRegistry); }
-
- virtual SkBenchmark* operator()() const SK_OVERRIDE {
- skiagm::GM* gm = fGMFactory(NULL);
- gm->setMode(skiagm::GM::kBench_Mode);
- return SkNEW_ARGS(SkGMBench, (gm));
- }
-
-private:
- skiagm::GMRegistry::Factory fGMFactory;
- BenchRegistry* fSelfRegistry;
-};
-
-static void register_gm_benches() {
- static bool gOnce;
- static RefCntArray gGMBenchFactories;
-
- 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()) {
- *gGMBenchFactories.append() = SkNEW_ARGS(GMBenchFactory, (gmreg));
- }
- SkDELETE(gm);
- gmreg = gmreg->next();
- }
- gOnce = true;
- }
-}
-
enum BenchMode {
kNormal_BenchMode,
kDeferred_BenchMode,
@@ -99,19 +52,29 @@ static const char kDefaultsConfigStr[] = "defaults";
class Iter {
public:
- Iter() : fBench(BenchRegistry::Head()) {}
+ Iter() : fBenches(BenchRegistry::Head()), fGMs(skiagm::GMRegistry::Head()) {}
SkBenchmark* next() {
- if (fBench) {
- BenchRegistry::Factory f = fBench->factory();
- fBench = fBench->next();
+ if (fBenches) {
+ BenchRegistry::Factory f = fBenches->factory();
+ fBenches = fBenches->next();
return (*f)();
}
+
+ while (fGMs) {
+ SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL));
+ fGMs = fGMs->next();
+ if (gm->getFlags() & skiagm::GM::kAsBench_Flag) {
+ return SkNEW_ARGS(SkGMBench, (gm.detach()));
+ }
+ }
+
return NULL;
}
private:
- const BenchRegistry* fBench;
+ const BenchRegistry* fBenches;
+ const skiagm::GMRegistry* fGMs;
};
class AutoPrePostDraw {
@@ -317,7 +280,6 @@ 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) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698