2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2009-01-05 03:34:50 +00:00
|
|
|
#ifndef SkBenchmark_DEFINED
|
|
|
|
#define SkBenchmark_DEFINED
|
|
|
|
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkPoint.h"
|
2013-09-25 21:42:12 +00:00
|
|
|
#include "SkString.h"
|
2009-01-26 23:15:37 +00:00
|
|
|
#include "SkTRegistry.h"
|
2009-01-05 03:34:50 +00:00
|
|
|
|
2012-10-16 15:57:13 +00:00
|
|
|
#define DEF_BENCH(code) \
|
2013-09-13 19:52:27 +00:00
|
|
|
static SkBenchmark* SK_MACRO_APPEND_LINE(F_)() { code; } \
|
2012-10-16 15:57:13 +00:00
|
|
|
static BenchRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* With the above macros, you can register benches as follows (at the bottom
|
|
|
|
* of your .cpp)
|
|
|
|
*
|
2013-09-13 19:52:27 +00:00
|
|
|
* DEF_BENCH(return new MyBenchmark(...))
|
|
|
|
* DEF_BENCH(return new MyBenchmark(...))
|
|
|
|
* DEF_BENCH(return new MyBenchmark(...))
|
2012-10-16 15:57:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
class SkCanvas;
|
2009-01-19 20:08:35 +00:00
|
|
|
class SkPaint;
|
2009-01-05 03:34:50 +00:00
|
|
|
|
2009-10-19 17:39:46 +00:00
|
|
|
class SkTriState {
|
|
|
|
public:
|
|
|
|
enum State {
|
|
|
|
kDefault,
|
|
|
|
kTrue,
|
|
|
|
kFalse
|
|
|
|
};
|
2013-09-10 19:23:38 +00:00
|
|
|
static const char* Name[];
|
2009-10-19 17:39:46 +00:00
|
|
|
};
|
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
class SkBenchmark : public SkRefCnt {
|
|
|
|
public:
|
2012-06-21 20:25:03 +00:00
|
|
|
SK_DECLARE_INST_COUNT(SkBenchmark)
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
SkBenchmark();
|
2009-01-19 20:08:35 +00:00
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
const char* getName();
|
|
|
|
SkIPoint getSize();
|
2012-08-13 14:03:31 +00:00
|
|
|
|
|
|
|
// Call before draw, allows the benchmark to do setup work outside of the
|
|
|
|
// timer. When a benchmark is repeatedly drawn, this should be called once
|
|
|
|
// before the initial draw.
|
|
|
|
void preDraw();
|
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
void draw(SkCanvas*);
|
2012-08-13 14:03:31 +00:00
|
|
|
|
|
|
|
// Call after draw, allows the benchmark to do cleanup work outside of the
|
|
|
|
// timer. When a benchmark is repeatedly drawn, this is only called once
|
|
|
|
// after the last draw.
|
|
|
|
void postDraw();
|
|
|
|
|
2009-01-19 20:08:35 +00:00
|
|
|
void setForceAlpha(int alpha) {
|
|
|
|
fForceAlpha = alpha;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-01-19 20:08:35 +00:00
|
|
|
void setForceAA(bool aa) {
|
|
|
|
fForceAA = aa;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-08-04 18:17:15 +00:00
|
|
|
void setForceFilter(bool filter) {
|
|
|
|
fForceFilter = filter;
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-10-19 17:39:46 +00:00
|
|
|
void setDither(SkTriState::State state) {
|
|
|
|
fDither = state;
|
|
|
|
}
|
2009-09-02 21:12:42 +00:00
|
|
|
|
2012-09-13 15:50:24 +00:00
|
|
|
/** If true; the benchmark does rendering; if false, the benchmark
|
|
|
|
doesn't, and so need not be re-run in every different rendering
|
|
|
|
mode. */
|
|
|
|
bool isRendering() {
|
|
|
|
return fIsRendering;
|
|
|
|
}
|
|
|
|
|
2013-05-29 15:39:54 +00:00
|
|
|
/** Assign masks for paint-flags. These will be applied when setupPaint()
|
|
|
|
* is called.
|
|
|
|
*
|
|
|
|
* Performs the following on the paint:
|
|
|
|
* uint32_t flags = paint.getFlags();
|
|
|
|
* flags &= ~clearMask;
|
|
|
|
* flags |= orMask;
|
|
|
|
* paint.setFlags(flags);
|
|
|
|
*/
|
|
|
|
void setPaintMasks(uint32_t orMask, uint32_t clearMask) {
|
|
|
|
fOrMask = orMask;
|
|
|
|
fClearMask = clearMask;
|
|
|
|
}
|
|
|
|
|
2013-09-10 19:23:38 +00:00
|
|
|
// The bench framework calls this to control the runtime of a bench.
|
|
|
|
void setLoops(int loops) {
|
|
|
|
fLoops = loops;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Each bench should do its main work in a loop like this:
|
|
|
|
// for (int i = 0; i < this->getLoops(); i++) { <work here> }
|
|
|
|
int getLoops() const { return fLoops; }
|
2013-05-29 15:39:54 +00:00
|
|
|
|
2013-09-25 21:42:12 +00:00
|
|
|
static void SetResourcePath(const char* resPath) { gResourcePath.set(resPath); }
|
|
|
|
|
|
|
|
static SkString& GetResourcePath() { return gResourcePath; }
|
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
protected:
|
2012-11-15 19:52:20 +00:00
|
|
|
virtual void setupPaint(SkPaint* paint);
|
2009-01-19 20:08:35 +00:00
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
virtual const char* onGetName() = 0;
|
2012-08-13 14:03:31 +00:00
|
|
|
virtual void onPreDraw() {}
|
2009-01-05 03:34:50 +00:00
|
|
|
virtual void onDraw(SkCanvas*) = 0;
|
2012-08-13 14:03:31 +00:00
|
|
|
virtual void onPostDraw() {}
|
2009-01-26 23:15:37 +00:00
|
|
|
|
|
|
|
virtual SkIPoint onGetSize();
|
2012-09-13 15:50:24 +00:00
|
|
|
/// Defaults to true.
|
|
|
|
bool fIsRendering;
|
2009-01-26 23:15:37 +00:00
|
|
|
|
2009-01-19 20:08:35 +00:00
|
|
|
private:
|
|
|
|
int fForceAlpha;
|
|
|
|
bool fForceAA;
|
2009-08-04 18:17:15 +00:00
|
|
|
bool fForceFilter;
|
2009-10-19 17:39:46 +00:00
|
|
|
SkTriState::State fDither;
|
2013-05-29 15:39:54 +00:00
|
|
|
uint32_t fOrMask, fClearMask;
|
2013-09-10 19:23:38 +00:00
|
|
|
int fLoops;
|
2013-09-25 21:42:12 +00:00
|
|
|
static SkString gResourcePath;
|
2012-06-21 20:25:03 +00:00
|
|
|
|
|
|
|
typedef SkRefCnt INHERITED;
|
2009-01-05 03:34:50 +00:00
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
typedef SkTRegistry<SkBenchmark*(*)()> BenchRegistry;
|
2009-01-26 23:15:37 +00:00
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
#endif
|