epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 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@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 8 | #include "SkBenchmark.h" |
| 9 | #include "SkMatrix.h" |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 10 | #include "SkMatrixUtils.h" |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 11 | #include "SkRandom.h" |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 12 | #include "SkString.h" |
| 13 | |
| 14 | class MatrixBench : public SkBenchmark { |
| 15 | SkString fName; |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 16 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 17 | MatrixBench(const char name[]) { |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 18 | fName.printf("matrix_%s", name); |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 22 | return backend == kNonRendering_Backend; |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | virtual void performTest() = 0; |
| 26 | |
| 27 | protected: |
reed@google.com | cbefd7d | 2011-06-06 13:31:30 +0000 | [diff] [blame] | 28 | virtual int mulLoopCount() const { return 1; } |
| 29 | |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 30 | virtual const char* onGetName() { |
| 31 | return fName.c_str(); |
| 32 | } |
| 33 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 34 | virtual void onDraw(const int loops, SkCanvas*) { |
| 35 | for (int i = 0; i < loops; i++) { |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 36 | this->performTest(); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | private: |
| 41 | typedef SkBenchmark INHERITED; |
| 42 | }; |
| 43 | |
| 44 | // we want to stop the compiler from eliminating code that it thinks is a no-op |
| 45 | // so we have a non-static global we increment, hoping that will convince the |
| 46 | // compiler to execute everything |
| 47 | int gMatrixBench_NonStaticGlobal; |
| 48 | |
| 49 | #define always_do(pred) \ |
| 50 | do { \ |
| 51 | if (pred) { \ |
| 52 | ++gMatrixBench_NonStaticGlobal; \ |
| 53 | } \ |
| 54 | } while (0) |
| 55 | |
| 56 | class EqualsMatrixBench : public MatrixBench { |
| 57 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 58 | EqualsMatrixBench() : INHERITED("equals") {} |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 59 | protected: |
| 60 | virtual void performTest() { |
| 61 | SkMatrix m0, m1, m2; |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 62 | |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 63 | m0.reset(); |
| 64 | m1.reset(); |
| 65 | m2.reset(); |
| 66 | always_do(m0 == m1); |
| 67 | always_do(m1 == m2); |
| 68 | always_do(m2 == m0); |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 69 | } |
| 70 | private: |
| 71 | typedef MatrixBench INHERITED; |
| 72 | }; |
| 73 | |
| 74 | class ScaleMatrixBench : public MatrixBench { |
| 75 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 76 | ScaleMatrixBench() : INHERITED("scale") { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 77 | fSX = fSY = 1.5f; |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 78 | fM0.reset(); |
| 79 | fM1.setScale(fSX, fSY); |
| 80 | fM2.setTranslate(fSX, fSY); |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 81 | } |
| 82 | protected: |
| 83 | virtual void performTest() { |
| 84 | SkMatrix m; |
| 85 | m = fM0; m.preScale(fSX, fSY); |
| 86 | m = fM1; m.preScale(fSX, fSY); |
| 87 | m = fM2; m.preScale(fSX, fSY); |
| 88 | } |
| 89 | private: |
| 90 | SkMatrix fM0, fM1, fM2; |
| 91 | SkScalar fSX, fSY; |
| 92 | typedef MatrixBench INHERITED; |
| 93 | }; |
| 94 | |
reed@google.com | e0dcde7 | 2011-06-06 13:20:29 +0000 | [diff] [blame] | 95 | // having unknown values in our arrays can throw off the timing a lot, perhaps |
| 96 | // handling NaN values is a lot slower. Anyway, this guy is just meant to put |
| 97 | // reasonable values in our arrays. |
| 98 | template <typename T> void init9(T array[9]) { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 99 | SkRandom rand; |
reed@google.com | e0dcde7 | 2011-06-06 13:20:29 +0000 | [diff] [blame] | 100 | for (int i = 0; i < 9; i++) { |
| 101 | array[i] = rand.nextSScalar1(); |
| 102 | } |
| 103 | } |
| 104 | |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 105 | // Test the performance of setConcat() non-perspective case: |
| 106 | // using floating point precision only. |
| 107 | class FloatConcatMatrixBench : public MatrixBench { |
| 108 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 109 | FloatConcatMatrixBench() : INHERITED("concat_floatfloat") { |
reed@google.com | e0dcde7 | 2011-06-06 13:20:29 +0000 | [diff] [blame] | 110 | init9(mya); |
| 111 | init9(myb); |
| 112 | init9(myr); |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 113 | } |
| 114 | protected: |
reed@google.com | cbefd7d | 2011-06-06 13:31:30 +0000 | [diff] [blame] | 115 | virtual int mulLoopCount() const { return 4; } |
| 116 | |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 117 | static inline void muladdmul(float a, float b, float c, float d, |
| 118 | float* result) { |
| 119 | *result = a * b + c * d; |
| 120 | } |
| 121 | virtual void performTest() { |
tomhudson@google.com | a20416b | 2011-06-03 20:32:58 +0000 | [diff] [blame] | 122 | const float* a = mya; |
| 123 | const float* b = myb; |
| 124 | float* r = myr; |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 125 | muladdmul(a[0], b[0], a[1], b[3], &r[0]); |
| 126 | muladdmul(a[0], b[1], a[1], b[4], &r[1]); |
| 127 | muladdmul(a[0], b[2], a[1], b[5], &r[2]); |
tomhudson@google.com | a20416b | 2011-06-03 20:32:58 +0000 | [diff] [blame] | 128 | r[2] += a[2]; |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 129 | muladdmul(a[3], b[0], a[4], b[3], &r[3]); |
| 130 | muladdmul(a[3], b[1], a[4], b[4], &r[4]); |
| 131 | muladdmul(a[3], b[2], a[4], b[5], &r[5]); |
tomhudson@google.com | a20416b | 2011-06-03 20:32:58 +0000 | [diff] [blame] | 132 | r[5] += a[5]; |
| 133 | r[6] = r[7] = 0.0f; |
| 134 | r[8] = 1.0f; |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 135 | } |
| 136 | private: |
tomhudson@google.com | a20416b | 2011-06-03 20:32:58 +0000 | [diff] [blame] | 137 | float mya [9]; |
| 138 | float myb [9]; |
| 139 | float myr [9]; |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 140 | typedef MatrixBench INHERITED; |
| 141 | }; |
| 142 | |
| 143 | static inline float SkDoubleToFloat(double x) { |
| 144 | return static_cast<float>(x); |
| 145 | } |
| 146 | |
| 147 | // Test the performance of setConcat() non-perspective case: |
| 148 | // using floating point precision but casting up to float for |
| 149 | // intermediate results during computations. |
| 150 | class FloatDoubleConcatMatrixBench : public MatrixBench { |
| 151 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 152 | FloatDoubleConcatMatrixBench() : INHERITED("concat_floatdouble") { |
reed@google.com | e0dcde7 | 2011-06-06 13:20:29 +0000 | [diff] [blame] | 153 | init9(mya); |
| 154 | init9(myb); |
| 155 | init9(myr); |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 156 | } |
| 157 | protected: |
reed@google.com | cbefd7d | 2011-06-06 13:31:30 +0000 | [diff] [blame] | 158 | virtual int mulLoopCount() const { return 4; } |
| 159 | |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 160 | static inline void muladdmul(float a, float b, float c, float d, |
| 161 | float* result) { |
| 162 | *result = SkDoubleToFloat((double)a * b + (double)c * d); |
| 163 | } |
| 164 | virtual void performTest() { |
tomhudson@google.com | a20416b | 2011-06-03 20:32:58 +0000 | [diff] [blame] | 165 | const float* a = mya; |
| 166 | const float* b = myb; |
| 167 | float* r = myr; |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 168 | muladdmul(a[0], b[0], a[1], b[3], &r[0]); |
| 169 | muladdmul(a[0], b[1], a[1], b[4], &r[1]); |
| 170 | muladdmul(a[0], b[2], a[1], b[5], &r[2]); |
tomhudson@google.com | a20416b | 2011-06-03 20:32:58 +0000 | [diff] [blame] | 171 | r[2] += a[2]; |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 172 | muladdmul(a[3], b[0], a[4], b[3], &r[3]); |
| 173 | muladdmul(a[3], b[1], a[4], b[4], &r[4]); |
| 174 | muladdmul(a[3], b[2], a[4], b[5], &r[5]); |
tomhudson@google.com | a20416b | 2011-06-03 20:32:58 +0000 | [diff] [blame] | 175 | r[5] += a[5]; |
| 176 | r[6] = r[7] = 0.0f; |
| 177 | r[8] = 1.0f; |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 178 | } |
| 179 | private: |
tomhudson@google.com | a20416b | 2011-06-03 20:32:58 +0000 | [diff] [blame] | 180 | float mya [9]; |
| 181 | float myb [9]; |
| 182 | float myr [9]; |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 183 | typedef MatrixBench INHERITED; |
| 184 | }; |
| 185 | |
| 186 | // Test the performance of setConcat() non-perspective case: |
| 187 | // using double precision only. |
| 188 | class DoubleConcatMatrixBench : public MatrixBench { |
| 189 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 190 | DoubleConcatMatrixBench() : INHERITED("concat_double") { |
reed@google.com | e0dcde7 | 2011-06-06 13:20:29 +0000 | [diff] [blame] | 191 | init9(mya); |
| 192 | init9(myb); |
| 193 | init9(myr); |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 194 | } |
| 195 | protected: |
reed@google.com | cbefd7d | 2011-06-06 13:31:30 +0000 | [diff] [blame] | 196 | virtual int mulLoopCount() const { return 4; } |
| 197 | |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 198 | static inline void muladdmul(double a, double b, double c, double d, |
| 199 | double* result) { |
| 200 | *result = a * b + c * d; |
| 201 | } |
| 202 | virtual void performTest() { |
tomhudson@google.com | a20416b | 2011-06-03 20:32:58 +0000 | [diff] [blame] | 203 | const double* a = mya; |
| 204 | const double* b = myb; |
| 205 | double* r = myr; |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 206 | muladdmul(a[0], b[0], a[1], b[3], &r[0]); |
| 207 | muladdmul(a[0], b[1], a[1], b[4], &r[1]); |
| 208 | muladdmul(a[0], b[2], a[1], b[5], &r[2]); |
tomhudson@google.com | a20416b | 2011-06-03 20:32:58 +0000 | [diff] [blame] | 209 | r[2] += a[2]; |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 210 | muladdmul(a[3], b[0], a[4], b[3], &r[3]); |
| 211 | muladdmul(a[3], b[1], a[4], b[4], &r[4]); |
| 212 | muladdmul(a[3], b[2], a[4], b[5], &r[5]); |
tomhudson@google.com | a20416b | 2011-06-03 20:32:58 +0000 | [diff] [blame] | 213 | r[5] += a[5]; |
| 214 | r[6] = r[7] = 0.0; |
| 215 | r[8] = 1.0; |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 216 | } |
| 217 | private: |
tomhudson@google.com | a20416b | 2011-06-03 20:32:58 +0000 | [diff] [blame] | 218 | double mya [9]; |
| 219 | double myb [9]; |
| 220 | double myr [9]; |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 221 | typedef MatrixBench INHERITED; |
| 222 | }; |
| 223 | |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 224 | class GetTypeMatrixBench : public MatrixBench { |
| 225 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 226 | GetTypeMatrixBench() |
| 227 | : INHERITED("gettype") { |
bsalomon@google.com | 820e80a | 2011-10-24 21:09:40 +0000 | [diff] [blame] | 228 | fArray[0] = (float) fRnd.nextS(); |
| 229 | fArray[1] = (float) fRnd.nextS(); |
| 230 | fArray[2] = (float) fRnd.nextS(); |
| 231 | fArray[3] = (float) fRnd.nextS(); |
| 232 | fArray[4] = (float) fRnd.nextS(); |
| 233 | fArray[5] = (float) fRnd.nextS(); |
| 234 | fArray[6] = (float) fRnd.nextS(); |
| 235 | fArray[7] = (float) fRnd.nextS(); |
| 236 | fArray[8] = (float) fRnd.nextS(); |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 237 | } |
| 238 | protected: |
| 239 | // Putting random generation of the matrix inside performTest() |
| 240 | // would help us avoid anomalous runs, but takes up 25% or |
| 241 | // more of the function time. |
| 242 | virtual void performTest() { |
| 243 | fMatrix.setAll(fArray[0], fArray[1], fArray[2], |
| 244 | fArray[3], fArray[4], fArray[5], |
| 245 | fArray[6], fArray[7], fArray[8]); |
| 246 | always_do(fMatrix.getType()); |
| 247 | fMatrix.dirtyMatrixTypeCache(); |
| 248 | always_do(fMatrix.getType()); |
| 249 | fMatrix.dirtyMatrixTypeCache(); |
| 250 | always_do(fMatrix.getType()); |
| 251 | fMatrix.dirtyMatrixTypeCache(); |
| 252 | always_do(fMatrix.getType()); |
| 253 | fMatrix.dirtyMatrixTypeCache(); |
| 254 | always_do(fMatrix.getType()); |
| 255 | fMatrix.dirtyMatrixTypeCache(); |
| 256 | always_do(fMatrix.getType()); |
| 257 | fMatrix.dirtyMatrixTypeCache(); |
| 258 | always_do(fMatrix.getType()); |
| 259 | fMatrix.dirtyMatrixTypeCache(); |
| 260 | always_do(fMatrix.getType()); |
| 261 | } |
| 262 | private: |
| 263 | SkMatrix fMatrix; |
| 264 | float fArray[9]; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 265 | SkRandom fRnd; |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 266 | typedef MatrixBench INHERITED; |
| 267 | }; |
| 268 | |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 269 | class ScaleTransMixedMatrixBench : public MatrixBench { |
| 270 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 271 | ScaleTransMixedMatrixBench() : INHERITED("scaletrans_mixed") { |
bsalomon@google.com | 3d3dfe0 | 2011-11-10 13:50:19 +0000 | [diff] [blame] | 272 | fMatrix.setAll(fRandom.nextSScalar1(), fRandom.nextSScalar1(), fRandom.nextSScalar1(), |
| 273 | fRandom.nextSScalar1(), fRandom.nextSScalar1(), fRandom.nextSScalar1(), |
| 274 | fRandom.nextSScalar1(), fRandom.nextSScalar1(), fRandom.nextSScalar1()); |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 275 | int i; |
tfarina@chromium.org | 7731ead | 2013-04-05 21:13:14 +0000 | [diff] [blame] | 276 | for (i = 0; i < kCount; i++) { |
bsalomon@google.com | 820e80a | 2011-10-24 21:09:40 +0000 | [diff] [blame] | 277 | fSrc[i].fX = fRandom.nextSScalar1(); |
| 278 | fSrc[i].fY = fRandom.nextSScalar1(); |
| 279 | fDst[i].fX = fRandom.nextSScalar1(); |
| 280 | fDst[i].fY = fRandom.nextSScalar1(); |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | protected: |
| 284 | virtual void performTest() { |
| 285 | SkPoint* dst = fDst; |
| 286 | const SkPoint* src = fSrc; |
tfarina@chromium.org | 7731ead | 2013-04-05 21:13:14 +0000 | [diff] [blame] | 287 | int count = kCount; |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 288 | float mx = fMatrix[SkMatrix::kMScaleX]; |
| 289 | float my = fMatrix[SkMatrix::kMScaleY]; |
| 290 | float tx = fMatrix[SkMatrix::kMTransX]; |
| 291 | float ty = fMatrix[SkMatrix::kMTransY]; |
| 292 | do { |
| 293 | dst->fY = SkScalarMulAdd(src->fY, my, ty); |
| 294 | dst->fX = SkScalarMulAdd(src->fX, mx, tx); |
| 295 | src += 1; |
| 296 | dst += 1; |
| 297 | } while (--count); |
| 298 | } |
| 299 | private: |
tfarina@chromium.org | 7731ead | 2013-04-05 21:13:14 +0000 | [diff] [blame] | 300 | enum { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 301 | kCount = 16 |
tfarina@chromium.org | 7731ead | 2013-04-05 21:13:14 +0000 | [diff] [blame] | 302 | }; |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 303 | SkMatrix fMatrix; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 304 | SkPoint fSrc [kCount]; |
| 305 | SkPoint fDst [kCount]; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 306 | SkRandom fRandom; |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 307 | typedef MatrixBench INHERITED; |
| 308 | }; |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 309 | |
| 310 | class ScaleTransDoubleMatrixBench : public MatrixBench { |
| 311 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 312 | ScaleTransDoubleMatrixBench() : INHERITED("scaletrans_double") { |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 313 | init9(fMatrix); |
| 314 | int i; |
tfarina@chromium.org | 7731ead | 2013-04-05 21:13:14 +0000 | [diff] [blame] | 315 | for (i = 0; i < kCount; i++) { |
bsalomon@google.com | 820e80a | 2011-10-24 21:09:40 +0000 | [diff] [blame] | 316 | fSrc[i].fX = fRandom.nextSScalar1(); |
| 317 | fSrc[i].fY = fRandom.nextSScalar1(); |
| 318 | fDst[i].fX = fRandom.nextSScalar1(); |
| 319 | fDst[i].fY = fRandom.nextSScalar1(); |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | protected: |
| 323 | virtual void performTest() { |
| 324 | SkPoint* dst = fDst; |
| 325 | const SkPoint* src = fSrc; |
tfarina@chromium.org | 7731ead | 2013-04-05 21:13:14 +0000 | [diff] [blame] | 326 | int count = kCount; |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 327 | // As doubles, on Z600 Linux systems this is 2.5x as expensive as mixed mode |
bsalomon@google.com | 820e80a | 2011-10-24 21:09:40 +0000 | [diff] [blame] | 328 | float mx = (float) fMatrix[SkMatrix::kMScaleX]; |
| 329 | float my = (float) fMatrix[SkMatrix::kMScaleY]; |
| 330 | float tx = (float) fMatrix[SkMatrix::kMTransX]; |
| 331 | float ty = (float) fMatrix[SkMatrix::kMTransY]; |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 332 | do { |
| 333 | dst->fY = src->fY * my + ty; |
| 334 | dst->fX = src->fX * mx + tx; |
| 335 | src += 1; |
| 336 | dst += 1; |
| 337 | } while (--count); |
| 338 | } |
| 339 | private: |
tfarina@chromium.org | 7731ead | 2013-04-05 21:13:14 +0000 | [diff] [blame] | 340 | enum { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 341 | kCount = 16 |
tfarina@chromium.org | 7731ead | 2013-04-05 21:13:14 +0000 | [diff] [blame] | 342 | }; |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 343 | double fMatrix [9]; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 344 | SkPoint fSrc [kCount]; |
| 345 | SkPoint fDst [kCount]; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 346 | SkRandom fRandom; |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 347 | typedef MatrixBench INHERITED; |
| 348 | }; |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 349 | |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 350 | class DecomposeMatrixBench : public MatrixBench { |
| 351 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 352 | DecomposeMatrixBench() : INHERITED("decompose") {} |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 353 | |
| 354 | protected: |
| 355 | virtual void onPreDraw() { |
| 356 | for (int i = 0; i < 10; ++i) { |
| 357 | SkScalar rot0 = (fRandom.nextBool()) ? fRandom.nextRangeF(-180, 180) : 0.0f; |
| 358 | SkScalar sx = fRandom.nextRangeF(-3000.f, 3000.f); |
| 359 | SkScalar sy = (fRandom.nextBool()) ? fRandom.nextRangeF(-3000.f, 3000.f) : sx; |
| 360 | SkScalar rot1 = fRandom.nextRangeF(-180, 180); |
| 361 | fMatrix[i].setRotate(rot0); |
| 362 | fMatrix[i].postScale(sx, sy); |
| 363 | fMatrix[i].postRotate(rot1); |
| 364 | } |
| 365 | } |
| 366 | virtual void performTest() { |
| 367 | SkPoint rotation1, scale, rotation2; |
| 368 | for (int i = 0; i < 10; ++i) { |
| 369 | (void) SkDecomposeUpper2x2(fMatrix[i], &rotation1, &scale, &rotation2); |
| 370 | } |
| 371 | } |
| 372 | private: |
| 373 | SkMatrix fMatrix[10]; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 374 | SkRandom fRandom; |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 375 | typedef MatrixBench INHERITED; |
| 376 | }; |
| 377 | |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 378 | class InvertMapRectMatrixBench : public MatrixBench { |
| 379 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 380 | InvertMapRectMatrixBench(const char* name, int flags) |
| 381 | : INHERITED(name) |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 382 | , fFlags(flags) { |
| 383 | fMatrix.reset(); |
| 384 | fIteration = 0; |
| 385 | if (flags & kScale_Flag) { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 386 | fMatrix.postScale(1.5f, 2.5f); |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 387 | } |
| 388 | if (flags & kTranslate_Flag) { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 389 | fMatrix.postTranslate(1.5f, 2.5f); |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 390 | } |
| 391 | if (flags & kRotate_Flag) { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 392 | fMatrix.postRotate(45.0f); |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 393 | } |
| 394 | if (flags & kPerspective_Flag) { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 395 | fMatrix.setPerspX(1.5f); |
| 396 | fMatrix.setPerspY(2.5f); |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 397 | } |
| 398 | if (0 == (flags & kUncachedTypeMask_Flag)) { |
| 399 | fMatrix.getType(); |
| 400 | } |
| 401 | } |
| 402 | enum Flag { |
| 403 | kScale_Flag = 0x01, |
| 404 | kTranslate_Flag = 0x02, |
| 405 | kRotate_Flag = 0x04, |
| 406 | kPerspective_Flag = 0x08, |
| 407 | kUncachedTypeMask_Flag = 0x10, |
| 408 | }; |
| 409 | protected: |
| 410 | virtual void performTest() { |
| 411 | if (fFlags & kUncachedTypeMask_Flag) { |
| 412 | // This will invalidate the typemask without |
| 413 | // changing the matrix. |
| 414 | fMatrix.setPerspX(fMatrix.getPerspX()); |
| 415 | } |
| 416 | SkMatrix inv; |
robertphillips@google.com | 31f8f73 | 2012-09-17 13:36:47 +0000 | [diff] [blame] | 417 | bool invertible = fMatrix.invert(&inv); |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 418 | SkASSERT(invertible); |
| 419 | SkRect transformedRect; |
robertphillips@google.com | 31f8f73 | 2012-09-17 13:36:47 +0000 | [diff] [blame] | 420 | // an arbitrary, small, non-zero rect to transform |
| 421 | SkRect srcRect = SkRect::MakeWH(SkIntToScalar(10), SkIntToScalar(10)); |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 422 | if (invertible) { |
robertphillips@google.com | 31f8f73 | 2012-09-17 13:36:47 +0000 | [diff] [blame] | 423 | inv.mapRect(&transformedRect, srcRect); |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | private: |
| 427 | SkMatrix fMatrix; |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 428 | int fFlags; |
| 429 | unsigned fIteration; |
| 430 | typedef MatrixBench INHERITED; |
| 431 | }; |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 432 | |
reed@google.com | 82bf8bb | 2013-01-04 14:04:08 +0000 | [diff] [blame] | 433 | /////////////////////////////////////////////////////////////////////////////// |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 434 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 435 | DEF_BENCH( return new EqualsMatrixBench(); ) |
| 436 | DEF_BENCH( return new ScaleMatrixBench(); ) |
| 437 | DEF_BENCH( return new FloatConcatMatrixBench(); ) |
| 438 | DEF_BENCH( return new FloatDoubleConcatMatrixBench(); ) |
| 439 | DEF_BENCH( return new DoubleConcatMatrixBench(); ) |
| 440 | DEF_BENCH( return new GetTypeMatrixBench(); ) |
| 441 | DEF_BENCH( return new DecomposeMatrixBench(); ) |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 442 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 443 | DEF_BENCH( return new InvertMapRectMatrixBench("invert_maprect_identity", 0); ) |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 444 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 445 | DEF_BENCH(return new InvertMapRectMatrixBench( |
reed@google.com | 90533be | 2013-01-04 15:46:42 +0000 | [diff] [blame] | 446 | "invert_maprect_rectstaysrect", |
| 447 | InvertMapRectMatrixBench::kScale_Flag | |
| 448 | InvertMapRectMatrixBench::kTranslate_Flag); ) |
| 449 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 450 | DEF_BENCH(return new InvertMapRectMatrixBench( |
reed@google.com | 90533be | 2013-01-04 15:46:42 +0000 | [diff] [blame] | 451 | "invert_maprect_translate", |
| 452 | InvertMapRectMatrixBench::kTranslate_Flag); ) |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 453 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 454 | DEF_BENCH(return new InvertMapRectMatrixBench( |
reed@google.com | 82bf8bb | 2013-01-04 14:04:08 +0000 | [diff] [blame] | 455 | "invert_maprect_nonpersp", |
| 456 | InvertMapRectMatrixBench::kScale_Flag | |
| 457 | InvertMapRectMatrixBench::kRotate_Flag | |
| 458 | InvertMapRectMatrixBench::kTranslate_Flag); ) |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 459 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 460 | DEF_BENCH( return new InvertMapRectMatrixBench( |
reed@google.com | 82bf8bb | 2013-01-04 14:04:08 +0000 | [diff] [blame] | 461 | "invert_maprect_persp", |
| 462 | InvertMapRectMatrixBench::kPerspective_Flag); ) |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 463 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 464 | DEF_BENCH( return new InvertMapRectMatrixBench( |
reed@google.com | 82bf8bb | 2013-01-04 14:04:08 +0000 | [diff] [blame] | 465 | "invert_maprect_typemask_rectstaysrect", |
| 466 | InvertMapRectMatrixBench::kUncachedTypeMask_Flag | |
| 467 | InvertMapRectMatrixBench::kScale_Flag | |
| 468 | InvertMapRectMatrixBench::kTranslate_Flag); ) |
| 469 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 470 | DEF_BENCH( return new InvertMapRectMatrixBench( |
reed@google.com | 82bf8bb | 2013-01-04 14:04:08 +0000 | [diff] [blame] | 471 | "invert_maprect_typemask_nonpersp", |
| 472 | InvertMapRectMatrixBench::kUncachedTypeMask_Flag | |
| 473 | InvertMapRectMatrixBench::kScale_Flag | |
| 474 | InvertMapRectMatrixBench::kRotate_Flag | |
| 475 | InvertMapRectMatrixBench::kTranslate_Flag); ) |
| 476 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 477 | DEF_BENCH( return new ScaleTransMixedMatrixBench(); ) |
| 478 | DEF_BENCH( return new ScaleTransDoubleMatrixBench(); ) |