| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 virtual void makePath(SkPath* path) { | 55 virtual void makePath(SkPath* path) { |
| 56 path_hline(path); | 56 path_hline(path); |
| 57 } | 57 } |
| 58 | 58 |
| 59 protected: | 59 protected: |
| 60 virtual const char* onGetName() SK_OVERRIDE { | 60 virtual const char* onGetName() SK_OVERRIDE { |
| 61 return fName.c_str(); | 61 return fName.c_str(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 64 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 65 SkPaint paint; | 65 SkPaint paint; |
| 66 this->setupPaint(&paint); | 66 this->setupPaint(&paint); |
| 67 paint.setStyle(SkPaint::kStroke_Style); | 67 paint.setStyle(SkPaint::kStroke_Style); |
| 68 paint.setStrokeWidth(SkIntToScalar(fWidth)); | 68 paint.setStrokeWidth(SkIntToScalar(fWidth)); |
| 69 paint.setAntiAlias(false); | 69 paint.setAntiAlias(false); |
| 70 | 70 |
| 71 SkPath path; | 71 SkPath path; |
| 72 this->makePath(&path); | 72 this->makePath(&path); |
| 73 | 73 |
| 74 paint.setPathEffect(new SkDashPathEffect(fIntervals.begin(), | 74 paint.setPathEffect(new SkDashPathEffect(fIntervals.begin(), |
| 75 fIntervals.count(), 0))->unref(
); | 75 fIntervals.count(), 0))->unref(
); |
| 76 | 76 |
| 77 if (fDoClip) { | 77 if (fDoClip) { |
| 78 SkRect r = path.getBounds(); | 78 SkRect r = path.getBounds(); |
| 79 r.inset(-SkIntToScalar(20), -SkIntToScalar(20)); | 79 r.inset(-SkIntToScalar(20), -SkIntToScalar(20)); |
| 80 // now move it so we don't intersect | 80 // now move it so we don't intersect |
| 81 r.offset(0, r.height() * 3 / 2); | 81 r.offset(0, r.height() * 3 / 2); |
| 82 canvas->clipRect(r); | 82 canvas->clipRect(r); |
| 83 } | 83 } |
| 84 | 84 |
| 85 this->handlePath(canvas, path, paint, this->getLoops()); | 85 this->handlePath(canvas, path, paint, loops); |
| 86 } | 86 } |
| 87 | 87 |
| 88 virtual void handlePath(SkCanvas* canvas, const SkPath& path, | 88 virtual void handlePath(SkCanvas* canvas, const SkPath& path, |
| 89 const SkPaint& paint, int N) { | 89 const SkPaint& paint, int N) { |
| 90 for (int i = 0; i < N; ++i) { | 90 for (int i = 0; i < N; ++i) { |
| 91 // canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, paint); | 91 // canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, paint); |
| 92 canvas->drawPath(path, paint); | 92 canvas->drawPath(path, paint); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 187 |
| 188 SkScalar vals[] = { SkIntToScalar(4), SkIntToScalar(4) }; | 188 SkScalar vals[] = { SkIntToScalar(4), SkIntToScalar(4) }; |
| 189 fPE.reset(new SkDashPathEffect(vals, 2, 0)); | 189 fPE.reset(new SkDashPathEffect(vals, 2, 0)); |
| 190 } | 190 } |
| 191 | 191 |
| 192 protected: | 192 protected: |
| 193 virtual const char* onGetName() SK_OVERRIDE { | 193 virtual const char* onGetName() SK_OVERRIDE { |
| 194 return fName.c_str(); | 194 return fName.c_str(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 virtual void onDraw(SkCanvas*) SK_OVERRIDE { | 197 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { |
| 198 SkPath dst; | 198 SkPath dst; |
| 199 for (int i = 0; i < this->getLoops(); ++i) { | 199 for (int i = 0; i < loops; ++i) { |
| 200 SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle); | 200 SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle); |
| 201 | 201 |
| 202 fPE->filterPath(&dst, fPath, &rec, NULL); | 202 fPE->filterPath(&dst, fPath, &rec, NULL); |
| 203 dst.rewind(); | 203 dst.rewind(); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 private: | 207 private: |
| 208 typedef SkBenchmark INHERITED; | 208 typedef SkBenchmark INHERITED; |
| 209 }; | 209 }; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 225 | 225 |
| 226 SkScalar vals[] = { SK_Scalar1, SK_Scalar1 }; | 226 SkScalar vals[] = { SK_Scalar1, SK_Scalar1 }; |
| 227 fPE.reset(new SkDashPathEffect(vals, 2, 0)); | 227 fPE.reset(new SkDashPathEffect(vals, 2, 0)); |
| 228 } | 228 } |
| 229 | 229 |
| 230 protected: | 230 protected: |
| 231 virtual const char* onGetName() SK_OVERRIDE { | 231 virtual const char* onGetName() SK_OVERRIDE { |
| 232 return fName.c_str(); | 232 return fName.c_str(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 235 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 236 SkPaint paint; | 236 SkPaint paint; |
| 237 this->setupPaint(&paint); | 237 this->setupPaint(&paint); |
| 238 paint.setStrokeWidth(fStrokeWidth); | 238 paint.setStrokeWidth(fStrokeWidth); |
| 239 paint.setStrokeCap(fIsRound ? SkPaint::kRound_Cap : SkPaint::kSquare_Cap
); | 239 paint.setStrokeCap(fIsRound ? SkPaint::kRound_Cap : SkPaint::kSquare_Cap
); |
| 240 paint.setPathEffect(fPE); | 240 paint.setPathEffect(fPE); |
| 241 for (int i = 0; i < this->getLoops(); ++i) { | 241 for (int i = 0; i < loops; ++i) { |
| 242 canvas->drawLine(10 * SK_Scalar1, 10 * SK_Scalar1, | 242 canvas->drawLine(10 * SK_Scalar1, 10 * SK_Scalar1, |
| 243 640 * SK_Scalar1, 10 * SK_Scalar1, paint); | 243 640 * SK_Scalar1, 10 * SK_Scalar1, paint); |
| 244 } | 244 } |
| 245 } | 245 } |
| 246 | 246 |
| 247 private: | 247 private: |
| 248 typedef SkBenchmark INHERITED; | 248 typedef SkBenchmark INHERITED; |
| 249 }; | 249 }; |
| 250 | 250 |
| 251 class DrawPointsDashingBench : public SkBenchmark { | 251 class DrawPointsDashingBench : public SkBenchmark { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 264 | 264 |
| 265 SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength)
}; | 265 SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength)
}; |
| 266 fPathEffect.reset(new SkDashPathEffect(vals, 2, SK_Scalar1, false)); | 266 fPathEffect.reset(new SkDashPathEffect(vals, 2, SK_Scalar1, false)); |
| 267 } | 267 } |
| 268 | 268 |
| 269 protected: | 269 protected: |
| 270 virtual const char* onGetName() SK_OVERRIDE { | 270 virtual const char* onGetName() SK_OVERRIDE { |
| 271 return fName.c_str(); | 271 return fName.c_str(); |
| 272 } | 272 } |
| 273 | 273 |
| 274 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 274 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 275 SkPaint p; | 275 SkPaint p; |
| 276 this->setupPaint(&p); | 276 this->setupPaint(&p); |
| 277 p.setColor(SK_ColorBLACK); | 277 p.setColor(SK_ColorBLACK); |
| 278 p.setStyle(SkPaint::kStroke_Style); | 278 p.setStyle(SkPaint::kStroke_Style); |
| 279 p.setStrokeWidth(SkIntToScalar(fStrokeWidth)); | 279 p.setStrokeWidth(SkIntToScalar(fStrokeWidth)); |
| 280 p.setPathEffect(fPathEffect); | 280 p.setPathEffect(fPathEffect); |
| 281 p.setAntiAlias(fDoAA); | 281 p.setAntiAlias(fDoAA); |
| 282 | 282 |
| 283 SkPoint pts[2] = { | 283 SkPoint pts[2] = { |
| 284 { SkIntToScalar(10), 0 }, | 284 { SkIntToScalar(10), 0 }, |
| 285 { SkIntToScalar(640), 0 } | 285 { SkIntToScalar(640), 0 } |
| 286 }; | 286 }; |
| 287 | 287 |
| 288 for (int i = 0; i < this->getLoops(); ++i) { | 288 for (int i = 0; i < loops; ++i) { |
| 289 pts[0].fY = pts[1].fY = SkIntToScalar(i % 480); | 289 pts[0].fY = pts[1].fY = SkIntToScalar(i % 480); |
| 290 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p); | 290 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p); |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 | 293 |
| 294 private: | 294 private: |
| 295 typedef SkBenchmark INHERITED; | 295 typedef SkBenchmark INHERITED; |
| 296 }; | 296 }; |
| 297 | 297 |
| 298 // Want to test how we handle dashing when 99% of the dash is clipped out | 298 // Want to test how we handle dashing when 99% of the dash is clipped out |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 { -overshoot, cy }, { 640 + overshoot, cy } | 350 { -overshoot, cy }, { 640 + overshoot, cy } |
| 351 }; | 351 }; |
| 352 matrix.mapPoints(fPts, pts, 2); | 352 matrix.mapPoints(fPts, pts, 2); |
| 353 } | 353 } |
| 354 | 354 |
| 355 protected: | 355 protected: |
| 356 virtual const char* onGetName() SK_OVERRIDE { | 356 virtual const char* onGetName() SK_OVERRIDE { |
| 357 return fName.c_str(); | 357 return fName.c_str(); |
| 358 } | 358 } |
| 359 | 359 |
| 360 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 360 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 361 SkPaint p; | 361 SkPaint p; |
| 362 this->setupPaint(&p); | 362 this->setupPaint(&p); |
| 363 p.setStyle(SkPaint::kStroke_Style); | 363 p.setStyle(SkPaint::kStroke_Style); |
| 364 p.setStrokeWidth(fStrokeWidth); | 364 p.setStrokeWidth(fStrokeWidth); |
| 365 p.setPathEffect(fPathEffect); | 365 p.setPathEffect(fPathEffect); |
| 366 | 366 |
| 367 for (int i = 0; i < this->getLoops(); i++) { | 367 for (int i = 0; i < loops; i++) { |
| 368 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, p); | 368 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, fPts, p); |
| 369 } | 369 } |
| 370 } | 370 } |
| 371 | 371 |
| 372 private: | 372 private: |
| 373 typedef SkBenchmark INHERITED; | 373 typedef SkBenchmark INHERITED; |
| 374 }; | 374 }; |
| 375 | 375 |
| 376 | 376 |
| 377 /////////////////////////////////////////////////////////////////////////////// | 377 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 0); ) | 409 DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 0); ) |
| 410 DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 0); ) | 410 DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 0); ) |
| 411 | 411 |
| 412 // pass 2 to explicitly avoid any 1-is-the-same-as-hairline special casing | 412 // pass 2 to explicitly avoid any 1-is-the-same-as-hairline special casing |
| 413 | 413 |
| 414 // hori_2 is just too slow to enable at the moment | 414 // hori_2 is just too slow to enable at the moment |
| 415 DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 2); ) | 415 DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 2); ) |
| 416 DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 2); ) | 416 DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 2); ) |
| 417 DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 2); ) | 417 DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 2); ) |
| 418 #endif | 418 #endif |
| OLD | NEW |