blob: b19af8f35fa8e8e6f1454807ce8d8029187b3103 [file] [log] [blame]
tfarinaf168b862014-06-19 12:32:29 -07001#include "Benchmark.h"
reed@google.comb8c39172012-03-07 12:36:07 +00002#include "SkColorPriv.h"
3#include "SkMatrix.h"
tfarinaf168b862014-06-19 12:32:29 -07004#include "SkPaint.h"
reed@google.comb8c39172012-03-07 12:36:07 +00005#include "SkRandom.h"
6#include "SkString.h"
reed@google.comb8c39172012-03-07 12:36:07 +00007
8#define TILE(x, width) (((x) & 0xFFFF) * width >> 16)
9
tfarinaf168b862014-06-19 12:32:29 -070010class InterpBench : public Benchmark {
reed@google.comb8c39172012-03-07 12:36:07 +000011 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;
commit-bot@chromium.org644629c2013-11-21 06:21:58 +000023 }
24
25 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
26 return backend == kNonRendering_Backend;
reed@google.comb8c39172012-03-07 12:36:07 +000027 }
28
29 virtual void performTest(int16_t dst[], float x, float dx, int count) = 0;
30
31protected:
32 virtual int mulLoopCount() const { return 1; }
33
34 virtual const char* onGetName() {
35 return fName.c_str();
36 }
37
commit-bot@chromium.org33614712013-12-03 18:17:16 +000038 virtual void onDraw(const int loops, SkCanvas*) {
39 int n = loops * this->mulLoopCount();
reed@google.comb8c39172012-03-07 12:36:07 +000040 for (int i = 0; i < n; i++) {
41 this->performTest(fDst, fFx, fDx, kBuffer);
42 }
43 }
44
45private:
tfarinaf168b862014-06-19 12:32:29 -070046 typedef Benchmark INHERITED;
reed@google.comb8c39172012-03-07 12:36:07 +000047};
48
49class Fixed16D16Interp : public InterpBench {
50public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000051 Fixed16D16Interp() : INHERITED("16.16") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +000052
reed@google.comb8c39172012-03-07 12:36:07 +000053protected:
54 virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
55 SkFixed curr = SkFloatToFixed(fx);
56 SkFixed step = SkFloatToFixed(dx);
57 for (int i = 0; i < count; i += 4) {
58 dst[i + 0] = TILE(curr, count); curr += step;
59 dst[i + 1] = TILE(curr, count); curr += step;
60 dst[i + 2] = TILE(curr, count); curr += step;
61 dst[i + 3] = TILE(curr, count); curr += step;
62 }
63 }
64private:
65 typedef InterpBench INHERITED;
66};
67
68class Fixed32D32Interp : public InterpBench {
69public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000070 Fixed32D32Interp() : INHERITED("32.32") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +000071
reed@google.comb8c39172012-03-07 12:36:07 +000072protected:
73 virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
74 int64_t curr = (int64_t)(fx * 65536 * 655536);
75 int64_t step = (int64_t)(dx * 65536 * 655536);
76 SkFixed tmp;
77 for (int i = 0; i < count; i += 4) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +000078 tmp = (SkFixed)(curr >> 16);
79 dst[i + 0] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +000080 curr += step;
81
rmistry@google.comfbfcd562012-08-23 18:09:54 +000082 tmp = (SkFixed)(curr >> 16);
83 dst[i + 1] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +000084 curr += step;
85
rmistry@google.comfbfcd562012-08-23 18:09:54 +000086 tmp = (SkFixed)(curr >> 16);
87 dst[i + 2] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +000088 curr += step;
89
rmistry@google.comfbfcd562012-08-23 18:09:54 +000090 tmp = (SkFixed)(curr >> 16);
91 dst[i + 3] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +000092 curr += step;
reed@google.comb8c39172012-03-07 12:36:07 +000093 }
94 }
95private:
96 typedef InterpBench INHERITED;
97};
98
99class Fixed16D48Interp : public InterpBench {
100public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000101 Fixed16D48Interp() : INHERITED("16.48") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000102
reed@google.comb8c39172012-03-07 12:36:07 +0000103protected:
104 virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
105 int64_t curr = (int64_t)(fx * 65536 * 655536 * 65536);
106 int64_t step = (int64_t)(dx * 65536 * 655536 * 65536);
107 SkFixed tmp;
108 for (int i = 0; i < count; i += 4) {
caryclark@google.com19069a22012-06-06 12:11:45 +0000109 tmp = (SkFixed) (curr >> 32); dst[i + 0] = TILE(tmp, count); curr += step;
110 tmp = (SkFixed) (curr >> 32); dst[i + 1] = TILE(tmp, count); curr += step;
111 tmp = (SkFixed) (curr >> 32); dst[i + 2] = TILE(tmp, count); curr += step;
112 tmp = (SkFixed) (curr >> 32); dst[i + 3] = TILE(tmp, count); curr += step;
reed@google.comb8c39172012-03-07 12:36:07 +0000113 }
114 }
115private:
116 typedef InterpBench INHERITED;
117};
118
119class FloatInterp : public InterpBench {
120public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000121 FloatInterp() : INHERITED("float") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000122
reed@google.comb8c39172012-03-07 12:36:07 +0000123protected:
124 virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
125 SkFixed tmp;
126 for (int i = 0; i < count; i += 4) {
127 tmp = SkFloatToFixed(fx); dst[i + 0] = TILE(tmp, count); fx += dx;
128 tmp = SkFloatToFixed(fx); dst[i + 1] = TILE(tmp, count); fx += dx;
129 tmp = SkFloatToFixed(fx); dst[i + 2] = TILE(tmp, count); fx += dx;
130 tmp = SkFloatToFixed(fx); dst[i + 3] = TILE(tmp, count); fx += dx;
131 }
132 }
133private:
134 typedef InterpBench INHERITED;
135};
136
137class DoubleInterp : public InterpBench {
138public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000139 DoubleInterp() : INHERITED("double") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000140
reed@google.comb8c39172012-03-07 12:36:07 +0000141protected:
142 virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
143 double ffx = fx;
144 double ddx = dx;
145 SkFixed tmp;
146 for (int i = 0; i < count; i += 4) {
147 tmp = SkDoubleToFixed(ffx); dst[i + 0] = TILE(tmp, count); ffx += ddx;
148 tmp = SkDoubleToFixed(ffx); dst[i + 1] = TILE(tmp, count); ffx += ddx;
149 tmp = SkDoubleToFixed(ffx); dst[i + 2] = TILE(tmp, count); ffx += ddx;
150 tmp = SkDoubleToFixed(ffx); dst[i + 3] = TILE(tmp, count); ffx += ddx;
151 }
152 }
153private:
154 typedef InterpBench INHERITED;
155};
156
157///////////////////////////////////////////////////////////////////////////////
158
mtklein@google.com410e6e82013-09-13 19:52:27 +0000159DEF_BENCH( return new Fixed16D16Interp(); )
160DEF_BENCH( return new Fixed32D32Interp(); )
161DEF_BENCH( return new Fixed16D48Interp(); )
162DEF_BENCH( return new FloatInterp(); )
163DEF_BENCH( return new DoubleInterp(); )