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 | */ |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "Benchmark.h" |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 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 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 14 | class MatrixBench : public Benchmark { |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 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 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 21 | bool isSuitableFor(Backend backend) override { |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 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 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 30 | const char* onGetName() override { |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 31 | return fName.c_str(); |
| 32 | } |
| 33 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 34 | void onDraw(const int loops, SkCanvas*) override { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 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: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 41 | typedef Benchmark INHERITED; |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 44 | |
| 45 | class EqualsMatrixBench : public MatrixBench { |
| 46 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 47 | EqualsMatrixBench() : INHERITED("equals") {} |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 48 | protected: |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 49 | void performTest() override { |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 50 | SkMatrix m0, m1, m2; |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 51 | |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 52 | m0.reset(); |
| 53 | m1.reset(); |
| 54 | m2.reset(); |
mtklein | cf44feb | 2014-06-02 18:22:12 -0700 | [diff] [blame] | 55 | |
| 56 | // xor into a volatile prevents these comparisons from being optimized away. |
| 57 | volatile bool junk = false; |
| 58 | junk ^= (m0 == m1); |
| 59 | junk ^= (m1 == m2); |
| 60 | junk ^= (m2 == m0); |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 61 | } |
| 62 | private: |
| 63 | typedef MatrixBench INHERITED; |
| 64 | }; |
| 65 | |
| 66 | class ScaleMatrixBench : public MatrixBench { |
| 67 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 68 | ScaleMatrixBench() : INHERITED("scale") { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 69 | fSX = fSY = 1.5f; |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 70 | fM0.reset(); |
| 71 | fM1.setScale(fSX, fSY); |
| 72 | fM2.setTranslate(fSX, fSY); |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 73 | } |
| 74 | protected: |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 75 | void performTest() override { |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 76 | SkMatrix m; |
| 77 | m = fM0; m.preScale(fSX, fSY); |
| 78 | m = fM1; m.preScale(fSX, fSY); |
| 79 | m = fM2; m.preScale(fSX, fSY); |
| 80 | } |
| 81 | private: |
| 82 | SkMatrix fM0, fM1, fM2; |
| 83 | SkScalar fSX, fSY; |
| 84 | typedef MatrixBench INHERITED; |
| 85 | }; |
| 86 | |
reed@google.com | e0dcde7 | 2011-06-06 13:20:29 +0000 | [diff] [blame] | 87 | // having unknown values in our arrays can throw off the timing a lot, perhaps |
| 88 | // handling NaN values is a lot slower. Anyway, this guy is just meant to put |
| 89 | // reasonable values in our arrays. |
| 90 | template <typename T> void init9(T array[9]) { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 91 | SkRandom rand; |
reed@google.com | e0dcde7 | 2011-06-06 13:20:29 +0000 | [diff] [blame] | 92 | for (int i = 0; i < 9; i++) { |
| 93 | array[i] = rand.nextSScalar1(); |
| 94 | } |
| 95 | } |
| 96 | |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 97 | class GetTypeMatrixBench : public MatrixBench { |
| 98 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 99 | GetTypeMatrixBench() |
| 100 | : INHERITED("gettype") { |
bsalomon@google.com | 820e80a | 2011-10-24 21:09:40 +0000 | [diff] [blame] | 101 | fArray[0] = (float) fRnd.nextS(); |
| 102 | fArray[1] = (float) fRnd.nextS(); |
| 103 | fArray[2] = (float) fRnd.nextS(); |
| 104 | fArray[3] = (float) fRnd.nextS(); |
| 105 | fArray[4] = (float) fRnd.nextS(); |
| 106 | fArray[5] = (float) fRnd.nextS(); |
| 107 | fArray[6] = (float) fRnd.nextS(); |
| 108 | fArray[7] = (float) fRnd.nextS(); |
| 109 | fArray[8] = (float) fRnd.nextS(); |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 110 | } |
| 111 | protected: |
| 112 | // Putting random generation of the matrix inside performTest() |
| 113 | // would help us avoid anomalous runs, but takes up 25% or |
| 114 | // more of the function time. |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 115 | void performTest() override { |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 116 | fMatrix.setAll(fArray[0], fArray[1], fArray[2], |
| 117 | fArray[3], fArray[4], fArray[5], |
| 118 | fArray[6], fArray[7], fArray[8]); |
mtklein | cf44feb | 2014-06-02 18:22:12 -0700 | [diff] [blame] | 119 | // xoring into a volatile prevents the compiler from optimizing these away |
| 120 | volatile int junk = 0; |
| 121 | junk ^= (fMatrix.getType()); |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 122 | fMatrix.dirtyMatrixTypeCache(); |
mtklein | cf44feb | 2014-06-02 18:22:12 -0700 | [diff] [blame] | 123 | junk ^= (fMatrix.getType()); |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 124 | fMatrix.dirtyMatrixTypeCache(); |
mtklein | cf44feb | 2014-06-02 18:22:12 -0700 | [diff] [blame] | 125 | junk ^= (fMatrix.getType()); |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 126 | fMatrix.dirtyMatrixTypeCache(); |
mtklein | cf44feb | 2014-06-02 18:22:12 -0700 | [diff] [blame] | 127 | junk ^= (fMatrix.getType()); |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 128 | fMatrix.dirtyMatrixTypeCache(); |
mtklein | cf44feb | 2014-06-02 18:22:12 -0700 | [diff] [blame] | 129 | junk ^= (fMatrix.getType()); |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 130 | fMatrix.dirtyMatrixTypeCache(); |
mtklein | cf44feb | 2014-06-02 18:22:12 -0700 | [diff] [blame] | 131 | junk ^= (fMatrix.getType()); |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 132 | fMatrix.dirtyMatrixTypeCache(); |
mtklein | cf44feb | 2014-06-02 18:22:12 -0700 | [diff] [blame] | 133 | junk ^= (fMatrix.getType()); |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 134 | fMatrix.dirtyMatrixTypeCache(); |
mtklein | cf44feb | 2014-06-02 18:22:12 -0700 | [diff] [blame] | 135 | junk ^= (fMatrix.getType()); |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 136 | } |
| 137 | private: |
| 138 | SkMatrix fMatrix; |
| 139 | float fArray[9]; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 140 | SkRandom fRnd; |
tomhudson@google.com | 317d540 | 2011-06-24 18:30:49 +0000 | [diff] [blame] | 141 | typedef MatrixBench INHERITED; |
| 142 | }; |
| 143 | |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 144 | class DecomposeMatrixBench : public MatrixBench { |
| 145 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 146 | DecomposeMatrixBench() : INHERITED("decompose") {} |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 147 | |
| 148 | protected: |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 149 | void onPreDraw() override { |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 150 | for (int i = 0; i < 10; ++i) { |
| 151 | SkScalar rot0 = (fRandom.nextBool()) ? fRandom.nextRangeF(-180, 180) : 0.0f; |
| 152 | SkScalar sx = fRandom.nextRangeF(-3000.f, 3000.f); |
| 153 | SkScalar sy = (fRandom.nextBool()) ? fRandom.nextRangeF(-3000.f, 3000.f) : sx; |
| 154 | SkScalar rot1 = fRandom.nextRangeF(-180, 180); |
| 155 | fMatrix[i].setRotate(rot0); |
| 156 | fMatrix[i].postScale(sx, sy); |
| 157 | fMatrix[i].postRotate(rot1); |
| 158 | } |
| 159 | } |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 160 | void performTest() override { |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 161 | SkPoint rotation1, scale, rotation2; |
| 162 | for (int i = 0; i < 10; ++i) { |
| 163 | (void) SkDecomposeUpper2x2(fMatrix[i], &rotation1, &scale, &rotation2); |
| 164 | } |
| 165 | } |
| 166 | private: |
| 167 | SkMatrix fMatrix[10]; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 168 | SkRandom fRandom; |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 169 | typedef MatrixBench INHERITED; |
| 170 | }; |
| 171 | |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 172 | class InvertMapRectMatrixBench : public MatrixBench { |
| 173 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 174 | InvertMapRectMatrixBench(const char* name, int flags) |
| 175 | : INHERITED(name) |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 176 | , fFlags(flags) { |
| 177 | fMatrix.reset(); |
| 178 | fIteration = 0; |
| 179 | if (flags & kScale_Flag) { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 180 | fMatrix.postScale(1.5f, 2.5f); |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 181 | } |
| 182 | if (flags & kTranslate_Flag) { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 183 | fMatrix.postTranslate(1.5f, 2.5f); |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 184 | } |
| 185 | if (flags & kRotate_Flag) { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 186 | fMatrix.postRotate(45.0f); |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 187 | } |
| 188 | if (flags & kPerspective_Flag) { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 189 | fMatrix.setPerspX(1.5f); |
| 190 | fMatrix.setPerspY(2.5f); |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 191 | } |
| 192 | if (0 == (flags & kUncachedTypeMask_Flag)) { |
| 193 | fMatrix.getType(); |
| 194 | } |
| 195 | } |
| 196 | enum Flag { |
| 197 | kScale_Flag = 0x01, |
| 198 | kTranslate_Flag = 0x02, |
| 199 | kRotate_Flag = 0x04, |
| 200 | kPerspective_Flag = 0x08, |
| 201 | kUncachedTypeMask_Flag = 0x10, |
| 202 | }; |
| 203 | protected: |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 204 | void performTest() override { |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 205 | if (fFlags & kUncachedTypeMask_Flag) { |
| 206 | // This will invalidate the typemask without |
| 207 | // changing the matrix. |
| 208 | fMatrix.setPerspX(fMatrix.getPerspX()); |
| 209 | } |
| 210 | SkMatrix inv; |
robertphillips@google.com | 31f8f73 | 2012-09-17 13:36:47 +0000 | [diff] [blame] | 211 | bool invertible = fMatrix.invert(&inv); |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 212 | SkASSERT(invertible); |
| 213 | SkRect transformedRect; |
robertphillips@google.com | 31f8f73 | 2012-09-17 13:36:47 +0000 | [diff] [blame] | 214 | // an arbitrary, small, non-zero rect to transform |
| 215 | SkRect srcRect = SkRect::MakeWH(SkIntToScalar(10), SkIntToScalar(10)); |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 216 | if (invertible) { |
robertphillips@google.com | 31f8f73 | 2012-09-17 13:36:47 +0000 | [diff] [blame] | 217 | inv.mapRect(&transformedRect, srcRect); |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | private: |
| 221 | SkMatrix fMatrix; |
junov@chromium.org | 6fc5699 | 2012-07-12 14:01:32 +0000 | [diff] [blame] | 222 | int fFlags; |
| 223 | unsigned fIteration; |
| 224 | typedef MatrixBench INHERITED; |
| 225 | }; |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 226 | |
reed@google.com | 82bf8bb | 2013-01-04 14:04:08 +0000 | [diff] [blame] | 227 | /////////////////////////////////////////////////////////////////////////////// |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 228 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 229 | DEF_BENCH( return new EqualsMatrixBench(); ) |
| 230 | DEF_BENCH( return new ScaleMatrixBench(); ) |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 231 | DEF_BENCH( return new GetTypeMatrixBench(); ) |
| 232 | DEF_BENCH( return new DecomposeMatrixBench(); ) |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 233 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 234 | DEF_BENCH( return new InvertMapRectMatrixBench("invert_maprect_identity", 0); ) |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 235 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 236 | DEF_BENCH(return new InvertMapRectMatrixBench( |
reed@google.com | 90533be | 2013-01-04 15:46:42 +0000 | [diff] [blame] | 237 | "invert_maprect_rectstaysrect", |
| 238 | InvertMapRectMatrixBench::kScale_Flag | |
| 239 | InvertMapRectMatrixBench::kTranslate_Flag); ) |
| 240 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 241 | DEF_BENCH(return new InvertMapRectMatrixBench( |
reed@google.com | 90533be | 2013-01-04 15:46:42 +0000 | [diff] [blame] | 242 | "invert_maprect_translate", |
| 243 | InvertMapRectMatrixBench::kTranslate_Flag); ) |
tomhudson@google.com | 7b4e107 | 2011-06-03 19:16:56 +0000 | [diff] [blame] | 244 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 245 | DEF_BENCH(return new InvertMapRectMatrixBench( |
reed@google.com | 82bf8bb | 2013-01-04 14:04:08 +0000 | [diff] [blame] | 246 | "invert_maprect_nonpersp", |
| 247 | InvertMapRectMatrixBench::kScale_Flag | |
| 248 | InvertMapRectMatrixBench::kRotate_Flag | |
| 249 | InvertMapRectMatrixBench::kTranslate_Flag); ) |
reed@google.com | 3fb5187 | 2011-06-01 15:11:22 +0000 | [diff] [blame] | 250 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 251 | DEF_BENCH( return new InvertMapRectMatrixBench( |
reed@google.com | 82bf8bb | 2013-01-04 14:04:08 +0000 | [diff] [blame] | 252 | "invert_maprect_persp", |
| 253 | InvertMapRectMatrixBench::kPerspective_Flag); ) |
tomhudson@google.com | 288ff33 | 2011-06-07 14:31:38 +0000 | [diff] [blame] | 254 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 255 | DEF_BENCH( return new InvertMapRectMatrixBench( |
reed@google.com | 82bf8bb | 2013-01-04 14:04:08 +0000 | [diff] [blame] | 256 | "invert_maprect_typemask_rectstaysrect", |
| 257 | InvertMapRectMatrixBench::kUncachedTypeMask_Flag | |
| 258 | InvertMapRectMatrixBench::kScale_Flag | |
| 259 | InvertMapRectMatrixBench::kTranslate_Flag); ) |
| 260 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 261 | DEF_BENCH( return new InvertMapRectMatrixBench( |
reed@google.com | 82bf8bb | 2013-01-04 14:04:08 +0000 | [diff] [blame] | 262 | "invert_maprect_typemask_nonpersp", |
| 263 | InvertMapRectMatrixBench::kUncachedTypeMask_Flag | |
| 264 | InvertMapRectMatrixBench::kScale_Flag | |
| 265 | InvertMapRectMatrixBench::kRotate_Flag | |
| 266 | InvertMapRectMatrixBench::kTranslate_Flag); ) |
| 267 | |
reed | 8010632 | 2015-03-23 08:15:14 -0700 | [diff] [blame] | 268 | /////////////////////////////////////////////////////////////////////////////// |
| 269 | |
reed | d8b34c2 | 2015-03-27 14:00:41 -0700 | [diff] [blame] | 270 | static SkMatrix make_trans() { return SkMatrix::MakeTrans(2, 3); } |
reed | 8010632 | 2015-03-23 08:15:14 -0700 | [diff] [blame] | 271 | static SkMatrix make_scale() { SkMatrix m(make_trans()); m.postScale(1.5f, 0.5f); return m; } |
| 272 | static SkMatrix make_afine() { SkMatrix m(make_trans()); m.postRotate(15); return m; } |
| 273 | |
| 274 | class MapPointsMatrixBench : public MatrixBench { |
| 275 | protected: |
| 276 | SkMatrix fM; |
| 277 | enum { |
| 278 | N = 32 |
| 279 | }; |
| 280 | SkPoint fSrc[N], fDst[N]; |
reed | 8010632 | 2015-03-23 08:15:14 -0700 | [diff] [blame] | 281 | public: |
reed | 7da1901 | 2015-03-29 11:58:48 -0700 | [diff] [blame] | 282 | MapPointsMatrixBench(const char name[], const SkMatrix& m) |
| 283 | : MatrixBench(name), fM(m) |
reed | 8010632 | 2015-03-23 08:15:14 -0700 | [diff] [blame] | 284 | { |
| 285 | SkRandom rand; |
| 286 | for (int i = 0; i < N; ++i) { |
| 287 | fSrc[i].set(rand.nextSScalar1(), rand.nextSScalar1()); |
| 288 | } |
| 289 | } |
| 290 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 291 | void performTest() override { |
reed | 7da1901 | 2015-03-29 11:58:48 -0700 | [diff] [blame] | 292 | for (int i = 0; i < 1000000; ++i) { |
| 293 | fM.mapPoints(fDst, fSrc, N); |
reed | 8010632 | 2015-03-23 08:15:14 -0700 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | }; |
reed | 7da1901 | 2015-03-29 11:58:48 -0700 | [diff] [blame] | 297 | DEF_BENCH( return new MapPointsMatrixBench("mappoints_identity", SkMatrix::I()); ) |
| 298 | DEF_BENCH( return new MapPointsMatrixBench("mappoints_trans", make_trans()); ) |
| 299 | DEF_BENCH( return new MapPointsMatrixBench("mappoints_scale", make_scale()); ) |
| 300 | DEF_BENCH( return new MapPointsMatrixBench("mappoints_affine", make_afine()); ) |
reed | 8010632 | 2015-03-23 08:15:14 -0700 | [diff] [blame] | 301 | |