blob: 8171131ebc3bc084feb26889092fb1985167d28e [file] [log] [blame]
mtkleinf0599002015-07-13 06:18:39 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
reed@google.comb8c39172012-03-07 12:36:07 +00009#include "SkColorPriv.h"
10#include "SkMatrix.h"
tfarinaf168b862014-06-19 12:32:29 -070011#include "SkPaint.h"
reed@google.comb8c39172012-03-07 12:36:07 +000012#include "SkRandom.h"
13#include "SkString.h"
reed@google.comb8c39172012-03-07 12:36:07 +000014
15#define TILE(x, width) (((x) & 0xFFFF) * width >> 16)
16
tfarinaf168b862014-06-19 12:32:29 -070017class InterpBench : public Benchmark {
reed@google.comb8c39172012-03-07 12:36:07 +000018 enum {
19 kBuffer = 128,
20 kLoop = 20000
21 };
22 SkString fName;
23 int16_t fDst[kBuffer];
24 float fFx, fDx;
25public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000026 InterpBench(const char name[]) {
reed@google.comb8c39172012-03-07 12:36:07 +000027 fName.printf("interp_%s", name);
robertphillips@google.com09042b82012-04-06 20:01:46 +000028 fFx = 3.3f;
29 fDx = 0.1257f;
commit-bot@chromium.org644629c2013-11-21 06:21:58 +000030 }
31
mtklein36352bf2015-03-25 18:17:31 -070032 bool isSuitableFor(Backend backend) override {
commit-bot@chromium.org644629c2013-11-21 06:21:58 +000033 return backend == kNonRendering_Backend;
reed@google.comb8c39172012-03-07 12:36:07 +000034 }
35
36 virtual void performTest(int16_t dst[], float x, float dx, int count) = 0;
37
38protected:
39 virtual int mulLoopCount() const { return 1; }
40
mtkleinf0599002015-07-13 06:18:39 -070041 const char* onGetName() override {
reed@google.comb8c39172012-03-07 12:36:07 +000042 return fName.c_str();
43 }
44
mtkleinf0599002015-07-13 06:18:39 -070045 void onDraw(const int loops, SkCanvas*) override {
commit-bot@chromium.org33614712013-12-03 18:17:16 +000046 int n = loops * this->mulLoopCount();
reed@google.comb8c39172012-03-07 12:36:07 +000047 for (int i = 0; i < n; i++) {
48 this->performTest(fDst, fFx, fDx, kBuffer);
49 }
50 }
51
52private:
tfarinaf168b862014-06-19 12:32:29 -070053 typedef Benchmark INHERITED;
reed@google.comb8c39172012-03-07 12:36:07 +000054};
55
56class Fixed16D16Interp : public InterpBench {
57public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000058 Fixed16D16Interp() : INHERITED("16.16") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +000059
reed@google.comb8c39172012-03-07 12:36:07 +000060protected:
mtklein36352bf2015-03-25 18:17:31 -070061 void performTest(int16_t dst[], float fx, float dx, int count) override {
reed@google.comb8c39172012-03-07 12:36:07 +000062 SkFixed curr = SkFloatToFixed(fx);
63 SkFixed step = SkFloatToFixed(dx);
64 for (int i = 0; i < count; i += 4) {
65 dst[i + 0] = TILE(curr, count); curr += step;
66 dst[i + 1] = TILE(curr, count); curr += step;
67 dst[i + 2] = TILE(curr, count); curr += step;
68 dst[i + 3] = TILE(curr, count); curr += step;
69 }
70 }
71private:
72 typedef InterpBench INHERITED;
73};
74
75class Fixed32D32Interp : public InterpBench {
76public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000077 Fixed32D32Interp() : INHERITED("32.32") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +000078
reed@google.comb8c39172012-03-07 12:36:07 +000079protected:
mtklein36352bf2015-03-25 18:17:31 -070080 void performTest(int16_t dst[], float fx, float dx, int count) override {
reed@google.comb8c39172012-03-07 12:36:07 +000081 int64_t curr = (int64_t)(fx * 65536 * 655536);
82 int64_t step = (int64_t)(dx * 65536 * 655536);
83 SkFixed tmp;
84 for (int i = 0; i < count; i += 4) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +000085 tmp = (SkFixed)(curr >> 16);
86 dst[i + 0] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +000087 curr += step;
88
rmistry@google.comfbfcd562012-08-23 18:09:54 +000089 tmp = (SkFixed)(curr >> 16);
90 dst[i + 1] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +000091 curr += step;
92
rmistry@google.comfbfcd562012-08-23 18:09:54 +000093 tmp = (SkFixed)(curr >> 16);
94 dst[i + 2] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +000095 curr += step;
96
rmistry@google.comfbfcd562012-08-23 18:09:54 +000097 tmp = (SkFixed)(curr >> 16);
98 dst[i + 3] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +000099 curr += step;
reed@google.comb8c39172012-03-07 12:36:07 +0000100 }
101 }
102private:
103 typedef InterpBench INHERITED;
104};
105
106class Fixed16D48Interp : public InterpBench {
107public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000108 Fixed16D48Interp() : INHERITED("16.48") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000109
reed@google.comb8c39172012-03-07 12:36:07 +0000110protected:
mtklein36352bf2015-03-25 18:17:31 -0700111 void performTest(int16_t dst[], float fx, float dx, int count) override {
reed@google.comb8c39172012-03-07 12:36:07 +0000112 int64_t curr = (int64_t)(fx * 65536 * 655536 * 65536);
113 int64_t step = (int64_t)(dx * 65536 * 655536 * 65536);
114 SkFixed tmp;
115 for (int i = 0; i < count; i += 4) {
caryclark@google.com19069a22012-06-06 12:11:45 +0000116 tmp = (SkFixed) (curr >> 32); dst[i + 0] = TILE(tmp, count); curr += step;
117 tmp = (SkFixed) (curr >> 32); dst[i + 1] = TILE(tmp, count); curr += step;
118 tmp = (SkFixed) (curr >> 32); dst[i + 2] = TILE(tmp, count); curr += step;
119 tmp = (SkFixed) (curr >> 32); dst[i + 3] = TILE(tmp, count); curr += step;
reed@google.comb8c39172012-03-07 12:36:07 +0000120 }
121 }
122private:
123 typedef InterpBench INHERITED;
124};
125
126class FloatInterp : public InterpBench {
127public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000128 FloatInterp() : INHERITED("float") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000129
reed@google.comb8c39172012-03-07 12:36:07 +0000130protected:
mtklein36352bf2015-03-25 18:17:31 -0700131 void performTest(int16_t dst[], float fx, float dx, int count) override {
reed@google.comb8c39172012-03-07 12:36:07 +0000132 SkFixed tmp;
133 for (int i = 0; i < count; i += 4) {
134 tmp = SkFloatToFixed(fx); dst[i + 0] = TILE(tmp, count); fx += dx;
135 tmp = SkFloatToFixed(fx); dst[i + 1] = TILE(tmp, count); fx += dx;
136 tmp = SkFloatToFixed(fx); dst[i + 2] = TILE(tmp, count); fx += dx;
137 tmp = SkFloatToFixed(fx); dst[i + 3] = TILE(tmp, count); fx += dx;
138 }
139 }
140private:
141 typedef InterpBench INHERITED;
142};
143
144class DoubleInterp : public InterpBench {
145public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000146 DoubleInterp() : INHERITED("double") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000147
reed@google.comb8c39172012-03-07 12:36:07 +0000148protected:
mtklein36352bf2015-03-25 18:17:31 -0700149 void performTest(int16_t dst[], float fx, float dx, int count) override {
reed@google.comb8c39172012-03-07 12:36:07 +0000150 double ffx = fx;
151 double ddx = dx;
152 SkFixed tmp;
153 for (int i = 0; i < count; i += 4) {
154 tmp = SkDoubleToFixed(ffx); dst[i + 0] = TILE(tmp, count); ffx += ddx;
155 tmp = SkDoubleToFixed(ffx); dst[i + 1] = TILE(tmp, count); ffx += ddx;
156 tmp = SkDoubleToFixed(ffx); dst[i + 2] = TILE(tmp, count); ffx += ddx;
157 tmp = SkDoubleToFixed(ffx); dst[i + 3] = TILE(tmp, count); ffx += ddx;
158 }
159 }
160private:
161 typedef InterpBench INHERITED;
162};
163
164///////////////////////////////////////////////////////////////////////////////
165
mtklein@google.com410e6e82013-09-13 19:52:27 +0000166DEF_BENCH( return new Fixed16D16Interp(); )
167DEF_BENCH( return new Fixed32D32Interp(); )
168DEF_BENCH( return new Fixed16D48Interp(); )
169DEF_BENCH( return new FloatInterp(); )
170DEF_BENCH( return new DoubleInterp(); )