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
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#ifndef Benchmark_DEFINED
|
|
|
|
#define Benchmark_DEFINED
|
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
#include "SkPoint.h"
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "SkRefCnt.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
|
|
|
|
2015-05-13 18:54:00 +00:00
|
|
|
#define DEF_BENCH3(code, N) \
|
|
|
|
static BenchRegistry gBench##N([](void*) -> Benchmark* { code; });
|
|
|
|
#define DEF_BENCH2(code, N) DEF_BENCH3(code, N)
|
|
|
|
#define DEF_BENCH(code) DEF_BENCH2(code, __COUNTER__)
|
2012-10-16 15:57:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class Benchmark : public SkRefCnt {
|
2009-01-05 03:34:50 +00:00
|
|
|
public:
|
2014-06-19 19:32:29 +00:00
|
|
|
Benchmark();
|
2009-01-19 20:08:35 +00:00
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
const char* getName();
|
2014-09-10 19:05:59 +00:00
|
|
|
const char* getUniqueName();
|
2009-01-05 03:34:50 +00:00
|
|
|
SkIPoint getSize();
|
2012-08-13 14:03:31 +00:00
|
|
|
|
2013-11-21 06:21:58 +00:00
|
|
|
enum Backend {
|
|
|
|
kNonRendering_Backend,
|
|
|
|
kRaster_Backend,
|
|
|
|
kGPU_Backend,
|
|
|
|
kPDF_Backend,
|
2015-03-26 18:28:06 +00:00
|
|
|
kHWUI_Backend,
|
2013-11-21 06:21:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Call to determine whether the benchmark is intended for
|
|
|
|
// the rendering mode.
|
|
|
|
virtual bool isSuitableFor(Backend backend) {
|
|
|
|
return backend != kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
2015-06-25 17:51:56 +00:00
|
|
|
virtual int calculateLoops(int defaultLoops) const {
|
|
|
|
return defaultLoops;
|
|
|
|
}
|
|
|
|
|
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.
|
2015-09-30 19:11:07 +00:00
|
|
|
void delayedSetup();
|
2012-08-13 14:03:31 +00:00
|
|
|
|
2014-11-21 14:19:36 +00:00
|
|
|
// Called once before and after a series of draw calls to a single canvas.
|
|
|
|
// The setup/break down in these calls is not timed.
|
|
|
|
void perCanvasPreDraw(SkCanvas*);
|
|
|
|
void perCanvasPostDraw(SkCanvas*);
|
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
// Called just before and after each call to draw(). Not timed.
|
|
|
|
void preDraw(SkCanvas*);
|
|
|
|
void postDraw(SkCanvas*);
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
// Bench framework can tune loops to be large enough for stable timing.
|
2015-10-01 16:43:39 +00:00
|
|
|
void draw(int loops, SkCanvas*);
|
2012-08-13 14:03:31 +00:00
|
|
|
|
2009-01-19 20:08:35 +00:00
|
|
|
void setForceAlpha(int alpha) {
|
|
|
|
fForceAlpha = alpha;
|
|
|
|
}
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-06-30 14:43:14 +00:00
|
|
|
/*
|
|
|
|
* Benches which support running in a visual mode can advertise this functionality
|
|
|
|
*/
|
|
|
|
virtual bool isVisual() { return false; }
|
|
|
|
|
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;
|
2014-09-10 19:05:59 +00:00
|
|
|
virtual const char* onGetUniqueName() { return this->onGetName(); }
|
2015-09-30 19:11:07 +00:00
|
|
|
virtual void onDelayedSetup() {}
|
2014-11-21 14:19:36 +00:00
|
|
|
virtual void onPerCanvasPreDraw(SkCanvas*) {}
|
|
|
|
virtual void onPerCanvasPostDraw(SkCanvas*) {}
|
2015-09-30 19:11:07 +00:00
|
|
|
virtual void onPreDraw(SkCanvas*) {}
|
|
|
|
virtual void onPostDraw(SkCanvas*) {}
|
2013-12-03 18:17:16 +00:00
|
|
|
// Each bench should do its main work in a loop like this:
|
|
|
|
// for (int i = 0; i < loops; i++) { <work here> }
|
2015-10-01 16:43:39 +00:00
|
|
|
virtual void onDraw(int loops, SkCanvas*) = 0;
|
2009-01-26 23:15:37 +00:00
|
|
|
|
|
|
|
virtual SkIPoint onGetSize();
|
|
|
|
|
2009-01-19 20:08:35 +00:00
|
|
|
private:
|
|
|
|
int fForceAlpha;
|
2009-10-19 17:39:46 +00:00
|
|
|
SkTriState::State fDither;
|
2013-05-29 15:39:54 +00:00
|
|
|
uint32_t fOrMask, fClearMask;
|
2012-06-21 20:25:03 +00:00
|
|
|
|
|
|
|
typedef SkRefCnt INHERITED;
|
2009-01-05 03:34:50 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef SkTRegistry<Benchmark*(*)(void*)> BenchRegistry;
|
2009-01-26 23:15:37 +00:00
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
#endif
|