blob: 5019b23e1af9419c8914f168a52fb703235c7492 [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:
reed@android.come9d00602009-09-02 21:12:42 +000036 SkBenchmark(void* defineDict);
reed@android.com4bc19832009-01-19 20:08:35 +000037
reed@android.combd700c32009-01-05 03:34:50 +000038 const char* getName();
39 SkIPoint getSize();
40 void draw(SkCanvas*);
reed@android.com4bc19832009-01-19 20:08:35 +000041
42 void setForceAlpha(int alpha) {
43 fForceAlpha = alpha;
44 }
45
46 void setForceAA(bool aa) {
47 fForceAA = aa;
48 }
reed@android.com29348cb2009-08-04 18:17:15 +000049
50 void setForceFilter(bool filter) {
51 fForceFilter = filter;
52 }
reed@android.com4e635f92009-10-19 17:39:46 +000053
54 void setDither(SkTriState::State state) {
55 fDither = state;
56 }
reed@android.come9d00602009-09-02 21:12:42 +000057
agl@chromium.org652807b2010-04-27 15:47:34 +000058 void setStrokeWidth(SkScalar width) {
59 strokeWidth = width;
60 fHasStrokeWidth = true;
61 }
62
63 SkScalar getStrokeWidth() {
64 return strokeWidth;
65 }
66
67 bool hasStrokeWidth() {
68 return fHasStrokeWidth;
69 }
70
reed@android.come9d00602009-09-02 21:12:42 +000071 const char* findDefine(const char* key) const;
reed@android.com0c9da392010-02-22 19:50:13 +000072 bool findDefine32(const char* key, int32_t* value) const;
73 bool findDefineScalar(const char* key, SkScalar* value) const;
reed@android.come9d00602009-09-02 21:12:42 +000074
reed@android.combd700c32009-01-05 03:34:50 +000075protected:
reed@android.com4bc19832009-01-19 20:08:35 +000076 void setupPaint(SkPaint* paint);
77
reed@android.combd700c32009-01-05 03:34:50 +000078 virtual const char* onGetName() = 0;
reed@android.combd700c32009-01-05 03:34:50 +000079 virtual void onDraw(SkCanvas*) = 0;
reed@android.comf523e252009-01-26 23:15:37 +000080
81 virtual SkIPoint onGetSize();
82
reed@android.com4bc19832009-01-19 20:08:35 +000083private:
reed@android.come9d00602009-09-02 21:12:42 +000084 const SkTDict<const char*>* fDict;
reed@android.com4bc19832009-01-19 20:08:35 +000085 int fForceAlpha;
86 bool fForceAA;
reed@android.com29348cb2009-08-04 18:17:15 +000087 bool fForceFilter;
reed@android.com4e635f92009-10-19 17:39:46 +000088 SkTriState::State fDither;
agl@chromium.org652807b2010-04-27 15:47:34 +000089 bool fHasStrokeWidth;
90 SkScalar strokeWidth;
reed@android.combd700c32009-01-05 03:34:50 +000091};
92
reed@android.comf523e252009-01-26 23:15:37 +000093typedef SkTRegistry<SkBenchmark*, void*> BenchRegistry;
94
reed@android.combd700c32009-01-05 03:34:50 +000095#endif