reed@google.com | 4aa1a70 | 2012-05-04 16:37:45 +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 | */ |
| 8 | #include "SkBenchmark.h" |
| 9 | #include "SkBitmap.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkDashPathEffect.h" |
| 12 | #include "SkPaint.h" |
| 13 | #include "SkPath.h" |
| 14 | #include "SkRandom.h" |
| 15 | #include "SkString.h" |
| 16 | #include "SkTDArray.h" |
| 17 | |
reed@google.com | ef85e3c | 2012-05-10 15:40:57 +0000 | [diff] [blame] | 18 | |
reed@google.com | 4aa1a70 | 2012-05-04 16:37:45 +0000 | [diff] [blame] | 19 | /* |
| 20 | * Cases to consider: |
| 21 | * |
| 22 | * 1. antialiasing on/off (esp. width <= 1) |
| 23 | * 2. strokewidth == 0, 1, 2 |
| 24 | * 3. hline, vline, diagonal, rect, oval |
| 25 | * 4. dots [1,1] ([N,N] where N=strokeWidth?) or arbitrary (e.g. [2,1] or [1,2,3,2]) |
| 26 | */ |
| 27 | static void path_hline(SkPath* path) { |
| 28 | path->moveTo(SkIntToScalar(10), SkIntToScalar(10)); |
| 29 | path->lineTo(SkIntToScalar(600), SkIntToScalar(10)); |
| 30 | } |
| 31 | |
| 32 | class DashBench : public SkBenchmark { |
reed@google.com | ef85e3c | 2012-05-10 15:40:57 +0000 | [diff] [blame] | 33 | protected: |
mike@reedtribe.org | 99a6ef4 | 2012-05-05 13:46:10 +0000 | [diff] [blame] | 34 | SkString fName; |
reed@google.com | 4aa1a70 | 2012-05-04 16:37:45 +0000 | [diff] [blame] | 35 | SkTDArray<SkScalar> fIntervals; |
mike@reedtribe.org | 99a6ef4 | 2012-05-05 13:46:10 +0000 | [diff] [blame] | 36 | int fWidth; |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 37 | SkPoint fPts[2]; |
| 38 | bool fDoClip; |
reed@google.com | 4aa1a70 | 2012-05-04 16:37:45 +0000 | [diff] [blame] | 39 | |
reed@google.com | 4aa1a70 | 2012-05-04 16:37:45 +0000 | [diff] [blame] | 40 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 41 | DashBench(const SkScalar intervals[], int count, int width, |
| 42 | bool doClip = false) { |
reed@google.com | 4aa1a70 | 2012-05-04 16:37:45 +0000 | [diff] [blame] | 43 | fIntervals.append(count, intervals); |
mike@reedtribe.org | 99a6ef4 | 2012-05-05 13:46:10 +0000 | [diff] [blame] | 44 | for (int i = 0; i < count; ++i) { |
| 45 | fIntervals[i] *= width; |
| 46 | } |
| 47 | fWidth = width; |
reed@google.com | 4ad2275 | 2012-05-15 19:50:58 +0000 | [diff] [blame] | 48 | fName.printf("dash_%d_%s", width, doClip ? "clipped" : "noclip"); |
| 49 | fDoClip = doClip; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 50 | |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 51 | fPts[0].set(SkIntToScalar(10), SkIntToScalar(10)); |
| 52 | fPts[1].set(SkIntToScalar(600), SkIntToScalar(10)); |
reed@google.com | 4aa1a70 | 2012-05-04 16:37:45 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | virtual void makePath(SkPath* path) { |
| 56 | path_hline(path); |
| 57 | } |
| 58 | |
| 59 | protected: |
| 60 | virtual const char* onGetName() SK_OVERRIDE { |
mike@reedtribe.org | 99a6ef4 | 2012-05-05 13:46:10 +0000 | [diff] [blame] | 61 | return fName.c_str(); |
reed@google.com | 4aa1a70 | 2012-05-04 16:37:45 +0000 | [diff] [blame] | 62 | } |
| 63 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 64 | virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
reed@google.com | 4aa1a70 | 2012-05-04 16:37:45 +0000 | [diff] [blame] | 65 | SkPaint paint; |
| 66 | this->setupPaint(&paint); |
| 67 | paint.setStyle(SkPaint::kStroke_Style); |
mike@reedtribe.org | 99a6ef4 | 2012-05-05 13:46:10 +0000 | [diff] [blame] | 68 | paint.setStrokeWidth(SkIntToScalar(fWidth)); |
reed@google.com | 4aa1a70 | 2012-05-04 16:37:45 +0000 | [diff] [blame] | 69 | paint.setAntiAlias(false); |
| 70 | |
| 71 | SkPath path; |
| 72 | this->makePath(&path); |
| 73 | |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 74 | paint.setPathEffect(SkDashPathEffect::Create(fIntervals.begin(), |
| 75 | fIntervals.count(), 0))->unref(); |
reed@google.com | 4ad2275 | 2012-05-15 19:50:58 +0000 | [diff] [blame] | 76 | |
| 77 | if (fDoClip) { |
| 78 | SkRect r = path.getBounds(); |
| 79 | r.inset(-SkIntToScalar(20), -SkIntToScalar(20)); |
| 80 | // now move it so we don't intersect |
| 81 | r.offset(0, r.height() * 3 / 2); |
| 82 | canvas->clipRect(r); |
| 83 | } |
| 84 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 85 | this->handlePath(canvas, path, paint, loops); |
reed@google.com | ef85e3c | 2012-05-10 15:40:57 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | virtual void handlePath(SkCanvas* canvas, const SkPath& path, |
| 89 | const SkPaint& paint, int N) { |
reed@google.com | 4aa1a70 | 2012-05-04 16:37:45 +0000 | [diff] [blame] | 90 | for (int i = 0; i < N; ++i) { |
reed@google.com | a584aed | 2012-05-16 14:06:02 +0000 | [diff] [blame] | 91 | // canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, paint); |
reed@google.com | 4aa1a70 | 2012-05-04 16:37:45 +0000 | [diff] [blame] | 92 | canvas->drawPath(path, paint); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | private: |
| 97 | typedef SkBenchmark INHERITED; |
| 98 | }; |
| 99 | |
reed@google.com | ef85e3c | 2012-05-10 15:40:57 +0000 | [diff] [blame] | 100 | class RectDashBench : public DashBench { |
| 101 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 102 | RectDashBench(const SkScalar intervals[], int count, int width) |
| 103 | : INHERITED(intervals, count, width) { |
reed@google.com | ef85e3c | 2012-05-10 15:40:57 +0000 | [diff] [blame] | 104 | fName.append("_rect"); |
| 105 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 106 | |
reed@google.com | ef85e3c | 2012-05-10 15:40:57 +0000 | [diff] [blame] | 107 | protected: |
| 108 | virtual void handlePath(SkCanvas* canvas, const SkPath& path, |
| 109 | const SkPaint& paint, int N) SK_OVERRIDE { |
| 110 | SkPoint pts[2]; |
| 111 | if (!path.isLine(pts) || pts[0].fY != pts[1].fY) { |
| 112 | this->INHERITED::handlePath(canvas, path, paint, N); |
| 113 | } else { |
| 114 | SkRect rect; |
| 115 | rect.fLeft = pts[0].fX; |
| 116 | rect.fTop = pts[0].fY - paint.getStrokeWidth() / 2; |
| 117 | rect.fRight = rect.fLeft + SkIntToScalar(fWidth); |
| 118 | rect.fBottom = rect.fTop + paint.getStrokeWidth(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 119 | |
reed@google.com | ef85e3c | 2012-05-10 15:40:57 +0000 | [diff] [blame] | 120 | SkPaint p(paint); |
| 121 | p.setStyle(SkPaint::kFill_Style); |
| 122 | p.setPathEffect(NULL); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 123 | |
reed@google.com | ef85e3c | 2012-05-10 15:40:57 +0000 | [diff] [blame] | 124 | int count = SkScalarRoundToInt((pts[1].fX - pts[0].fX) / (2*fWidth)); |
| 125 | SkScalar dx = SkIntToScalar(2 * fWidth); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 126 | |
reed@google.com | ef85e3c | 2012-05-10 15:40:57 +0000 | [diff] [blame] | 127 | for (int i = 0; i < N*10; ++i) { |
| 128 | SkRect r = rect; |
| 129 | for (int j = 0; j < count; ++j) { |
| 130 | canvas->drawRect(r, p); |
| 131 | r.offset(dx, 0); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 136 | |
reed@google.com | ef85e3c | 2012-05-10 15:40:57 +0000 | [diff] [blame] | 137 | private: |
| 138 | typedef DashBench INHERITED; |
| 139 | }; |
| 140 | |
reed@google.com | ea6f683 | 2012-05-18 18:32:54 +0000 | [diff] [blame] | 141 | static void make_unit_star(SkPath* path, int n) { |
| 142 | SkScalar rad = -SK_ScalarPI / 2; |
| 143 | const SkScalar drad = (n >> 1) * SK_ScalarPI * 2 / n; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 144 | |
reed@google.com | ea6f683 | 2012-05-18 18:32:54 +0000 | [diff] [blame] | 145 | path->moveTo(0, -SK_Scalar1); |
| 146 | for (int i = 1; i < n; i++) { |
| 147 | rad += drad; |
| 148 | SkScalar cosV, sinV = SkScalarSinCos(rad, &cosV); |
| 149 | path->lineTo(cosV, sinV); |
| 150 | } |
| 151 | path->close(); |
| 152 | } |
| 153 | |
| 154 | static void make_poly(SkPath* path) { |
| 155 | make_unit_star(path, 9); |
| 156 | SkMatrix matrix; |
| 157 | matrix.setScale(SkIntToScalar(100), SkIntToScalar(100)); |
| 158 | path->transform(matrix); |
| 159 | } |
| 160 | |
| 161 | static void make_quad(SkPath* path) { |
| 162 | SkScalar x0 = SkIntToScalar(10); |
| 163 | SkScalar y0 = SkIntToScalar(10); |
| 164 | path->moveTo(x0, y0); |
| 165 | path->quadTo(x0, y0 + 400 * SK_Scalar1, |
| 166 | x0 + 600 * SK_Scalar1, y0 + 400 * SK_Scalar1); |
| 167 | } |
| 168 | |
| 169 | static void make_cubic(SkPath* path) { |
| 170 | SkScalar x0 = SkIntToScalar(10); |
| 171 | SkScalar y0 = SkIntToScalar(10); |
| 172 | path->moveTo(x0, y0); |
| 173 | path->cubicTo(x0, y0 + 400 * SK_Scalar1, |
| 174 | x0 + 600 * SK_Scalar1, y0 + 400 * SK_Scalar1, |
| 175 | x0 + 600 * SK_Scalar1, y0); |
| 176 | } |
| 177 | |
| 178 | class MakeDashBench : public SkBenchmark { |
| 179 | SkString fName; |
| 180 | SkPath fPath; |
| 181 | SkAutoTUnref<SkPathEffect> fPE; |
skia.committer@gmail.com | 73bb3be | 2012-09-05 02:01:29 +0000 | [diff] [blame] | 182 | |
reed@google.com | ea6f683 | 2012-05-18 18:32:54 +0000 | [diff] [blame] | 183 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 184 | MakeDashBench(void (*proc)(SkPath*), const char name[]) { |
reed@google.com | ea6f683 | 2012-05-18 18:32:54 +0000 | [diff] [blame] | 185 | fName.printf("makedash_%s", name); |
| 186 | proc(&fPath); |
skia.committer@gmail.com | 73bb3be | 2012-09-05 02:01:29 +0000 | [diff] [blame] | 187 | |
reed@google.com | ea6f683 | 2012-05-18 18:32:54 +0000 | [diff] [blame] | 188 | SkScalar vals[] = { SkIntToScalar(4), SkIntToScalar(4) }; |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 189 | fPE.reset(SkDashPathEffect::Create(vals, 2, 0)); |
reed@google.com | ea6f683 | 2012-05-18 18:32:54 +0000 | [diff] [blame] | 190 | } |
skia.committer@gmail.com | 73bb3be | 2012-09-05 02:01:29 +0000 | [diff] [blame] | 191 | |
reed@google.com | ea6f683 | 2012-05-18 18:32:54 +0000 | [diff] [blame] | 192 | protected: |
| 193 | virtual const char* onGetName() SK_OVERRIDE { |
| 194 | return fName.c_str(); |
| 195 | } |
skia.committer@gmail.com | 73bb3be | 2012-09-05 02:01:29 +0000 | [diff] [blame] | 196 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 197 | virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { |
reed@google.com | ea6f683 | 2012-05-18 18:32:54 +0000 | [diff] [blame] | 198 | SkPath dst; |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 199 | for (int i = 0; i < loops; ++i) { |
reed@google.com | fd4be26 | 2012-05-25 01:04:12 +0000 | [diff] [blame] | 200 | SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle); |
skia.committer@gmail.com | 73bb3be | 2012-09-05 02:01:29 +0000 | [diff] [blame] | 201 | |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 202 | fPE->filterPath(&dst, fPath, &rec, NULL); |
reed@google.com | ea6f683 | 2012-05-18 18:32:54 +0000 | [diff] [blame] | 203 | dst.rewind(); |
| 204 | } |
| 205 | } |
skia.committer@gmail.com | 73bb3be | 2012-09-05 02:01:29 +0000 | [diff] [blame] | 206 | |
reed@google.com | 31e9d64 | 2012-09-04 20:07:23 +0000 | [diff] [blame] | 207 | private: |
| 208 | typedef SkBenchmark INHERITED; |
| 209 | }; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 210 | |
reed@google.com | 5125d84 | 2012-09-04 20:19:35 +0000 | [diff] [blame] | 211 | /* |
| 212 | * We try to special case square dashes (intervals are equal to strokewidth). |
| 213 | */ |
reed@google.com | 31e9d64 | 2012-09-04 20:07:23 +0000 | [diff] [blame] | 214 | class DashLineBench : public SkBenchmark { |
| 215 | SkString fName; |
reed@google.com | 5125d84 | 2012-09-04 20:19:35 +0000 | [diff] [blame] | 216 | SkScalar fStrokeWidth; |
| 217 | bool fIsRound; |
reed@google.com | 31e9d64 | 2012-09-04 20:07:23 +0000 | [diff] [blame] | 218 | SkAutoTUnref<SkPathEffect> fPE; |
skia.committer@gmail.com | 73bb3be | 2012-09-05 02:01:29 +0000 | [diff] [blame] | 219 | |
reed@google.com | 31e9d64 | 2012-09-04 20:07:23 +0000 | [diff] [blame] | 220 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 221 | DashLineBench(SkScalar width, bool isRound) { |
reed@google.com | 5125d84 | 2012-09-04 20:19:35 +0000 | [diff] [blame] | 222 | fName.printf("dashline_%g_%s", SkScalarToFloat(width), isRound ? "circle" : "square"); |
| 223 | fStrokeWidth = width; |
| 224 | fIsRound = isRound; |
skia.committer@gmail.com | 73bb3be | 2012-09-05 02:01:29 +0000 | [diff] [blame] | 225 | |
reed@google.com | 5125d84 | 2012-09-04 20:19:35 +0000 | [diff] [blame] | 226 | SkScalar vals[] = { SK_Scalar1, SK_Scalar1 }; |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 227 | fPE.reset(SkDashPathEffect::Create(vals, 2, 0)); |
reed@google.com | 31e9d64 | 2012-09-04 20:07:23 +0000 | [diff] [blame] | 228 | } |
skia.committer@gmail.com | 73bb3be | 2012-09-05 02:01:29 +0000 | [diff] [blame] | 229 | |
reed@google.com | 31e9d64 | 2012-09-04 20:07:23 +0000 | [diff] [blame] | 230 | protected: |
| 231 | virtual const char* onGetName() SK_OVERRIDE { |
| 232 | return fName.c_str(); |
| 233 | } |
skia.committer@gmail.com | 73bb3be | 2012-09-05 02:01:29 +0000 | [diff] [blame] | 234 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 235 | virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
reed@google.com | 31e9d64 | 2012-09-04 20:07:23 +0000 | [diff] [blame] | 236 | SkPaint paint; |
| 237 | this->setupPaint(&paint); |
reed@google.com | 5125d84 | 2012-09-04 20:19:35 +0000 | [diff] [blame] | 238 | paint.setStrokeWidth(fStrokeWidth); |
| 239 | paint.setStrokeCap(fIsRound ? SkPaint::kRound_Cap : SkPaint::kSquare_Cap); |
reed@google.com | 31e9d64 | 2012-09-04 20:07:23 +0000 | [diff] [blame] | 240 | paint.setPathEffect(fPE); |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 241 | for (int i = 0; i < loops; ++i) { |
reed@google.com | 5125d84 | 2012-09-04 20:19:35 +0000 | [diff] [blame] | 242 | canvas->drawLine(10 * SK_Scalar1, 10 * SK_Scalar1, |
| 243 | 640 * SK_Scalar1, 10 * SK_Scalar1, paint); |
reed@google.com | 31e9d64 | 2012-09-04 20:07:23 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
skia.committer@gmail.com | 73bb3be | 2012-09-05 02:01:29 +0000 | [diff] [blame] | 246 | |
reed@google.com | ea6f683 | 2012-05-18 18:32:54 +0000 | [diff] [blame] | 247 | private: |
| 248 | typedef SkBenchmark INHERITED; |
| 249 | }; |
| 250 | |
robertphillips@google.com | 935ad02 | 2012-12-05 19:07:21 +0000 | [diff] [blame] | 251 | class DrawPointsDashingBench : public SkBenchmark { |
| 252 | SkString fName; |
| 253 | int fStrokeWidth; |
robertphillips@google.com | ca47aae | 2012-12-12 15:58:25 +0000 | [diff] [blame] | 254 | bool fDoAA; |
robertphillips@google.com | 935ad02 | 2012-12-05 19:07:21 +0000 | [diff] [blame] | 255 | |
| 256 | SkAutoTUnref<SkPathEffect> fPathEffect; |
| 257 | |
robertphillips@google.com | 935ad02 | 2012-12-05 19:07:21 +0000 | [diff] [blame] | 258 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 259 | DrawPointsDashingBench(int dashLength, int strokeWidth, bool doAA) |
| 260 | { |
robertphillips@google.com | 935ad02 | 2012-12-05 19:07:21 +0000 | [diff] [blame] | 261 | fName.printf("drawpointsdash_%d_%d%s", dashLength, strokeWidth, doAA ? "_aa" : "_bw"); |
| 262 | fStrokeWidth = strokeWidth; |
robertphillips@google.com | ca47aae | 2012-12-12 15:58:25 +0000 | [diff] [blame] | 263 | fDoAA = doAA; |
robertphillips@google.com | 935ad02 | 2012-12-05 19:07:21 +0000 | [diff] [blame] | 264 | |
| 265 | SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength) }; |
commit-bot@chromium.org | 35c03fb | 2014-03-31 18:52:51 +0000 | [diff] [blame] | 266 | fPathEffect.reset(SkDashPathEffect::Create(vals, 2, SK_Scalar1)); |
robertphillips@google.com | 935ad02 | 2012-12-05 19:07:21 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | protected: |
| 270 | virtual const char* onGetName() SK_OVERRIDE { |
| 271 | return fName.c_str(); |
| 272 | } |
| 273 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 274 | virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
robertphillips@google.com | 935ad02 | 2012-12-05 19:07:21 +0000 | [diff] [blame] | 275 | SkPaint p; |
| 276 | this->setupPaint(&p); |
| 277 | p.setColor(SK_ColorBLACK); |
| 278 | p.setStyle(SkPaint::kStroke_Style); |
| 279 | p.setStrokeWidth(SkIntToScalar(fStrokeWidth)); |
| 280 | p.setPathEffect(fPathEffect); |
robertphillips@google.com | ca47aae | 2012-12-12 15:58:25 +0000 | [diff] [blame] | 281 | p.setAntiAlias(fDoAA); |
robertphillips@google.com | 935ad02 | 2012-12-05 19:07:21 +0000 | [diff] [blame] | 282 | |
| 283 | SkPoint pts[2] = { |
| 284 | { SkIntToScalar(10), 0 }, |
| 285 | { SkIntToScalar(640), 0 } |
| 286 | }; |
| 287 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 288 | for (int i = 0; i < loops; ++i) { |
robertphillips@google.com | 935ad02 | 2012-12-05 19:07:21 +0000 | [diff] [blame] | 289 | pts[0].fY = pts[1].fY = SkIntToScalar(i % 480); |
| 290 | canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | private: |
| 295 | typedef SkBenchmark INHERITED; |
| 296 | }; |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 297 | |
reed@google.com | e5ceea9 | 2013-01-24 17:33:21 +0000 | [diff] [blame] | 298 | // Want to test how we handle dashing when 99% of the dash is clipped out |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 299 | class GiantDashBench : public SkBenchmark { |
| 300 | SkString fName; |
reed@google.com | e5ceea9 | 2013-01-24 17:33:21 +0000 | [diff] [blame] | 301 | SkScalar fStrokeWidth; |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 302 | SkPoint fPts[2]; |
| 303 | SkAutoTUnref<SkPathEffect> fPathEffect; |
skia.committer@gmail.com | 4024f32 | 2013-01-25 07:06:46 +0000 | [diff] [blame] | 304 | |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 305 | public: |
| 306 | enum LineType { |
| 307 | kHori_LineType, |
| 308 | kVert_LineType, |
commit-bot@chromium.org | 5d7ca95 | 2013-04-22 20:26:44 +0000 | [diff] [blame] | 309 | kDiag_LineType, |
| 310 | kLineTypeCount |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 311 | }; |
| 312 | |
| 313 | static const char* LineTypeName(LineType lt) { |
| 314 | static const char* gNames[] = { "hori", "vert", "diag" }; |
commit-bot@chromium.org | 5d7ca95 | 2013-04-22 20:26:44 +0000 | [diff] [blame] | 315 | SK_COMPILE_ASSERT(kLineTypeCount == SK_ARRAY_COUNT(gNames), names_wrong_size); |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 316 | return gNames[lt]; |
| 317 | } |
| 318 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 319 | GiantDashBench(LineType lt, SkScalar width) { |
reed@google.com | e5ceea9 | 2013-01-24 17:33:21 +0000 | [diff] [blame] | 320 | fName.printf("giantdashline_%s_%g", LineTypeName(lt), width); |
| 321 | fStrokeWidth = width; |
| 322 | |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 323 | // deliberately pick intervals that won't be caught by asPoints(), so |
| 324 | // we can test the filterPath code-path. |
commit-bot@chromium.org | ae4976c | 2014-05-01 15:30:52 +0000 | [diff] [blame] | 325 | const SkScalar intervals[] = { 20, 10, 10, 10 }; |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 326 | fPathEffect.reset(SkDashPathEffect::Create(intervals, |
| 327 | SK_ARRAY_COUNT(intervals), 0)); |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 328 | |
| 329 | SkScalar cx = 640 / 2; // center X |
| 330 | SkScalar cy = 480 / 2; // center Y |
| 331 | SkMatrix matrix; |
skia.committer@gmail.com | 4024f32 | 2013-01-25 07:06:46 +0000 | [diff] [blame] | 332 | |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 333 | switch (lt) { |
| 334 | case kHori_LineType: |
| 335 | matrix.setIdentity(); |
| 336 | break; |
| 337 | case kVert_LineType: |
| 338 | matrix.setRotate(90, cx, cy); |
| 339 | break; |
| 340 | case kDiag_LineType: |
| 341 | matrix.setRotate(45, cx, cy); |
| 342 | break; |
commit-bot@chromium.org | 5d7ca95 | 2013-04-22 20:26:44 +0000 | [diff] [blame] | 343 | case kLineTypeCount: |
| 344 | // Not a real enum value. |
| 345 | break; |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 346 | } |
skia.committer@gmail.com | 4024f32 | 2013-01-25 07:06:46 +0000 | [diff] [blame] | 347 | |
reed@google.com | e5ceea9 | 2013-01-24 17:33:21 +0000 | [diff] [blame] | 348 | const SkScalar overshoot = 100*1000; |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 349 | const SkPoint pts[2] = { |
| 350 | { -overshoot, cy }, { 640 + overshoot, cy } |
| 351 | }; |
| 352 | matrix.mapPoints(fPts, pts, 2); |
| 353 | } |
skia.committer@gmail.com | 4024f32 | 2013-01-25 07:06:46 +0000 | [diff] [blame] | 354 | |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 355 | protected: |
| 356 | virtual const char* onGetName() SK_OVERRIDE { |
| 357 | return fName.c_str(); |
| 358 | } |
skia.committer@gmail.com | 4024f32 | 2013-01-25 07:06:46 +0000 | [diff] [blame] | 359 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 360 | virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 361 | SkPaint p; |
| 362 | this->setupPaint(&p); |
| 363 | p.setStyle(SkPaint::kStroke_Style); |
reed@google.com | e5ceea9 | 2013-01-24 17:33:21 +0000 | [diff] [blame] | 364 | p.setStrokeWidth(fStrokeWidth); |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 365 | p.setPathEffect(fPathEffect); |
| 366 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 367 | for (int i = 0; i < loops; i++) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 368 | canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, p); |
| 369 | } |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 370 | } |
skia.committer@gmail.com | 4024f32 | 2013-01-25 07:06:46 +0000 | [diff] [blame] | 371 | |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 372 | private: |
| 373 | typedef SkBenchmark INHERITED; |
| 374 | }; |
| 375 | |
| 376 | |
reed@google.com | 4aa1a70 | 2012-05-04 16:37:45 +0000 | [diff] [blame] | 377 | /////////////////////////////////////////////////////////////////////////////// |
| 378 | |
| 379 | static const SkScalar gDots[] = { SK_Scalar1, SK_Scalar1 }; |
| 380 | |
| 381 | #define PARAM(array) array, SK_ARRAY_COUNT(array) |
| 382 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 383 | DEF_BENCH( return new DashBench(PARAM(gDots), 0); ) |
| 384 | DEF_BENCH( return new DashBench(PARAM(gDots), 1); ) |
| 385 | DEF_BENCH( return new DashBench(PARAM(gDots), 1, true); ) |
| 386 | DEF_BENCH( return new DashBench(PARAM(gDots), 4); ) |
| 387 | DEF_BENCH( return new MakeDashBench(make_poly, "poly"); ) |
| 388 | DEF_BENCH( return new MakeDashBench(make_quad, "quad"); ) |
| 389 | DEF_BENCH( return new MakeDashBench(make_cubic, "cubic"); ) |
| 390 | DEF_BENCH( return new DashLineBench(0, false); ) |
| 391 | DEF_BENCH( return new DashLineBench(SK_Scalar1, false); ) |
| 392 | DEF_BENCH( return new DashLineBench(2 * SK_Scalar1, false); ) |
| 393 | DEF_BENCH( return new DashLineBench(0, true); ) |
| 394 | DEF_BENCH( return new DashLineBench(SK_Scalar1, true); ) |
| 395 | DEF_BENCH( return new DashLineBench(2 * SK_Scalar1, true); ) |
reed@google.com | 4aa1a70 | 2012-05-04 16:37:45 +0000 | [diff] [blame] | 396 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 397 | DEF_BENCH( return new DrawPointsDashingBench(1, 1, false); ) |
| 398 | DEF_BENCH( return new DrawPointsDashingBench(1, 1, true); ) |
| 399 | DEF_BENCH( return new DrawPointsDashingBench(3, 1, false); ) |
| 400 | DEF_BENCH( return new DrawPointsDashingBench(3, 1, true); ) |
| 401 | DEF_BENCH( return new DrawPointsDashingBench(5, 5, false); ) |
| 402 | DEF_BENCH( return new DrawPointsDashingBench(5, 5, true); ) |
reed@google.com | 996f64f | 2013-01-24 17:17:28 +0000 | [diff] [blame] | 403 | |
djsollen@google.com | 69feaca | 2013-07-18 17:22:30 +0000 | [diff] [blame] | 404 | /* Disable the GiantDashBench for Android devices until we can better control |
| 405 | * the memory usage. (https://code.google.com/p/skia/issues/detail?id=1430) |
| 406 | */ |
| 407 | #ifndef SK_BUILD_FOR_ANDROID |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 408 | DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 0); ) |
| 409 | DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 0); ) |
| 410 | DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 0); ) |
reed@google.com | e5ceea9 | 2013-01-24 17:33:21 +0000 | [diff] [blame] | 411 | |
| 412 | // pass 2 to explicitly avoid any 1-is-the-same-as-hairline special casing |
| 413 | |
| 414 | // hori_2 is just too slow to enable at the moment |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 415 | DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 2); ) |
| 416 | DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 2); ) |
| 417 | DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 2); ) |
djsollen@google.com | 69feaca | 2013-07-18 17:22:30 +0000 | [diff] [blame] | 418 | #endif |