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"
|
2009-09-02 21:12:42 +00:00
|
|
|
#include "SkTDict.h"
|
2009-01-26 23:15:37 +00:00
|
|
|
#include "SkTRegistry.h"
|
2009-01-05 03:34:50 +00:00
|
|
|
|
2011-10-28 15:34:49 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
#define SkBENCHLOOP(n) 1
|
|
|
|
#else
|
|
|
|
#define SkBENCHLOOP(n) n
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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)
|
|
|
|
|
2009-09-02 21:12:42 +00:00
|
|
|
SkBenchmark(void* defineDict);
|
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
|
|
|
|
2010-04-27 15:47:34 +00:00
|
|
|
void setStrokeWidth(SkScalar width) {
|
|
|
|
strokeWidth = width;
|
|
|
|
fHasStrokeWidth = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkScalar getStrokeWidth() {
|
|
|
|
return strokeWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasStrokeWidth() {
|
|
|
|
return fHasStrokeWidth;
|
|
|
|
}
|
|
|
|
|
2009-09-02 21:12:42 +00:00
|
|
|
const char* findDefine(const char* key) const;
|
2010-02-22 19:50:13 +00:00
|
|
|
bool findDefine32(const char* key, int32_t* value) const;
|
|
|
|
bool findDefineScalar(const char* key, SkScalar* value) const;
|
2009-09-02 21:12:42 +00:00
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
protected:
|
2009-01-19 20:08:35 +00:00
|
|
|
void setupPaint(SkPaint* paint);
|
|
|
|
|
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();
|
|
|
|
|
2009-01-19 20:08:35 +00:00
|
|
|
private:
|
2009-09-02 21:12:42 +00:00
|
|
|
const SkTDict<const char*>* fDict;
|
2009-01-19 20:08:35 +00:00
|
|
|
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;
|
2010-04-27 15:47:34 +00:00
|
|
|
bool fHasStrokeWidth;
|
|
|
|
SkScalar strokeWidth;
|
2012-06-21 20:25:03 +00:00
|
|
|
|
|
|
|
typedef SkRefCnt INHERITED;
|
2009-01-05 03:34:50 +00:00
|
|
|
};
|
|
|
|
|
2009-01-26 23:15:37 +00:00
|
|
|
typedef SkTRegistry<SkBenchmark*, void*> BenchRegistry;
|
|
|
|
|
2009-01-05 03:34:50 +00:00
|
|
|
#endif
|