epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | */ |
Mike Reed | 75ae421 | 2018-01-23 11:24:08 -0500 | [diff] [blame] | 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" |
| 11 | #include "include/core/SkPaint.h" |
| 12 | #include "include/core/SkShader.h" |
| 13 | #include "include/core/SkString.h" |
| 14 | #include "include/effects/SkGradientShader.h" |
| 15 | #include "include/utils/SkRandom.h" |
| 16 | #include "tools/flags/CommandLineFlags.h" |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 17 | |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 18 | static DEFINE_double(strokeWidth, -1.0, "If set, use this stroke width in RectBench."); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 19 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 20 | class RectBench : public Benchmark { |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 21 | public: |
mike@reedtribe.org | 2ecead5 | 2011-04-02 13:37:23 +0000 | [diff] [blame] | 22 | int fShift, fStroke; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 23 | enum { |
| 24 | W = 640, |
| 25 | H = 480, |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 26 | N = 300, |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 27 | }; |
| 28 | SkRect fRects[N]; |
| 29 | SkColor fColors[N]; |
Michael Ludwig | dde8b55 | 2018-11-20 14:58:23 -0500 | [diff] [blame] | 30 | bool fAA; |
| 31 | bool fPerspective; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 32 | |
Michael Ludwig | dde8b55 | 2018-11-20 14:58:23 -0500 | [diff] [blame] | 33 | RectBench(int shift, int stroke = 0, bool aa = true, bool perspective = false) |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 34 | : fShift(shift) |
Michael Ludwig | dde8b55 | 2018-11-20 14:58:23 -0500 | [diff] [blame] | 35 | , fStroke(stroke) |
| 36 | , fAA(aa) |
| 37 | , fPerspective(perspective) {} |
reed@google.com | 1fcd51e | 2011-01-05 15:50:27 +0000 | [diff] [blame] | 38 | |
reed@android.com | d2c3744 | 2009-01-08 03:00:57 +0000 | [diff] [blame] | 39 | const char* computeName(const char root[]) { |
Brian Salomon | 3349c6f | 2017-03-01 09:49:58 -0500 | [diff] [blame] | 40 | fBaseName.printf("%s_%d", root, fShift); |
mike@reedtribe.org | 2ecead5 | 2011-04-02 13:37:23 +0000 | [diff] [blame] | 41 | if (fStroke > 0) { |
Brian Salomon | 3349c6f | 2017-03-01 09:49:58 -0500 | [diff] [blame] | 42 | fBaseName.appendf("_stroke_%d", fStroke); |
mike@reedtribe.org | 2ecead5 | 2011-04-02 13:37:23 +0000 | [diff] [blame] | 43 | } |
Michael Ludwig | dde8b55 | 2018-11-20 14:58:23 -0500 | [diff] [blame] | 44 | if (fAA) { |
| 45 | fBaseName.appendf("_aa"); |
| 46 | } else { |
| 47 | fBaseName.appendf("_bw"); |
| 48 | } |
| 49 | if (fPerspective) { |
| 50 | fBaseName.appendf("_persp"); |
| 51 | } |
Brian Salomon | 3349c6f | 2017-03-01 09:49:58 -0500 | [diff] [blame] | 52 | return fBaseName.c_str(); |
reed@android.com | d2c3744 | 2009-01-08 03:00:57 +0000 | [diff] [blame] | 53 | } |
reed@google.com | 1fcd51e | 2011-01-05 15:50:27 +0000 | [diff] [blame] | 54 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 55 | protected: |
Brian Salomon | dac5f6b | 2017-02-28 16:11:04 -0500 | [diff] [blame] | 56 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 57 | virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) { |
| 58 | c->drawRect(r, p); |
| 59 | } |
| 60 | |
reed | 57b7671 | 2015-09-25 04:49:43 -0700 | [diff] [blame] | 61 | const char* onGetName() override { return computeName("rects"); } |
commit-bot@chromium.org | 000d732 | 2013-12-05 12:07:44 +0000 | [diff] [blame] | 62 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 63 | void onDelayedSetup() override { |
commit-bot@chromium.org | 000d732 | 2013-12-05 12:07:44 +0000 | [diff] [blame] | 64 | SkRandom rand; |
| 65 | const SkScalar offset = SK_Scalar1/3; |
| 66 | for (int i = 0; i < N; i++) { |
| 67 | int x = rand.nextU() % W; |
| 68 | int y = rand.nextU() % H; |
| 69 | int w = rand.nextU() % W; |
| 70 | int h = rand.nextU() % H; |
| 71 | w >>= fShift; |
| 72 | h >>= fShift; |
| 73 | x -= w/2; |
| 74 | y -= h/2; |
| 75 | fRects[i].set(SkIntToScalar(x), SkIntToScalar(y), |
| 76 | SkIntToScalar(x+w), SkIntToScalar(y+h)); |
| 77 | fRects[i].offset(offset, offset); |
| 78 | fColors[i] = rand.nextU() | 0xFF808080; |
| 79 | } |
| 80 | } |
| 81 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 82 | void onDraw(int loops, SkCanvas* canvas) override { |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 83 | SkPaint paint; |
mike@reedtribe.org | 2ecead5 | 2011-04-02 13:37:23 +0000 | [diff] [blame] | 84 | if (fStroke > 0) { |
| 85 | paint.setStyle(SkPaint::kStroke_Style); |
| 86 | paint.setStrokeWidth(SkIntToScalar(fStroke)); |
| 87 | } |
Michael Ludwig | dde8b55 | 2018-11-20 14:58:23 -0500 | [diff] [blame] | 88 | if (fPerspective) { |
| 89 | // Apply some fixed perspective to change how ops may draw the rects |
| 90 | SkMatrix perspective; |
| 91 | perspective.setIdentity(); |
| 92 | perspective.setPerspX(1e-4f); |
| 93 | perspective.setPerspY(1e-3f); |
| 94 | perspective.setSkewX(0.1f); |
| 95 | canvas->concat(perspective); |
| 96 | } |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 97 | for (int i = 0; i < loops; i++) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 98 | paint.setColor(fColors[i % N]); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 99 | this->setupPaint(&paint); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 100 | this->drawThisRect(canvas, fRects[i % N], paint); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
Brian Salomon | 3349c6f | 2017-03-01 09:49:58 -0500 | [diff] [blame] | 103 | |
Michael Ludwig | dde8b55 | 2018-11-20 14:58:23 -0500 | [diff] [blame] | 104 | void setupPaint(SkPaint* paint) override { |
| 105 | this->INHERITED::setupPaint(paint); |
| 106 | paint->setAntiAlias(fAA); |
| 107 | } |
| 108 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 109 | private: |
Brian Salomon | 3349c6f | 2017-03-01 09:49:58 -0500 | [diff] [blame] | 110 | SkString fBaseName; |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 111 | typedef Benchmark INHERITED; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
reed@google.com | 2d078b6 | 2012-11-15 19:52:07 +0000 | [diff] [blame] | 114 | class SrcModeRectBench : public RectBench { |
| 115 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 116 | SrcModeRectBench() : INHERITED(1, 0) { |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 117 | fMode = SkBlendMode::kSrc; |
reed@google.com | 2d078b6 | 2012-11-15 19:52:07 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 121 | void setupPaint(SkPaint* paint) override { |
reed@google.com | 2d078b6 | 2012-11-15 19:52:07 +0000 | [diff] [blame] | 122 | this->INHERITED::setupPaint(paint); |
| 123 | // srcmode is most interesting when we're not opaque |
| 124 | paint->setAlpha(0x80); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 125 | paint->setBlendMode(fMode); |
reed@google.com | 2d078b6 | 2012-11-15 19:52:07 +0000 | [diff] [blame] | 126 | } |
| 127 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 128 | const char* onGetName() override { |
reed@google.com | 2d078b6 | 2012-11-15 19:52:07 +0000 | [diff] [blame] | 129 | fName.set(this->INHERITED::onGetName()); |
| 130 | fName.prepend("srcmode_"); |
| 131 | return fName.c_str(); |
| 132 | } |
| 133 | |
| 134 | private: |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 135 | SkBlendMode fMode; |
Brian Salomon | 3349c6f | 2017-03-01 09:49:58 -0500 | [diff] [blame] | 136 | SkString fName; |
reed@google.com | 2d078b6 | 2012-11-15 19:52:07 +0000 | [diff] [blame] | 137 | |
| 138 | typedef RectBench INHERITED; |
| 139 | }; |
| 140 | |
joshualitt | 8db65a6 | 2015-09-24 12:42:02 -0700 | [diff] [blame] | 141 | class TransparentRectBench : public RectBench { |
| 142 | public: |
| 143 | TransparentRectBench() : INHERITED(1, 0) {} |
| 144 | |
| 145 | protected: |
| 146 | void setupPaint(SkPaint* paint) override { |
| 147 | this->INHERITED::setupPaint(paint); |
| 148 | // draw non opaque rect |
| 149 | paint->setAlpha(0x80); |
| 150 | } |
| 151 | |
| 152 | const char* onGetName() override { |
| 153 | fName.set(this->INHERITED::onGetName()); |
| 154 | fName.prepend("transparent_"); |
| 155 | return fName.c_str(); |
| 156 | } |
| 157 | |
| 158 | private: |
Brian Salomon | 3349c6f | 2017-03-01 09:49:58 -0500 | [diff] [blame] | 159 | SkString fName; |
joshualitt | 8db65a6 | 2015-09-24 12:42:02 -0700 | [diff] [blame] | 160 | typedef RectBench INHERITED; |
| 161 | }; |
| 162 | |
Michael Ludwig | dde8b55 | 2018-11-20 14:58:23 -0500 | [diff] [blame] | 163 | // Adds a shader to the paint that requires local coordinates to be used |
| 164 | class LocalCoordsRectBench : public RectBench { |
| 165 | public: |
| 166 | LocalCoordsRectBench(bool aa, bool perspective = false) : INHERITED(1, 0, aa, perspective) { } |
| 167 | |
| 168 | protected: |
| 169 | void onDelayedSetup() override { |
| 170 | this->INHERITED::onDelayedSetup(); |
| 171 | // Create the shader once, so that isn't included in the timing |
| 172 | SkPoint pts[2] = { {0.f, 0.f}, {50.f, 50.f} }; |
| 173 | SkColor colors[] = { SK_ColorWHITE, SK_ColorBLUE }; |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 174 | fShader = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp); |
Michael Ludwig | dde8b55 | 2018-11-20 14:58:23 -0500 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | void setupPaint(SkPaint* paint) override { |
| 178 | this->INHERITED::setupPaint(paint); |
| 179 | paint->setShader(fShader); |
| 180 | } |
| 181 | |
| 182 | const char* onGetName() override { |
| 183 | fName.set(this->INHERITED::onGetName()); |
| 184 | fName.append("_localcoords"); |
| 185 | return fName.c_str(); |
| 186 | } |
| 187 | |
| 188 | private: |
| 189 | SkString fName; |
| 190 | sk_sp<SkShader> fShader; |
| 191 | |
| 192 | typedef RectBench INHERITED; |
| 193 | }; |
| 194 | |
joshualitt | 8db65a6 | 2015-09-24 12:42:02 -0700 | [diff] [blame] | 195 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 196 | class OvalBench : public RectBench { |
reed@android.com | d2c3744 | 2009-01-08 03:00:57 +0000 | [diff] [blame] | 197 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 198 | OvalBench(int shift, int stroke = 0) : RectBench(shift, stroke) {} |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 199 | protected: |
reed | 57b7671 | 2015-09-25 04:49:43 -0700 | [diff] [blame] | 200 | void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) override { |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 201 | c->drawOval(r, p); |
| 202 | } |
reed | 57b7671 | 2015-09-25 04:49:43 -0700 | [diff] [blame] | 203 | const char* onGetName() override { return computeName("ovals"); } |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | class RRectBench : public RectBench { |
reed@android.com | d2c3744 | 2009-01-08 03:00:57 +0000 | [diff] [blame] | 207 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 208 | RRectBench(int shift, int stroke = 0) : RectBench(shift, stroke) {} |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 209 | protected: |
reed | 57b7671 | 2015-09-25 04:49:43 -0700 | [diff] [blame] | 210 | void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) override { |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 211 | c->drawRoundRect(r, r.width() / 4, r.height() / 4, p); |
| 212 | } |
reed | 57b7671 | 2015-09-25 04:49:43 -0700 | [diff] [blame] | 213 | const char* onGetName() override { return computeName("rrects"); } |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 214 | }; |
| 215 | |
| 216 | class PointsBench : public RectBench { |
| 217 | public: |
| 218 | SkCanvas::PointMode fMode; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 219 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 220 | PointsBench(SkCanvas::PointMode mode, const char* name) |
| 221 | : RectBench(2) |
| 222 | , fMode(mode) { |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 223 | fName = name; |
| 224 | } |
| 225 | |
| 226 | protected: |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 227 | void onDraw(int loops, SkCanvas* canvas) override { |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 228 | SkScalar gSizes[] = { |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 229 | SkIntToScalar(7), 0 |
| 230 | }; |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 231 | size_t sizes = SK_ARRAY_COUNT(gSizes); |
| 232 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 233 | if (FLAGS_strokeWidth >= 0) { |
mtklein@google.com | b87bf83 | 2013-09-10 19:51:10 +0000 | [diff] [blame] | 234 | gSizes[0] = (SkScalar)FLAGS_strokeWidth; |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 235 | sizes = 1; |
| 236 | } |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 237 | |
| 238 | SkPaint paint; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 239 | paint.setStrokeCap(SkPaint::kRound_Cap); |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 240 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 241 | for (int loop = 0; loop < loops; loop++) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 242 | for (size_t i = 0; i < sizes; i++) { |
| 243 | paint.setStrokeWidth(gSizes[i]); |
| 244 | this->setupPaint(&paint); |
Mike Klein | e72e773 | 2018-06-14 14:41:22 -0400 | [diff] [blame] | 245 | canvas->drawPoints(fMode, N * 2, reinterpret_cast<SkPoint*>(fRects), paint); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 246 | paint.setColor(fColors[i % N]); |
| 247 | } |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 248 | } |
| 249 | } |
Brian Salomon | dac5f6b | 2017-02-28 16:11:04 -0500 | [diff] [blame] | 250 | const char* onGetName() override { return fName.c_str(); } |
Brian Salomon | 3349c6f | 2017-03-01 09:49:58 -0500 | [diff] [blame] | 251 | |
| 252 | private: |
| 253 | SkString fName; |
| 254 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 255 | }; |
| 256 | |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 257 | /******************************************************************************* |
| 258 | * to bench BlitMask [Opaque, Black, color, shader] |
| 259 | *******************************************************************************/ |
| 260 | |
| 261 | class BlitMaskBench : public RectBench { |
| 262 | public: |
| 263 | enum kMaskType { |
| 264 | kMaskOpaque = 0, |
| 265 | kMaskBlack, |
| 266 | kMaskColor, |
| 267 | KMaskShader |
| 268 | }; |
| 269 | SkCanvas::PointMode fMode; |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 270 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 271 | BlitMaskBench(SkCanvas::PointMode mode, |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 272 | BlitMaskBench::kMaskType type, const char* name) : |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 273 | RectBench(2), fMode(mode), _type(type) { |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 274 | fName = name; |
| 275 | } |
| 276 | |
| 277 | protected: |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 278 | void onDraw(int loops, SkCanvas* canvas) override { |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 279 | SkScalar gSizes[] = { |
| 280 | SkIntToScalar(13), SkIntToScalar(24) |
| 281 | }; |
| 282 | size_t sizes = SK_ARRAY_COUNT(gSizes); |
| 283 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 284 | if (FLAGS_strokeWidth >= 0) { |
mtklein@google.com | b87bf83 | 2013-09-10 19:51:10 +0000 | [diff] [blame] | 285 | gSizes[0] = (SkScalar)FLAGS_strokeWidth; |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 286 | sizes = 1; |
| 287 | } |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 288 | SkRandom rand; |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 289 | SkColor color = 0xFF000000; |
| 290 | U8CPU alpha = 0xFF; |
| 291 | SkPaint paint; |
| 292 | paint.setStrokeCap(SkPaint::kRound_Cap); |
| 293 | if (_type == KMaskShader) { |
| 294 | SkBitmap srcBM; |
reed | 6c22573 | 2014-06-09 19:52:07 -0700 | [diff] [blame] | 295 | srcBM.allocN32Pixels(10, 1); |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 296 | srcBM.eraseColor(0xFF00FF00); |
| 297 | |
Mike Reed | 50acf8f | 2019-04-08 13:20:23 -0400 | [diff] [blame] | 298 | paint.setShader(srcBM.makeShader()); |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 299 | } |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 300 | for (int loop = 0; loop < loops; loop++) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 301 | for (size_t i = 0; i < sizes; i++) { |
| 302 | switch (_type) { |
| 303 | case kMaskOpaque: |
| 304 | color = fColors[i]; |
| 305 | alpha = 0xFF; |
| 306 | break; |
| 307 | case kMaskBlack: |
| 308 | alpha = 0xFF; |
| 309 | color = 0xFF000000; |
| 310 | break; |
| 311 | case kMaskColor: |
| 312 | color = fColors[i]; |
| 313 | alpha = rand.nextU() & 255; |
| 314 | break; |
| 315 | case KMaskShader: |
| 316 | break; |
| 317 | } |
| 318 | paint.setStrokeWidth(gSizes[i]); |
| 319 | this->setupPaint(&paint); |
| 320 | paint.setColor(color); |
| 321 | paint.setAlpha(alpha); |
Mike Klein | e72e773 | 2018-06-14 14:41:22 -0400 | [diff] [blame] | 322 | canvas->drawPoints(fMode, N * 2, reinterpret_cast<SkPoint*>(fRects), paint); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 323 | } |
| 324 | } |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 325 | } |
Brian Salomon | dac5f6b | 2017-02-28 16:11:04 -0500 | [diff] [blame] | 326 | const char* onGetName() override { return fName.c_str(); } |
Brian Salomon | 3349c6f | 2017-03-01 09:49:58 -0500 | [diff] [blame] | 327 | |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 328 | private: |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 329 | typedef RectBench INHERITED; |
| 330 | kMaskType _type; |
Brian Salomon | 3349c6f | 2017-03-01 09:49:58 -0500 | [diff] [blame] | 331 | SkString fName; |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 332 | }; |
| 333 | |
Michael Ludwig | dde8b55 | 2018-11-20 14:58:23 -0500 | [diff] [blame] | 334 | // AA rects |
| 335 | DEF_BENCH(return new RectBench(1, 0, true);) |
| 336 | DEF_BENCH(return new RectBench(1, 4, true);) |
| 337 | DEF_BENCH(return new RectBench(3, 0, true);) |
| 338 | DEF_BENCH(return new RectBench(3, 4, true);) |
| 339 | // Non-AA rects |
| 340 | DEF_BENCH(return new RectBench(1, 0, false);) |
| 341 | DEF_BENCH(return new RectBench(1, 4, false);) |
| 342 | DEF_BENCH(return new RectBench(3, 0, false);) |
| 343 | DEF_BENCH(return new RectBench(3, 4, false);) |
| 344 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 345 | DEF_BENCH(return new OvalBench(1);) |
| 346 | DEF_BENCH(return new OvalBench(3);) |
| 347 | DEF_BENCH(return new OvalBench(1, 4);) |
| 348 | DEF_BENCH(return new OvalBench(3, 4);) |
| 349 | DEF_BENCH(return new RRectBench(1);) |
| 350 | DEF_BENCH(return new RRectBench(1, 4);) |
| 351 | DEF_BENCH(return new RRectBench(3);) |
| 352 | DEF_BENCH(return new RRectBench(3, 4);) |
| 353 | DEF_BENCH(return new PointsBench(SkCanvas::kPoints_PointMode, "points");) |
| 354 | DEF_BENCH(return new PointsBench(SkCanvas::kLines_PointMode, "lines");) |
| 355 | DEF_BENCH(return new PointsBench(SkCanvas::kPolygon_PointMode, "polygon");) |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 356 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 357 | DEF_BENCH(return new SrcModeRectBench();) |
robertphillips@google.com | 370d835 | 2013-05-02 13:57:52 +0000 | [diff] [blame] | 358 | |
joshualitt | 8db65a6 | 2015-09-24 12:42:02 -0700 | [diff] [blame] | 359 | DEF_BENCH(return new TransparentRectBench();) |
| 360 | |
Michael Ludwig | dde8b55 | 2018-11-20 14:58:23 -0500 | [diff] [blame] | 361 | DEF_BENCH(return new LocalCoordsRectBench(true);) |
| 362 | DEF_BENCH(return new LocalCoordsRectBench(false);) |
| 363 | |
| 364 | // Perspective rects |
| 365 | DEF_BENCH(return new RectBench(1, 0, true, true);) |
| 366 | DEF_BENCH(return new RectBench(1, 0, false, true);) |
| 367 | DEF_BENCH(return new LocalCoordsRectBench(true, true);) |
| 368 | DEF_BENCH(return new LocalCoordsRectBench(false, true);) |
| 369 | |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 370 | /* init the blitmask bench |
| 371 | */ |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 372 | DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, |
| 373 | BlitMaskBench::kMaskOpaque, |
| 374 | "maskopaque");) |
| 375 | DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, |
| 376 | BlitMaskBench::kMaskBlack, |
| 377 | "maskblack");) |
| 378 | DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, |
| 379 | BlitMaskBench::kMaskColor, |
| 380 | "maskcolor");) |
| 381 | DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, |
| 382 | BlitMaskBench::KMaskShader, |
| 383 | "maskshader");) |