blob: 16cc4991663b2dde04df2f1d962ce82b1ecbe2c6 [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"
Cary Clarka4083c92017-09-15 11:59:23 -04009#include "SkColorData.h"
benjaminwagner6c71e0a2016-04-07 08:49:31 -070010#include "SkFixed.h"
reed@google.comb8c39172012-03-07 12:36:07 +000011#include "SkMatrix.h"
tfarinaf168b862014-06-19 12:32:29 -070012#include "SkPaint.h"
reed@google.comb8c39172012-03-07 12:36:07 +000013#include "SkRandom.h"
14#include "SkString.h"
reed@google.comb8c39172012-03-07 12:36:07 +000015
16#define TILE(x, width) (((x) & 0xFFFF) * width >> 16)
17
tfarinaf168b862014-06-19 12:32:29 -070018class InterpBench : public Benchmark {
reed@google.comb8c39172012-03-07 12:36:07 +000019 enum {
20 kBuffer = 128,
21 kLoop = 20000
22 };
23 SkString fName;
24 int16_t fDst[kBuffer];
25 float fFx, fDx;
26public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000027 InterpBench(const char name[]) {
reed@google.comb8c39172012-03-07 12:36:07 +000028 fName.printf("interp_%s", name);
robertphillips@google.com09042b82012-04-06 20:01:46 +000029 fFx = 3.3f;
30 fDx = 0.1257f;
commit-bot@chromium.org644629c2013-11-21 06:21:58 +000031 }
32
mtklein36352bf2015-03-25 18:17:31 -070033 bool isSuitableFor(Backend backend) override {
commit-bot@chromium.org644629c2013-11-21 06:21:58 +000034 return backend == kNonRendering_Backend;
reed@google.comb8c39172012-03-07 12:36:07 +000035 }
36
37 virtual void performTest(int16_t dst[], float x, float dx, int count) = 0;
38
39protected:
40 virtual int mulLoopCount() const { return 1; }
41
mtkleinf0599002015-07-13 06:18:39 -070042 const char* onGetName() override {
reed@google.comb8c39172012-03-07 12:36:07 +000043 return fName.c_str();
44 }
45
mtkleina1ebeb22015-10-01 09:43:39 -070046 void onDraw(int loops, SkCanvas*) override {
commit-bot@chromium.org33614712013-12-03 18:17:16 +000047 int n = loops * this->mulLoopCount();
reed@google.comb8c39172012-03-07 12:36:07 +000048 for (int i = 0; i < n; i++) {
49 this->performTest(fDst, fFx, fDx, kBuffer);
50 }
51 }
52
53private:
tfarinaf168b862014-06-19 12:32:29 -070054 typedef Benchmark INHERITED;
reed@google.comb8c39172012-03-07 12:36:07 +000055};
56
57class Fixed16D16Interp : public InterpBench {
58public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000059 Fixed16D16Interp() : INHERITED("16.16") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +000060
reed@google.comb8c39172012-03-07 12:36:07 +000061protected:
mtklein36352bf2015-03-25 18:17:31 -070062 void performTest(int16_t dst[], float fx, float dx, int count) override {
reed@google.comb8c39172012-03-07 12:36:07 +000063 SkFixed curr = SkFloatToFixed(fx);
64 SkFixed step = SkFloatToFixed(dx);
65 for (int i = 0; i < count; i += 4) {
66 dst[i + 0] = TILE(curr, count); curr += step;
67 dst[i + 1] = TILE(curr, count); curr += step;
68 dst[i + 2] = TILE(curr, count); curr += step;
69 dst[i + 3] = TILE(curr, count); curr += step;
70 }
71 }
72private:
73 typedef InterpBench INHERITED;
74};
75
76class Fixed32D32Interp : public InterpBench {
77public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000078 Fixed32D32Interp() : INHERITED("32.32") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +000079
reed@google.comb8c39172012-03-07 12:36:07 +000080protected:
mtklein36352bf2015-03-25 18:17:31 -070081 void performTest(int16_t dst[], float fx, float dx, int count) override {
reed@google.comb8c39172012-03-07 12:36:07 +000082 int64_t curr = (int64_t)(fx * 65536 * 655536);
83 int64_t step = (int64_t)(dx * 65536 * 655536);
84 SkFixed tmp;
85 for (int i = 0; i < count; i += 4) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +000086 tmp = (SkFixed)(curr >> 16);
87 dst[i + 0] = 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 + 1] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +000092 curr += step;
93
rmistry@google.comfbfcd562012-08-23 18:09:54 +000094 tmp = (SkFixed)(curr >> 16);
95 dst[i + 2] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +000096 curr += step;
97
rmistry@google.comfbfcd562012-08-23 18:09:54 +000098 tmp = (SkFixed)(curr >> 16);
99 dst[i + 3] = TILE(tmp, count);
robertphillips@google.com4debcac2012-05-14 16:33:36 +0000100 curr += step;
reed@google.comb8c39172012-03-07 12:36:07 +0000101 }
102 }
103private:
104 typedef InterpBench INHERITED;
105};
106
107class Fixed16D48Interp : public InterpBench {
108public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000109 Fixed16D48Interp() : INHERITED("16.48") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000110
reed@google.comb8c39172012-03-07 12:36:07 +0000111protected:
mtklein36352bf2015-03-25 18:17:31 -0700112 void performTest(int16_t dst[], float fx, float dx, int count) override {
reed@google.comb8c39172012-03-07 12:36:07 +0000113 int64_t curr = (int64_t)(fx * 65536 * 655536 * 65536);
114 int64_t step = (int64_t)(dx * 65536 * 655536 * 65536);
115 SkFixed tmp;
116 for (int i = 0; i < count; i += 4) {
caryclark@google.com19069a22012-06-06 12:11:45 +0000117 tmp = (SkFixed) (curr >> 32); dst[i + 0] = TILE(tmp, count); curr += step;
118 tmp = (SkFixed) (curr >> 32); dst[i + 1] = TILE(tmp, count); curr += step;
119 tmp = (SkFixed) (curr >> 32); dst[i + 2] = TILE(tmp, count); curr += step;
120 tmp = (SkFixed) (curr >> 32); dst[i + 3] = TILE(tmp, count); curr += step;
reed@google.comb8c39172012-03-07 12:36:07 +0000121 }
122 }
123private:
124 typedef InterpBench INHERITED;
125};
126
127class FloatInterp : public InterpBench {
128public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000129 FloatInterp() : INHERITED("float") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000130
reed@google.comb8c39172012-03-07 12:36:07 +0000131protected:
mtklein36352bf2015-03-25 18:17:31 -0700132 void performTest(int16_t dst[], float fx, float dx, int count) override {
reed@google.comb8c39172012-03-07 12:36:07 +0000133 SkFixed tmp;
134 for (int i = 0; i < count; i += 4) {
135 tmp = SkFloatToFixed(fx); dst[i + 0] = TILE(tmp, count); fx += dx;
136 tmp = SkFloatToFixed(fx); dst[i + 1] = TILE(tmp, count); fx += dx;
137 tmp = SkFloatToFixed(fx); dst[i + 2] = TILE(tmp, count); fx += dx;
138 tmp = SkFloatToFixed(fx); dst[i + 3] = TILE(tmp, count); fx += dx;
139 }
140 }
141private:
142 typedef InterpBench INHERITED;
143};
144
145class DoubleInterp : public InterpBench {
146public:
mtklein@google.com410e6e82013-09-13 19:52:27 +0000147 DoubleInterp() : INHERITED("double") {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000148
reed@google.comb8c39172012-03-07 12:36:07 +0000149protected:
mtklein36352bf2015-03-25 18:17:31 -0700150 void performTest(int16_t dst[], float fx, float dx, int count) override {
reed@google.comb8c39172012-03-07 12:36:07 +0000151 double ffx = fx;
152 double ddx = dx;
153 SkFixed tmp;
154 for (int i = 0; i < count; i += 4) {
155 tmp = SkDoubleToFixed(ffx); dst[i + 0] = TILE(tmp, count); ffx += ddx;
156 tmp = SkDoubleToFixed(ffx); dst[i + 1] = TILE(tmp, count); ffx += ddx;
157 tmp = SkDoubleToFixed(ffx); dst[i + 2] = TILE(tmp, count); ffx += ddx;
158 tmp = SkDoubleToFixed(ffx); dst[i + 3] = TILE(tmp, count); ffx += ddx;
159 }
160 }
161private:
162 typedef InterpBench INHERITED;
163};
164
165///////////////////////////////////////////////////////////////////////////////
166
mtklein@google.com410e6e82013-09-13 19:52:27 +0000167DEF_BENCH( return new Fixed16D16Interp(); )
168DEF_BENCH( return new Fixed32D32Interp(); )
169DEF_BENCH( return new Fixed16D48Interp(); )
170DEF_BENCH( return new FloatInterp(); )
171DEF_BENCH( return new DoubleInterp(); )