blob: adffd50e1d905581f8c167b90f2401722fd3b651 [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
16class SkCanvas;
reed@android.com4bc19832009-01-19 20:08:35 +000017class SkPaint;
reed@android.combd700c32009-01-05 03:34:50 +000018
reed@android.com4e635f92009-10-19 17:39:46 +000019class SkTriState {
20public:
21 enum State {
22 kDefault,
23 kTrue,
24 kFalse
25 };
26};
27
reed@android.combd700c32009-01-05 03:34:50 +000028class SkBenchmark : public SkRefCnt {
29public:
reed@android.come9d00602009-09-02 21:12:42 +000030 SkBenchmark(void* defineDict);
reed@android.com4bc19832009-01-19 20:08:35 +000031
reed@android.combd700c32009-01-05 03:34:50 +000032 const char* getName();
33 SkIPoint getSize();
34 void draw(SkCanvas*);
reed@android.com4bc19832009-01-19 20:08:35 +000035
36 void setForceAlpha(int alpha) {
37 fForceAlpha = alpha;
38 }
39
40 void setForceAA(bool aa) {
41 fForceAA = aa;
42 }
reed@android.com29348cb2009-08-04 18:17:15 +000043
44 void setForceFilter(bool filter) {
45 fForceFilter = filter;
46 }
reed@android.com4e635f92009-10-19 17:39:46 +000047
48 void setDither(SkTriState::State state) {
49 fDither = state;
50 }
reed@android.come9d00602009-09-02 21:12:42 +000051
agl@chromium.org652807b2010-04-27 15:47:34 +000052 void setStrokeWidth(SkScalar width) {
53 strokeWidth = width;
54 fHasStrokeWidth = true;
55 }
56
57 SkScalar getStrokeWidth() {
58 return strokeWidth;
59 }
60
61 bool hasStrokeWidth() {
62 return fHasStrokeWidth;
63 }
64
reed@android.come9d00602009-09-02 21:12:42 +000065 const char* findDefine(const char* key) const;
reed@android.com0c9da392010-02-22 19:50:13 +000066 bool findDefine32(const char* key, int32_t* value) const;
67 bool findDefineScalar(const char* key, SkScalar* value) const;
reed@android.come9d00602009-09-02 21:12:42 +000068
reed@android.combd700c32009-01-05 03:34:50 +000069protected:
reed@android.com4bc19832009-01-19 20:08:35 +000070 void setupPaint(SkPaint* paint);
71
reed@android.combd700c32009-01-05 03:34:50 +000072 virtual const char* onGetName() = 0;
reed@android.combd700c32009-01-05 03:34:50 +000073 virtual void onDraw(SkCanvas*) = 0;
reed@android.comf523e252009-01-26 23:15:37 +000074
75 virtual SkIPoint onGetSize();
76
reed@android.com4bc19832009-01-19 20:08:35 +000077private:
reed@android.come9d00602009-09-02 21:12:42 +000078 const SkTDict<const char*>* fDict;
reed@android.com4bc19832009-01-19 20:08:35 +000079 int fForceAlpha;
80 bool fForceAA;
reed@android.com29348cb2009-08-04 18:17:15 +000081 bool fForceFilter;
reed@android.com4e635f92009-10-19 17:39:46 +000082 SkTriState::State fDither;
agl@chromium.org652807b2010-04-27 15:47:34 +000083 bool fHasStrokeWidth;
84 SkScalar strokeWidth;
reed@android.combd700c32009-01-05 03:34:50 +000085};
86
reed@android.comf523e252009-01-26 23:15:37 +000087typedef SkTRegistry<SkBenchmark*, void*> BenchRegistry;
88
reed@android.combd700c32009-01-05 03:34:50 +000089#endif