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
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "tools/Registry.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
|
|
|
*/
|
|
|
|
|
2017-10-11 19:34:27 +00:00
|
|
|
struct GrContextOptions;
|
2021-04-30 23:16:12 +00:00
|
|
|
class GrRecordingContext;
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-10-11 19:34:27 +00:00
|
|
|
// Allows a benchmark to override options used to construct the GrContext.
|
|
|
|
virtual void modifyGrContextOptions(GrContextOptions*) {}
|
|
|
|
|
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
|
|
|
|
2015-12-02 17:05:37 +00:00
|
|
|
virtual void getGpuStats(SkCanvas*, SkTArray<SkString>* keys, SkTArray<double>* values) {}
|
|
|
|
|
2021-04-30 23:16:12 +00:00
|
|
|
// Replaces the GrRecordingContext's dmsaaStats() with a single frame of this benchmark.
|
|
|
|
virtual bool getDMSAAStats(GrRecordingContext*) { return false; }
|
|
|
|
|
2019-05-31 15:03:07 +00:00
|
|
|
// Count of units (pixels, whatever) being exercised, to scale timing by.
|
|
|
|
int getUnits() const { return fUnits; }
|
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
protected:
|
2019-05-31 15:03:07 +00:00
|
|
|
void setUnits(int units) { SkASSERT(units > 0); fUnits = units; }
|
|
|
|
|
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:
|
2019-05-31 15:03:07 +00:00
|
|
|
int fUnits = 1;
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = SkRefCnt;
|
2009-01-05 03:34:50 +00:00
|
|
|
};
|
|
|
|
|
2017-01-11 18:58:55 +00:00
|
|
|
typedef sk_tools::Registry<Benchmark*(*)(void*)> BenchRegistry;
|
2009-01-26 23:15:37 +00:00
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
#endif
|