blob: f43c37e77d51d390955bccb1e3bb18e7abf74da3 [file] [log] [blame]
reed@google.comb8c39172012-03-07 12:36:07 +00001#include "SkBenchmark.h"
2#include "SkColorPriv.h"
3#include "SkMatrix.h"
4#include "SkRandom.h"
5#include "SkString.h"
6#include "SkPaint.h"
7
8#define TILE(x, width) (((x) & 0xFFFF) * width >> 16)
9
10class InterpBench : public SkBenchmark {
11 enum {
12 kBuffer = 128,
13 kLoop = 20000
14 };
15 SkString fName;
16 int16_t fDst[kBuffer];
17 float fFx, fDx;
18public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000019 InterpBench(const char name[]) {
reed@google.comb8c39172012-03-07 12:36:07 +000020 fName.printf("interp_%s", name);
robertphillips@google.com09042b82012-04-06 20:01:46 +000021 fFx = 3.3f;
22 fDx = 0.1257f;
tomhudson@google.com9dc27132012-09-13 15:50:24 +000023 fIsRendering = false;
reed@google.comb8c39172012-03-07 12:36:07 +000024 }
25
26 virtual void performTest(int16_t dst[], float x, float dx, int count) = 0;
27
28protected:
29 virtual int mulLoopCount() const { return 1; }
30
31 virtual const char* onGetName() {
32 return fName.c_str();
33 }
34
sugoi@google.com77472f02013-03-05 18:50:01 +000035 virtual void onDraw(SkCanvas*) {
mtklein@google.comc2897432013-09-10 19:23:38 +000036 int n = this->getLoops() * this->mulLoopCount();
reed@google.comb8c39172012-03-07 12:36:07 +000037 for (int i = 0; i < n; i++) {
38 this->performTest(fDst, fFx, fDx, kBuffer);
39 }
40 }
41
42private:
43 typedef SkBenchmark INHERITED;
44};
45
46class Fixed16D16Interp : public InterpBench {
47public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000048 Fixed16D16Interp() : INHERITED("16.16") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +000049
reed@google.comb8c39172012-03-07 12:36:07 +000050protected:
51 virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
52 SkFixed curr = SkFloatToFixed(fx);
53 SkFixed step = SkFloatToFixed(dx);
54 for (int i = 0; i < count; i += 4) {
55 dst[i + 0] = TILE(curr, count); curr += step;
56 dst[i + 1] = TILE(curr, count); curr += step;
57 dst[i + 2] = TILE(curr, count); curr += step;
58 dst[i + 3] = TILE(curr, count); curr += step;
59 }
60 }
61private:
62 typedef InterpBench INHERITED;
63};
64
65class Fixed32D32Interp : public InterpBench {
66public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000067 Fixed32D32Interp() : INHERITED("32.32") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +000068
reed@google.comb8c39172012-03-07 12:36:07 +000069protected:
70 virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
71 int64_t curr = (int64_t)(fx * 65536 * 655536);
72 int64_t step = (int64_t)(dx * 65536 * 655536);
73 SkFixed tmp;
74 for (int i = 0; i < count; i += 4) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +000075 tmp = (SkFixed)(curr >> 16);
76 dst[i + 0] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +000077 curr += step;
78
rmistry@google.comfbfcd562012-08-23 18:09:54 +000079 tmp = (SkFixed)(curr >> 16);
80 dst[i + 1] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +000081 curr += step;
82
rmistry@google.comfbfcd562012-08-23 18:09:54 +000083 tmp = (SkFixed)(curr >> 16);
84 dst[i + 2] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +000085 curr += step;
86
rmistry@google.comfbfcd562012-08-23 18:09:54 +000087 tmp = (SkFixed)(curr >> 16);
88 dst[i + 3] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +000089 curr += step;
reed@google.comb8c39172012-03-07 12:36:07 +000090 }
91 }
92private:
93 typedef InterpBench INHERITED;
94};
95
96class Fixed16D48Interp : public InterpBench {
97public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000098 Fixed16D48Interp() : INHERITED("16.48") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +000099
reed@google.comb8c39172012-03-07 12:36:07 +0000100protected:
101 virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
102 int64_t curr = (int64_t)(fx * 65536 * 655536 * 65536);
103 int64_t step = (int64_t)(dx * 65536 * 655536 * 65536);
104 SkFixed tmp;
105 for (int i = 0; i < count; i += 4) {
caryclark@google.com19069a22012-06-06 12:11:45 +0000106 tmp = (SkFixed) (curr >> 32); dst[i + 0] = TILE(tmp, count); curr += step;
107 tmp = (SkFixed) (curr >> 32); dst[i + 1] = TILE(tmp, count); curr += step;
108 tmp = (SkFixed) (curr >> 32); dst[i + 2] = TILE(tmp, count); curr += step;
109 tmp = (SkFixed) (curr >> 32); dst[i + 3] = TILE(tmp, count); curr += step;
reed@google.comb8c39172012-03-07 12:36:07 +0000110 }
111 }
112private:
113 typedef InterpBench INHERITED;
114};
115
116class FloatInterp : public InterpBench {
117public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000118 FloatInterp() : INHERITED("float") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000119
reed@google.comb8c39172012-03-07 12:36:07 +0000120protected:
121 virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
122 SkFixed tmp;
123 for (int i = 0; i < count; i += 4) {
124 tmp = SkFloatToFixed(fx); dst[i + 0] = TILE(tmp, count); fx += dx;
125 tmp = SkFloatToFixed(fx); dst[i + 1] = TILE(tmp, count); fx += dx;
126 tmp = SkFloatToFixed(fx); dst[i + 2] = TILE(tmp, count); fx += dx;
127 tmp = SkFloatToFixed(fx); dst[i + 3] = TILE(tmp, count); fx += dx;
128 }
129 }
130private:
131 typedef InterpBench INHERITED;
132};
133
134class DoubleInterp : public InterpBench {
135public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000136 DoubleInterp() : INHERITED("double") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000137
reed@google.comb8c39172012-03-07 12:36:07 +0000138protected:
139 virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
140 double ffx = fx;
141 double ddx = dx;
142 SkFixed tmp;
143 for (int i = 0; i < count; i += 4) {
144 tmp = SkDoubleToFixed(ffx); dst[i + 0] = TILE(tmp, count); ffx += ddx;
145 tmp = SkDoubleToFixed(ffx); dst[i + 1] = TILE(tmp, count); ffx += ddx;
146 tmp = SkDoubleToFixed(ffx); dst[i + 2] = TILE(tmp, count); ffx += ddx;
147 tmp = SkDoubleToFixed(ffx); dst[i + 3] = TILE(tmp, count); ffx += ddx;
148 }
149 }
150private:
151 typedef InterpBench INHERITED;
152};
153
154///////////////////////////////////////////////////////////////////////////////
155
mtklein@google.com410e6e82013-09-13 19:52:27 +0000156DEF_BENCH( return new Fixed16D16Interp(); )
157DEF_BENCH( return new Fixed32D32Interp(); )
158DEF_BENCH( return new Fixed16D48Interp(); )
159DEF_BENCH( return new FloatInterp(); )
160DEF_BENCH( return new DoubleInterp(); )