| 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 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 class DashBench : public SkBenchmark { | 32 class DashBench : public SkBenchmark { |
| 33 protected: | 33 protected: |
| 34 SkString fName; | 34 SkString fName; |
| 35 SkTDArray<SkScalar> fIntervals; | 35 SkTDArray<SkScalar> fIntervals; |
| 36 int fWidth; | 36 int fWidth; |
| 37 SkPoint fPts[2]; | 37 SkPoint fPts[2]; |
| 38 bool fDoClip; | 38 bool fDoClip; |
| 39 | 39 |
| 40 public: | 40 public: |
| 41 DashBench(void* param, const SkScalar intervals[], int count, int width, | 41 DashBench(const SkScalar intervals[], int count, int width, |
| 42 bool doClip = false) : INHERITED(param) { | 42 bool doClip = false) { |
| 43 fIntervals.append(count, intervals); | 43 fIntervals.append(count, intervals); |
| 44 for (int i = 0; i < count; ++i) { | 44 for (int i = 0; i < count; ++i) { |
| 45 fIntervals[i] *= width; | 45 fIntervals[i] *= width; |
| 46 } | 46 } |
| 47 fWidth = width; | 47 fWidth = width; |
| 48 fName.printf("dash_%d_%s", width, doClip ? "clipped" : "noclip"); | 48 fName.printf("dash_%d_%s", width, doClip ? "clipped" : "noclip"); |
| 49 fDoClip = doClip; | 49 fDoClip = doClip; |
| 50 | 50 |
| 51 fPts[0].set(SkIntToScalar(10), SkIntToScalar(10)); | 51 fPts[0].set(SkIntToScalar(10), SkIntToScalar(10)); |
| 52 fPts[1].set(SkIntToScalar(600), SkIntToScalar(10)); | 52 fPts[1].set(SkIntToScalar(600), SkIntToScalar(10)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 canvas->drawPath(path, paint); | 92 canvas->drawPath(path, paint); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 private: | 96 private: |
| 97 typedef SkBenchmark INHERITED; | 97 typedef SkBenchmark INHERITED; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 class RectDashBench : public DashBench { | 100 class RectDashBench : public DashBench { |
| 101 public: | 101 public: |
| 102 RectDashBench(void* param, const SkScalar intervals[], int count, int width) | 102 RectDashBench(const SkScalar intervals[], int count, int width) |
| 103 : INHERITED(param, intervals, count, width) { | 103 : INHERITED(intervals, count, width) { |
| 104 fName.append("_rect"); | 104 fName.append("_rect"); |
| 105 } | 105 } |
| 106 | 106 |
| 107 protected: | 107 protected: |
| 108 virtual void handlePath(SkCanvas* canvas, const SkPath& path, | 108 virtual void handlePath(SkCanvas* canvas, const SkPath& path, |
| 109 const SkPaint& paint, int N) SK_OVERRIDE { | 109 const SkPaint& paint, int N) SK_OVERRIDE { |
| 110 SkPoint pts[2]; | 110 SkPoint pts[2]; |
| 111 if (!path.isLine(pts) || pts[0].fY != pts[1].fY) { | 111 if (!path.isLine(pts) || pts[0].fY != pts[1].fY) { |
| 112 this->INHERITED::handlePath(canvas, path, paint, N); | 112 this->INHERITED::handlePath(canvas, path, paint, N); |
| 113 } else { | 113 } else { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 x0 + 600 * SK_Scalar1, y0 + 400 * SK_Scalar1, | 174 x0 + 600 * SK_Scalar1, y0 + 400 * SK_Scalar1, |
| 175 x0 + 600 * SK_Scalar1, y0); | 175 x0 + 600 * SK_Scalar1, y0); |
| 176 } | 176 } |
| 177 | 177 |
| 178 class MakeDashBench : public SkBenchmark { | 178 class MakeDashBench : public SkBenchmark { |
| 179 SkString fName; | 179 SkString fName; |
| 180 SkPath fPath; | 180 SkPath fPath; |
| 181 SkAutoTUnref<SkPathEffect> fPE; | 181 SkAutoTUnref<SkPathEffect> fPE; |
| 182 | 182 |
| 183 public: | 183 public: |
| 184 MakeDashBench(void* param, void (*proc)(SkPath*), const char name[]) : INHER
ITED(param) { | 184 MakeDashBench(void (*proc)(SkPath*), const char name[]) { |
| 185 fName.printf("makedash_%s", name); | 185 fName.printf("makedash_%s", name); |
| 186 proc(&fPath); | 186 proc(&fPath); |
| 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(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 211 /* | 211 /* |
| 212 * We try to special case square dashes (intervals are equal to strokewidth). | 212 * We try to special case square dashes (intervals are equal to strokewidth). |
| 213 */ | 213 */ |
| 214 class DashLineBench : public SkBenchmark { | 214 class DashLineBench : public SkBenchmark { |
| 215 SkString fName; | 215 SkString fName; |
| 216 SkScalar fStrokeWidth; | 216 SkScalar fStrokeWidth; |
| 217 bool fIsRound; | 217 bool fIsRound; |
| 218 SkAutoTUnref<SkPathEffect> fPE; | 218 SkAutoTUnref<SkPathEffect> fPE; |
| 219 | 219 |
| 220 public: | 220 public: |
| 221 DashLineBench(void* param, SkScalar width, bool isRound) : INHERITED(param)
{ | 221 DashLineBench(SkScalar width, bool isRound) { |
| 222 fName.printf("dashline_%g_%s", SkScalarToFloat(width), isRound ? "circle
" : "square"); | 222 fName.printf("dashline_%g_%s", SkScalarToFloat(width), isRound ? "circle
" : "square"); |
| 223 fStrokeWidth = width; | 223 fStrokeWidth = width; |
| 224 fIsRound = isRound; | 224 fIsRound = isRound; |
| 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 { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 249 }; | 249 }; |
| 250 | 250 |
| 251 class DrawPointsDashingBench : public SkBenchmark { | 251 class DrawPointsDashingBench : public SkBenchmark { |
| 252 SkString fName; | 252 SkString fName; |
| 253 int fStrokeWidth; | 253 int fStrokeWidth; |
| 254 bool fDoAA; | 254 bool fDoAA; |
| 255 | 255 |
| 256 SkAutoTUnref<SkPathEffect> fPathEffect; | 256 SkAutoTUnref<SkPathEffect> fPathEffect; |
| 257 | 257 |
| 258 public: | 258 public: |
| 259 DrawPointsDashingBench(void* param, int dashLength, int strokeWidth, bool do
AA) | 259 DrawPointsDashingBench(int dashLength, int strokeWidth, bool doAA) |
| 260 : INHERITED(param) { | 260 { |
| 261 fName.printf("drawpointsdash_%d_%d%s", dashLength, strokeWidth, doAA ? "
_aa" : "_bw"); | 261 fName.printf("drawpointsdash_%d_%d%s", dashLength, strokeWidth, doAA ? "
_aa" : "_bw"); |
| 262 fStrokeWidth = strokeWidth; | 262 fStrokeWidth = strokeWidth; |
| 263 fDoAA = doAA; | 263 fDoAA = doAA; |
| 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 { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 kDiag_LineType, | 309 kDiag_LineType, |
| 310 kLineTypeCount | 310 kLineTypeCount |
| 311 }; | 311 }; |
| 312 | 312 |
| 313 static const char* LineTypeName(LineType lt) { | 313 static const char* LineTypeName(LineType lt) { |
| 314 static const char* gNames[] = { "hori", "vert", "diag" }; | 314 static const char* gNames[] = { "hori", "vert", "diag" }; |
| 315 SK_COMPILE_ASSERT(kLineTypeCount == SK_ARRAY_COUNT(gNames), names_wrong_
size); | 315 SK_COMPILE_ASSERT(kLineTypeCount == SK_ARRAY_COUNT(gNames), names_wrong_
size); |
| 316 return gNames[lt]; | 316 return gNames[lt]; |
| 317 } | 317 } |
| 318 | 318 |
| 319 GiantDashBench(void* param, LineType lt, SkScalar width) : INHERITED(param)
{ | 319 GiantDashBench(LineType lt, SkScalar width) { |
| 320 fName.printf("giantdashline_%s_%g", LineTypeName(lt), width); | 320 fName.printf("giantdashline_%s_%g", LineTypeName(lt), width); |
| 321 fStrokeWidth = width; | 321 fStrokeWidth = width; |
| 322 | 322 |
| 323 // deliberately pick intervals that won't be caught by asPoints(), so | 323 // deliberately pick intervals that won't be caught by asPoints(), so |
| 324 // we can test the filterPath code-path. | 324 // we can test the filterPath code-path. |
| 325 const SkScalar intervals[] = { 2, 1, 1, 1 }; | 325 const SkScalar intervals[] = { 2, 1, 1, 1 }; |
| 326 fPathEffect.reset(new SkDashPathEffect(intervals, | 326 fPathEffect.reset(new SkDashPathEffect(intervals, |
| 327 SK_ARRAY_COUNT(intervals), 0)); | 327 SK_ARRAY_COUNT(intervals), 0)); |
| 328 | 328 |
| 329 SkScalar cx = 640 / 2; // center X | 329 SkScalar cx = 640 / 2; // center X |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 typedef SkBenchmark INHERITED; | 373 typedef SkBenchmark INHERITED; |
| 374 }; | 374 }; |
| 375 | 375 |
| 376 | 376 |
| 377 /////////////////////////////////////////////////////////////////////////////// | 377 /////////////////////////////////////////////////////////////////////////////// |
| 378 | 378 |
| 379 static const SkScalar gDots[] = { SK_Scalar1, SK_Scalar1 }; | 379 static const SkScalar gDots[] = { SK_Scalar1, SK_Scalar1 }; |
| 380 | 380 |
| 381 #define PARAM(array) array, SK_ARRAY_COUNT(array) | 381 #define PARAM(array) array, SK_ARRAY_COUNT(array) |
| 382 | 382 |
| 383 DEF_BENCH( return new DashBench(p, PARAM(gDots), 0); ) | 383 DEF_BENCH( return new DashBench(PARAM(gDots), 0); ) |
| 384 DEF_BENCH( return new DashBench(p, PARAM(gDots), 1); ) | 384 DEF_BENCH( return new DashBench(PARAM(gDots), 1); ) |
| 385 DEF_BENCH( return new DashBench(p, PARAM(gDots), 1, true); ) | 385 DEF_BENCH( return new DashBench(PARAM(gDots), 1, true); ) |
| 386 DEF_BENCH( return new DashBench(p, PARAM(gDots), 4); ) | 386 DEF_BENCH( return new DashBench(PARAM(gDots), 4); ) |
| 387 DEF_BENCH( return new MakeDashBench(p, make_poly, "poly"); ) | 387 DEF_BENCH( return new MakeDashBench(make_poly, "poly"); ) |
| 388 DEF_BENCH( return new MakeDashBench(p, make_quad, "quad"); ) | 388 DEF_BENCH( return new MakeDashBench(make_quad, "quad"); ) |
| 389 DEF_BENCH( return new MakeDashBench(p, make_cubic, "cubic"); ) | 389 DEF_BENCH( return new MakeDashBench(make_cubic, "cubic"); ) |
| 390 DEF_BENCH( return new DashLineBench(p, 0, false); ) | 390 DEF_BENCH( return new DashLineBench(0, false); ) |
| 391 DEF_BENCH( return new DashLineBench(p, SK_Scalar1, false); ) | 391 DEF_BENCH( return new DashLineBench(SK_Scalar1, false); ) |
| 392 DEF_BENCH( return new DashLineBench(p, 2 * SK_Scalar1, false); ) | 392 DEF_BENCH( return new DashLineBench(2 * SK_Scalar1, false); ) |
| 393 DEF_BENCH( return new DashLineBench(p, 0, true); ) | 393 DEF_BENCH( return new DashLineBench(0, true); ) |
| 394 DEF_BENCH( return new DashLineBench(p, SK_Scalar1, true); ) | 394 DEF_BENCH( return new DashLineBench(SK_Scalar1, true); ) |
| 395 DEF_BENCH( return new DashLineBench(p, 2 * SK_Scalar1, true); ) | 395 DEF_BENCH( return new DashLineBench(2 * SK_Scalar1, true); ) |
| 396 | 396 |
| 397 DEF_BENCH( return new DrawPointsDashingBench(p, 1, 1, false); ) | 397 DEF_BENCH( return new DrawPointsDashingBench(1, 1, false); ) |
| 398 DEF_BENCH( return new DrawPointsDashingBench(p, 1, 1, true); ) | 398 DEF_BENCH( return new DrawPointsDashingBench(1, 1, true); ) |
| 399 DEF_BENCH( return new DrawPointsDashingBench(p, 3, 1, false); ) | 399 DEF_BENCH( return new DrawPointsDashingBench(3, 1, false); ) |
| 400 DEF_BENCH( return new DrawPointsDashingBench(p, 3, 1, true); ) | 400 DEF_BENCH( return new DrawPointsDashingBench(3, 1, true); ) |
| 401 DEF_BENCH( return new DrawPointsDashingBench(p, 5, 5, false); ) | 401 DEF_BENCH( return new DrawPointsDashingBench(5, 5, false); ) |
| 402 DEF_BENCH( return new DrawPointsDashingBench(p, 5, 5, true); ) | 402 DEF_BENCH( return new DrawPointsDashingBench(5, 5, true); ) |
| 403 | 403 |
| 404 /* Disable the GiantDashBench for Android devices until we can better control | 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) | 405 * the memory usage. (https://code.google.com/p/skia/issues/detail?id=1430) |
| 406 */ | 406 */ |
| 407 #ifndef SK_BUILD_FOR_ANDROID | 407 #ifndef SK_BUILD_FOR_ANDROID |
| 408 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kHori_LineType, 0); ) | 408 DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 0); ) |
| 409 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kVert_LineType, 0); ) | 409 DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 0); ) |
| 410 DEF_BENCH( return new GiantDashBench(p, 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(p, GiantDashBench::kHori_LineType, 2); ) | 415 DEF_BENCH( return new GiantDashBench(GiantDashBench::kHori_LineType, 2); ) |
| 416 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kVert_LineType, 2); ) | 416 DEF_BENCH( return new GiantDashBench(GiantDashBench::kVert_LineType, 2); ) |
| 417 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kDiag_LineType, 2); ) | 417 DEF_BENCH( return new GiantDashBench(GiantDashBench::kDiag_LineType, 2); ) |
| 418 #endif | 418 #endif |
| OLD | NEW |