blob: 28314ea11b3203219940a1d58ca7caad8daddafc [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.combd700c32009-01-05 03:34:50 +00008#ifndef SkBenchmark_DEFINED
9#define SkBenchmark_DEFINED
10
11#include "SkRefCnt.h"
12#include "SkPoint.h"
reed@android.come9d00602009-09-02 21:12:42 +000013#include "SkTDict.h"
reed@android.comf523e252009-01-26 23:15:37 +000014#include "SkTRegistry.h"
reed@android.combd700c32009-01-05 03:34:50 +000015
tomhudson@google.comca529d32011-10-28 15:34:49 +000016#ifdef SK_DEBUG
17 #define SkBENCHLOOP(n) 1
18#else
19 #define SkBENCHLOOP(n) n
20#endif
21
reed@android.combd700c32009-01-05 03:34:50 +000022class SkCanvas;
reed@android.com4bc19832009-01-19 20:08:35 +000023class SkPaint;
reed@android.combd700c32009-01-05 03:34:50 +000024
reed@android.com4e635f92009-10-19 17:39:46 +000025class SkTriState {
26public:
27 enum State {
28 kDefault,
29 kTrue,
30 kFalse
31 };
32};
33
reed@android.combd700c32009-01-05 03:34:50 +000034class SkBenchmark : public SkRefCnt {
35public:
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000036 SK_DECLARE_INST_COUNT(SkBenchmark)
37
reed@android.come9d00602009-09-02 21:12:42 +000038 SkBenchmark(void* defineDict);
reed@android.com4bc19832009-01-19 20:08:35 +000039
reed@android.combd700c32009-01-05 03:34:50 +000040 const char* getName();
41 SkIPoint getSize();
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +000042
43 // Call before draw, allows the benchmark to do setup work outside of the
44 // timer. When a benchmark is repeatedly drawn, this should be called once
45 // before the initial draw.
46 void preDraw();
47
reed@android.combd700c32009-01-05 03:34:50 +000048 void draw(SkCanvas*);
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +000049
50 // Call after draw, allows the benchmark to do cleanup work outside of the
51 // timer. When a benchmark is repeatedly drawn, this is only called once
52 // after the last draw.
53 void postDraw();
54
reed@android.com4bc19832009-01-19 20:08:35 +000055 void setForceAlpha(int alpha) {
56 fForceAlpha = alpha;
57 }
58
59 void setForceAA(bool aa) {
60 fForceAA = aa;
61 }
reed@android.com29348cb2009-08-04 18:17:15 +000062
63 void setForceFilter(bool filter) {
64 fForceFilter = filter;
65 }
reed@android.com4e635f92009-10-19 17:39:46 +000066
67 void setDither(SkTriState::State state) {
68 fDither = state;
69 }
reed@android.come9d00602009-09-02 21:12:42 +000070
agl@chromium.org652807b2010-04-27 15:47:34 +000071 void setStrokeWidth(SkScalar width) {
72 strokeWidth = width;
73 fHasStrokeWidth = true;
74 }
75
76 SkScalar getStrokeWidth() {
77 return strokeWidth;
78 }
79
80 bool hasStrokeWidth() {
81 return fHasStrokeWidth;
82 }
83
reed@android.come9d00602009-09-02 21:12:42 +000084 const char* findDefine(const char* key) const;
reed@android.com0c9da392010-02-22 19:50:13 +000085 bool findDefine32(const char* key, int32_t* value) const;
86 bool findDefineScalar(const char* key, SkScalar* value) const;
reed@android.come9d00602009-09-02 21:12:42 +000087
reed@android.combd700c32009-01-05 03:34:50 +000088protected:
reed@android.com4bc19832009-01-19 20:08:35 +000089 void setupPaint(SkPaint* paint);
90
reed@android.combd700c32009-01-05 03:34:50 +000091 virtual const char* onGetName() = 0;
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +000092 virtual void onPreDraw() {}
reed@android.combd700c32009-01-05 03:34:50 +000093 virtual void onDraw(SkCanvas*) = 0;
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +000094 virtual void onPostDraw() {}
reed@android.comf523e252009-01-26 23:15:37 +000095
96 virtual SkIPoint onGetSize();
97
reed@android.com4bc19832009-01-19 20:08:35 +000098private:
reed@android.come9d00602009-09-02 21:12:42 +000099 const SkTDict<const char*>* fDict;
reed@android.com4bc19832009-01-19 20:08:35 +0000100 int fForceAlpha;
101 bool fForceAA;
reed@android.com29348cb2009-08-04 18:17:15 +0000102 bool fForceFilter;
reed@android.com4e635f92009-10-19 17:39:46 +0000103 SkTriState::State fDither;
agl@chromium.org652807b2010-04-27 15:47:34 +0000104 bool fHasStrokeWidth;
105 SkScalar strokeWidth;
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +0000106
107 typedef SkRefCnt INHERITED;
reed@android.combd700c32009-01-05 03:34:50 +0000108};
109
reed@android.comf523e252009-01-26 23:15:37 +0000110typedef SkTRegistry<SkBenchmark*, void*> BenchRegistry;
111
reed@android.combd700c32009-01-05 03:34:50 +0000112#endif