robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "bench/Benchmark.h" |
| 9 | #include "include/core/SkBitmap.h" |
| 10 | #include "include/core/SkCanvas.h" |
Mike Reed | 46f5c5f | 2020-02-20 15:42:29 -0500 | [diff] [blame] | 11 | #include "include/core/SkM44.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkPaint.h" |
| 13 | #include "include/core/SkShader.h" |
| 14 | #include "include/core/SkString.h" |
| 15 | #include "include/core/SkVertices.h" |
| 16 | #include "include/utils/SkRandom.h" |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 17 | |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 18 | // This bench simulates the calls Skia sees from various HTML5 canvas |
| 19 | // game bench marks |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 20 | class GameBench : public Benchmark { |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 21 | public: |
| 22 | enum Type { |
skia.committer@gmail.com | 0f20a3f | 2013-05-10 07:01:04 +0000 | [diff] [blame] | 23 | kScale_Type, |
| 24 | kTranslate_Type, |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 25 | kRotate_Type |
| 26 | }; |
| 27 | |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 28 | enum Clear { |
| 29 | kFull_Clear, |
| 30 | kPartial_Clear |
| 31 | }; |
| 32 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 33 | GameBench(Type type, Clear clear, |
robertphillips@google.com | 631a59b | 2013-07-31 14:57:53 +0000 | [diff] [blame] | 34 | bool aligned = false, bool useAtlas = false, |
| 35 | bool useDrawVertices = false) |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 36 | : fType(type) |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 37 | , fClear(clear) |
robertphillips@google.com | 347fd4e | 2013-05-15 14:18:32 +0000 | [diff] [blame] | 38 | , fAligned(aligned) |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 39 | , fUseAtlas(useAtlas) |
robertphillips@google.com | 631a59b | 2013-07-31 14:57:53 +0000 | [diff] [blame] | 40 | , fUseDrawVertices(useDrawVertices) |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 41 | , fName("game") |
| 42 | , fNumSaved(0) |
| 43 | , fInitialized(false) { |
| 44 | |
| 45 | switch (fType) { |
| 46 | case kScale_Type: |
| 47 | fName.append("_scale"); |
| 48 | break; |
| 49 | case kTranslate_Type: |
| 50 | fName.append("_trans"); |
| 51 | break; |
| 52 | case kRotate_Type: |
| 53 | fName.append("_rot"); |
| 54 | break; |
Brian Salomon | 2335644 | 2018-11-30 15:33:19 -0500 | [diff] [blame] | 55 | } |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 56 | |
robertphillips@google.com | 347fd4e | 2013-05-15 14:18:32 +0000 | [diff] [blame] | 57 | if (aligned) { |
| 58 | fName.append("_aligned"); |
| 59 | } |
| 60 | |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 61 | if (kPartial_Clear == clear) { |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 62 | fName.append("_partial"); |
| 63 | } else { |
| 64 | fName.append("_full"); |
| 65 | } |
| 66 | |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 67 | if (useAtlas) { |
| 68 | fName.append("_atlas"); |
| 69 | } |
| 70 | |
robertphillips@google.com | 631a59b | 2013-07-31 14:57:53 +0000 | [diff] [blame] | 71 | if (useDrawVertices) { |
| 72 | fName.append("_drawVerts"); |
| 73 | } |
| 74 | |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 75 | // It's HTML 5 canvas, so always AA |
| 76 | fName.append("_aa"); |
| 77 | } |
| 78 | |
| 79 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 80 | const char* onGetName() override { |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 81 | return fName.c_str(); |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 82 | } |
| 83 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 84 | void onDelayedSetup() override { |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 85 | if (!fInitialized) { |
| 86 | this->makeCheckerboard(); |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 87 | this->makeAtlas(); |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 88 | fInitialized = true; |
| 89 | } |
| 90 | } |
| 91 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 92 | void onDraw(int loops, SkCanvas* canvas) override { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 93 | SkRandom scaleRand; |
| 94 | SkRandom transRand; |
| 95 | SkRandom rotRand; |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 96 | |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 97 | int width, height; |
| 98 | if (fUseAtlas) { |
| 99 | width = kAtlasCellWidth; |
| 100 | height = kAtlasCellHeight; |
| 101 | } else { |
| 102 | width = kCheckerboardWidth; |
| 103 | height = kCheckerboardHeight; |
| 104 | } |
| 105 | |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 106 | SkPaint clearPaint; |
| 107 | clearPaint.setColor(0xFF000000); |
| 108 | clearPaint.setAntiAlias(true); |
| 109 | |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 110 | SkISize size = canvas->getBaseLayerSize(); |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 111 | |
| 112 | SkScalar maxTransX, maxTransY; |
| 113 | |
| 114 | if (kScale_Type == fType) { |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 115 | maxTransX = size.fWidth - (1.5f * width); |
| 116 | maxTransY = size.fHeight - (1.5f * height); |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 117 | } else if (kTranslate_Type == fType) { |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 118 | maxTransX = SkIntToScalar(size.fWidth - width); |
| 119 | maxTransY = SkIntToScalar(size.fHeight - height); |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 120 | } else { |
| 121 | SkASSERT(kRotate_Type == fType); |
| 122 | // Yes, some rotations will be off the top and left sides |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 123 | maxTransX = size.fWidth - SK_ScalarSqrt2 * height; |
| 124 | maxTransY = size.fHeight - SK_ScalarSqrt2 * height; |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | SkMatrix mat; |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 128 | SkRect dst = { 0, 0, SkIntToScalar(width), SkIntToScalar(height) }; |
| 129 | SkRect clearRect = { -1.0f, -1.0f, width+1.0f, height+1.0f }; |
robertphillips@google.com | 631a59b | 2013-07-31 14:57:53 +0000 | [diff] [blame] | 130 | SkPoint verts[4] = { // for drawVertices path |
| 131 | { 0, 0 }, |
| 132 | { 0, SkIntToScalar(height) }, |
| 133 | { SkIntToScalar(width), SkIntToScalar(height) }, |
| 134 | { SkIntToScalar(width), 0 } |
| 135 | }; |
| 136 | uint16_t indices[6] = { 0, 1, 2, 0, 2, 3 }; |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 137 | |
| 138 | SkPaint p; |
| 139 | p.setColor(0xFF000000); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 140 | p.setFilterQuality(kLow_SkFilterQuality); |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 141 | |
robertphillips@google.com | 631a59b | 2013-07-31 14:57:53 +0000 | [diff] [blame] | 142 | SkPaint p2; // for drawVertices path |
| 143 | p2.setColor(0xFF000000); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 144 | p2.setFilterQuality(kLow_SkFilterQuality); |
Mike Reed | 50acf8f | 2019-04-08 13:20:23 -0400 | [diff] [blame] | 145 | p2.setShader(fAtlas.makeShader()); |
robertphillips@google.com | 631a59b | 2013-07-31 14:57:53 +0000 | [diff] [blame] | 146 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 147 | for (int i = 0; i < loops; ++i, ++fNumSaved) { |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 148 | if (0 == i % kNumBeforeClear) { |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 149 | if (kPartial_Clear == fClear) { |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 150 | for (int j = 0; j < fNumSaved; ++j) { |
| 151 | canvas->setMatrix(SkMatrix::I()); |
| 152 | mat.setTranslate(fSaved[j][0], fSaved[j][1]); |
| 153 | |
| 154 | if (kScale_Type == fType) { |
| 155 | mat.preScale(fSaved[j][2], fSaved[j][2]); |
| 156 | } else if (kRotate_Type == fType) { |
| 157 | mat.preRotate(fSaved[j][2]); |
| 158 | } |
| 159 | |
| 160 | canvas->concat(mat); |
| 161 | canvas->drawRect(clearRect, clearPaint); |
| 162 | } |
| 163 | } else { |
| 164 | canvas->clear(0xFF000000); |
| 165 | } |
| 166 | |
| 167 | fNumSaved = 0; |
| 168 | } |
| 169 | |
| 170 | SkASSERT(fNumSaved < kNumBeforeClear); |
| 171 | |
| 172 | canvas->setMatrix(SkMatrix::I()); |
| 173 | |
| 174 | fSaved[fNumSaved][0] = transRand.nextRangeScalar(0.0f, maxTransX); |
| 175 | fSaved[fNumSaved][1] = transRand.nextRangeScalar(0.0f, maxTransY); |
robertphillips@google.com | 347fd4e | 2013-05-15 14:18:32 +0000 | [diff] [blame] | 176 | if (fAligned) { |
| 177 | // make the translations integer aligned |
| 178 | fSaved[fNumSaved][0] = SkScalarFloorToScalar(fSaved[fNumSaved][0]); |
| 179 | fSaved[fNumSaved][1] = SkScalarFloorToScalar(fSaved[fNumSaved][1]); |
| 180 | } |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 181 | |
| 182 | mat.setTranslate(fSaved[fNumSaved][0], fSaved[fNumSaved][1]); |
| 183 | |
| 184 | if (kScale_Type == fType) { |
| 185 | fSaved[fNumSaved][2] = scaleRand.nextRangeScalar(0.5f, 1.5f); |
| 186 | mat.preScale(fSaved[fNumSaved][2], fSaved[fNumSaved][2]); |
| 187 | } else if (kRotate_Type == fType) { |
| 188 | fSaved[fNumSaved][2] = rotRand.nextRangeScalar(0.0f, 360.0f); |
| 189 | mat.preRotate(fSaved[fNumSaved][2]); |
| 190 | } |
| 191 | |
| 192 | canvas->concat(mat); |
skia.committer@gmail.com | 26da7f0 | 2013-06-01 07:01:39 +0000 | [diff] [blame] | 193 | if (fUseAtlas) { |
commit-bot@chromium.org | 44e3f71 | 2014-05-07 17:12:55 +0000 | [diff] [blame] | 194 | const int curCell = i % (kNumAtlasedX * kNumAtlasedY); |
robertphillips@google.com | 631a59b | 2013-07-31 14:57:53 +0000 | [diff] [blame] | 195 | SkIRect src = fAtlasRects[curCell % (kNumAtlasedX)][curCell / (kNumAtlasedX)]; |
robertphillips@google.com | 631a59b | 2013-07-31 14:57:53 +0000 | [diff] [blame] | 196 | |
| 197 | if (fUseDrawVertices) { |
skia.committer@gmail.com | 5d4b773 | 2013-08-01 07:01:05 +0000 | [diff] [blame] | 198 | SkPoint uvs[4] = { |
robertphillips@google.com | 631a59b | 2013-07-31 14:57:53 +0000 | [diff] [blame] | 199 | { SkIntToScalar(src.fLeft), SkIntToScalar(src.fBottom) }, |
| 200 | { SkIntToScalar(src.fLeft), SkIntToScalar(src.fTop) }, |
| 201 | { SkIntToScalar(src.fRight), SkIntToScalar(src.fTop) }, |
| 202 | { SkIntToScalar(src.fRight), SkIntToScalar(src.fBottom) }, |
| 203 | }; |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 204 | canvas->drawVertices(SkVertices::MakeCopy(SkVertices::kTriangles_VertexMode, |
| 205 | 4, verts, uvs, nullptr, 6, indices), |
| 206 | SkBlendMode::kModulate, p2); |
robertphillips@google.com | 631a59b | 2013-07-31 14:57:53 +0000 | [diff] [blame] | 207 | } else { |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 208 | canvas->drawBitmapRect(fAtlas, src, dst, &p, |
| 209 | SkCanvas::kFast_SrcRectConstraint); |
robertphillips@google.com | 631a59b | 2013-07-31 14:57:53 +0000 | [diff] [blame] | 210 | } |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 211 | } else { |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 212 | canvas->drawBitmapRect(fCheckerboard, dst, &p); |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 213 | } |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
| 217 | private: |
| 218 | static const int kCheckerboardWidth = 64; |
| 219 | static const int kCheckerboardHeight = 128; |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 220 | |
| 221 | static const int kAtlasCellWidth = 48; |
| 222 | static const int kAtlasCellHeight = 36; |
| 223 | static const int kNumAtlasedX = 5; |
| 224 | static const int kNumAtlasedY = 5; |
| 225 | static const int kAtlasSpacer = 2; |
| 226 | static const int kTotAtlasWidth = kNumAtlasedX * kAtlasCellWidth + |
| 227 | (kNumAtlasedX+1) * kAtlasSpacer; |
| 228 | static const int kTotAtlasHeight = kNumAtlasedY * kAtlasCellHeight + |
| 229 | (kNumAtlasedY+1) * kAtlasSpacer; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 230 | static const int kNumBeforeClear = 100; |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 231 | |
| 232 | Type fType; |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 233 | Clear fClear; |
robertphillips@google.com | 347fd4e | 2013-05-15 14:18:32 +0000 | [diff] [blame] | 234 | bool fAligned; |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 235 | bool fUseAtlas; |
robertphillips@google.com | 631a59b | 2013-07-31 14:57:53 +0000 | [diff] [blame] | 236 | bool fUseDrawVertices; |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 237 | SkString fName; |
| 238 | int fNumSaved; // num draws stored in 'fSaved' |
| 239 | bool fInitialized; |
| 240 | |
| 241 | // 0 & 1 are always x & y translate. 2 is either scale or rotate. |
| 242 | SkScalar fSaved[kNumBeforeClear][3]; |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 243 | |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 244 | SkBitmap fCheckerboard; |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 245 | SkBitmap fAtlas; |
| 246 | SkIRect fAtlasRects[kNumAtlasedX][kNumAtlasedY]; |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 247 | |
| 248 | // Note: the resulting checker board has transparency |
| 249 | void makeCheckerboard() { |
robertphillips@google.com | 6d58ad3 | 2013-05-09 19:08:57 +0000 | [diff] [blame] | 250 | static int kCheckSize = 16; |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 251 | |
reed | 6c22573 | 2014-06-09 19:52:07 -0700 | [diff] [blame] | 252 | fCheckerboard.allocN32Pixels(kCheckerboardWidth, kCheckerboardHeight); |
robertphillips@google.com | 6d58ad3 | 2013-05-09 19:08:57 +0000 | [diff] [blame] | 253 | for (int y = 0; y < kCheckerboardHeight; ++y) { |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 254 | int even = (y / kCheckSize) % 2; |
| 255 | |
| 256 | SkPMColor* scanline = fCheckerboard.getAddr32(0, y); |
| 257 | |
robertphillips@google.com | 6d58ad3 | 2013-05-09 19:08:57 +0000 | [diff] [blame] | 258 | for (int x = 0; x < kCheckerboardWidth; ++x) { |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 259 | if (even == (x / kCheckSize) % 2) { |
| 260 | *scanline++ = 0xFFFF0000; |
| 261 | } else { |
| 262 | *scanline++ = 0x00000000; |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 268 | // Note: the resulting atlas has transparency |
| 269 | void makeAtlas() { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 270 | SkRandom rand; |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 271 | |
| 272 | SkColor colors[kNumAtlasedX][kNumAtlasedY]; |
| 273 | |
| 274 | for (int y = 0; y < kNumAtlasedY; ++y) { |
| 275 | for (int x = 0; x < kNumAtlasedX; ++x) { |
| 276 | colors[x][y] = rand.nextU() | 0xff000000; |
| 277 | fAtlasRects[x][y] = SkIRect::MakeXYWH(kAtlasSpacer + x * (kAtlasCellWidth + kAtlasSpacer), |
| 278 | kAtlasSpacer + y * (kAtlasCellHeight + kAtlasSpacer), |
| 279 | kAtlasCellWidth, |
| 280 | kAtlasCellHeight); |
| 281 | } |
| 282 | } |
| 283 | |
reed | 6c22573 | 2014-06-09 19:52:07 -0700 | [diff] [blame] | 284 | fAtlas.allocN32Pixels(kTotAtlasWidth, kTotAtlasHeight); |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 285 | |
| 286 | for (int y = 0; y < kTotAtlasHeight; ++y) { |
| 287 | int colorY = y / (kAtlasCellHeight + kAtlasSpacer); |
| 288 | bool inColorY = (y % (kAtlasCellHeight + kAtlasSpacer)) >= kAtlasSpacer; |
| 289 | |
| 290 | SkPMColor* scanline = fAtlas.getAddr32(0, y); |
| 291 | |
| 292 | for (int x = 0; x < kTotAtlasWidth; ++x, ++scanline) { |
| 293 | int colorX = x / (kAtlasCellWidth + kAtlasSpacer); |
| 294 | bool inColorX = (x % (kAtlasCellWidth + kAtlasSpacer)) >= kAtlasSpacer; |
| 295 | |
| 296 | if (inColorX && inColorY) { |
| 297 | SkASSERT(colorX < kNumAtlasedX && colorY < kNumAtlasedY); |
| 298 | *scanline = colors[colorX][colorY]; |
| 299 | } else { |
| 300 | *scanline = 0x00000000; |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 306 | typedef Benchmark INHERITED; |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 307 | }; |
| 308 | |
| 309 | // Partial clear |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 310 | DEF_BENCH(return new GameBench(GameBench::kScale_Type, GameBench::kPartial_Clear);) |
| 311 | DEF_BENCH(return new GameBench(GameBench::kTranslate_Type, GameBench::kPartial_Clear);) |
| 312 | DEF_BENCH(return new GameBench(GameBench::kTranslate_Type, GameBench::kPartial_Clear, true);) |
| 313 | DEF_BENCH(return new GameBench(GameBench::kRotate_Type, GameBench::kPartial_Clear);) |
robertphillips@google.com | 6670ab9 | 2013-05-09 19:03:48 +0000 | [diff] [blame] | 314 | |
| 315 | // Full clear |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 316 | DEF_BENCH(return new GameBench(GameBench::kScale_Type, GameBench::kFull_Clear);) |
| 317 | DEF_BENCH(return new GameBench(GameBench::kTranslate_Type, GameBench::kFull_Clear);) |
| 318 | DEF_BENCH(return new GameBench(GameBench::kTranslate_Type, GameBench::kFull_Clear, true);) |
| 319 | DEF_BENCH(return new GameBench(GameBench::kRotate_Type, GameBench::kFull_Clear);) |
robertphillips@google.com | f865be3 | 2013-05-31 13:27:02 +0000 | [diff] [blame] | 320 | |
| 321 | // Atlased |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 322 | DEF_BENCH(return new GameBench(GameBench::kTranslate_Type, GameBench::kFull_Clear, false, true);) |
| 323 | DEF_BENCH(return new GameBench( |
| 324 | GameBench::kTranslate_Type, GameBench::kFull_Clear, false, true, true);) |
Mike Reed | 77cf430 | 2019-12-30 10:21:29 -0500 | [diff] [blame] | 325 | |
| 326 | |
| 327 | class CanvasMatrixBench : public Benchmark { |
| 328 | SkString fName; |
| 329 | public: |
| 330 | enum Type { |
| 331 | kTranslate_Type, |
| 332 | kScale_Type, |
| 333 | k2x3_Type, |
| 334 | k3x3_Type, |
Mike Reed | 064c7f9 | 2020-01-08 17:33:04 -0500 | [diff] [blame] | 335 | k4x4_Type, |
Mike Reed | 77cf430 | 2019-12-30 10:21:29 -0500 | [diff] [blame] | 336 | }; |
| 337 | Type fType; |
| 338 | |
| 339 | CanvasMatrixBench(Type t) : fType(t) { |
| 340 | fName.set("canvas_matrix"); |
| 341 | switch (fType) { |
| 342 | case kTranslate_Type: fName.append("_trans"); break; |
| 343 | case kScale_Type: fName.append("_scale"); break; |
| 344 | case k2x3_Type: fName.append("_2x3"); break; |
| 345 | case k3x3_Type: fName.append("_3x3"); break; |
Mike Reed | 064c7f9 | 2020-01-08 17:33:04 -0500 | [diff] [blame] | 346 | case k4x4_Type: fName.append("_4x4"); break; |
Mike Reed | 77cf430 | 2019-12-30 10:21:29 -0500 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
| 350 | protected: |
| 351 | const char* onGetName() override { |
| 352 | return fName.c_str(); |
| 353 | } |
| 354 | |
| 355 | void onDraw(int loops, SkCanvas* canvas) override { |
| 356 | SkMatrix m; |
| 357 | m.setRotate(1); |
| 358 | if (fType == k3x3_Type) { |
| 359 | m[7] = 0.0001f; |
| 360 | } |
Mike Reed | b26b4e7 | 2020-01-22 14:31:21 -0500 | [diff] [blame] | 361 | SkM44 m4(m); |
Mike Reed | 77cf430 | 2019-12-30 10:21:29 -0500 | [diff] [blame] | 362 | |
| 363 | for (int i = 0; i < loops; ++i) { |
| 364 | canvas->save(); |
| 365 | for (int j = 0; j < 10000; ++j) { |
| 366 | switch (fType) { |
| 367 | case kTranslate_Type: canvas->translate(0.0001f, 0.0001f); break; |
| 368 | case kScale_Type: canvas->scale(1.0001f, 0.9999f); break; |
| 369 | case k2x3_Type: canvas->concat(m); break; |
| 370 | case k3x3_Type: canvas->concat(m); break; |
Mike Reed | 3ef77dd | 2020-04-06 10:41:09 -0400 | [diff] [blame^] | 371 | case k4x4_Type: canvas->concat(m4); break; |
Mike Reed | 77cf430 | 2019-12-30 10:21:29 -0500 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | canvas->restore(); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | private: |
| 379 | typedef Benchmark INHERITED; |
| 380 | }; |
| 381 | |
| 382 | DEF_BENCH(return new CanvasMatrixBench(CanvasMatrixBench::kTranslate_Type)); |
| 383 | DEF_BENCH(return new CanvasMatrixBench(CanvasMatrixBench::kScale_Type)); |
| 384 | DEF_BENCH(return new CanvasMatrixBench(CanvasMatrixBench::k2x3_Type)); |
| 385 | DEF_BENCH(return new CanvasMatrixBench(CanvasMatrixBench::k3x3_Type)); |
Mike Reed | 064c7f9 | 2020-01-08 17:33:04 -0500 | [diff] [blame] | 386 | DEF_BENCH(return new CanvasMatrixBench(CanvasMatrixBench::k4x4_Type)); |