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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 class GiantDashBench : public SkBenchmark { | 316 class GiantDashBench : public SkBenchmark { |
317 SkString fName; | 317 SkString fName; |
318 SkScalar fStrokeWidth; | 318 SkScalar fStrokeWidth; |
319 SkPoint fPts[2]; | 319 SkPoint fPts[2]; |
320 SkAutoTUnref<SkPathEffect> fPathEffect; | 320 SkAutoTUnref<SkPathEffect> fPathEffect; |
321 | 321 |
322 public: | 322 public: |
323 enum LineType { | 323 enum LineType { |
324 kHori_LineType, | 324 kHori_LineType, |
325 kVert_LineType, | 325 kVert_LineType, |
326 kDiag_LineType | 326 kDiag_LineType, |
| 327 kLineTypeCount |
327 }; | 328 }; |
328 | 329 |
329 static const char* LineTypeName(LineType lt) { | 330 static const char* LineTypeName(LineType lt) { |
330 static const char* gNames[] = { "hori", "vert", "diag" }; | 331 static const char* gNames[] = { "hori", "vert", "diag" }; |
331 SkASSERT((size_t)lt <= SK_ARRAY_COUNT(gNames)); | 332 SK_COMPILE_ASSERT(kLineTypeCount == SK_ARRAY_COUNT(gNames), names_wrong_
size); |
332 return gNames[lt]; | 333 return gNames[lt]; |
333 } | 334 } |
334 | 335 |
335 GiantDashBench(void* param, LineType lt, SkScalar width) : INHERITED(param)
{ | 336 GiantDashBench(void* param, LineType lt, SkScalar width) : INHERITED(param)
{ |
336 fName.printf("giantdashline_%s_%g", LineTypeName(lt), width); | 337 fName.printf("giantdashline_%s_%g", LineTypeName(lt), width); |
337 fStrokeWidth = width; | 338 fStrokeWidth = width; |
338 | 339 |
339 // deliberately pick intervals that won't be caught by asPoints(), so | 340 // deliberately pick intervals that won't be caught by asPoints(), so |
340 // we can test the filterPath code-path. | 341 // we can test the filterPath code-path. |
341 const SkScalar intervals[] = { 2, 1, 1, 1 }; | 342 const SkScalar intervals[] = { 2, 1, 1, 1 }; |
342 fPathEffect.reset(new SkDashPathEffect(intervals, | 343 fPathEffect.reset(new SkDashPathEffect(intervals, |
343 SK_ARRAY_COUNT(intervals), 0)); | 344 SK_ARRAY_COUNT(intervals), 0)); |
344 | 345 |
345 SkScalar cx = 640 / 2; // center X | 346 SkScalar cx = 640 / 2; // center X |
346 SkScalar cy = 480 / 2; // center Y | 347 SkScalar cy = 480 / 2; // center Y |
347 SkMatrix matrix; | 348 SkMatrix matrix; |
348 | 349 |
349 switch (lt) { | 350 switch (lt) { |
350 case kHori_LineType: | 351 case kHori_LineType: |
351 matrix.setIdentity(); | 352 matrix.setIdentity(); |
352 break; | 353 break; |
353 case kVert_LineType: | 354 case kVert_LineType: |
354 matrix.setRotate(90, cx, cy); | 355 matrix.setRotate(90, cx, cy); |
355 break; | 356 break; |
356 case kDiag_LineType: | 357 case kDiag_LineType: |
357 matrix.setRotate(45, cx, cy); | 358 matrix.setRotate(45, cx, cy); |
358 break; | 359 break; |
| 360 case kLineTypeCount: |
| 361 // Not a real enum value. |
| 362 break; |
359 } | 363 } |
360 | 364 |
361 const SkScalar overshoot = 100*1000; | 365 const SkScalar overshoot = 100*1000; |
362 const SkPoint pts[2] = { | 366 const SkPoint pts[2] = { |
363 { -overshoot, cy }, { 640 + overshoot, cy } | 367 { -overshoot, cy }, { 640 + overshoot, cy } |
364 }; | 368 }; |
365 matrix.mapPoints(fPts, pts, 2); | 369 matrix.mapPoints(fPts, pts, 2); |
366 } | 370 } |
367 | 371 |
368 protected: | 372 protected: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kHori_LineType, 0); ) | 419 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kHori_LineType, 0); ) |
416 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kVert_LineType, 0); ) | 420 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kVert_LineType, 0); ) |
417 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kDiag_LineType, 0); ) | 421 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kDiag_LineType, 0); ) |
418 | 422 |
419 // pass 2 to explicitly avoid any 1-is-the-same-as-hairline special casing | 423 // pass 2 to explicitly avoid any 1-is-the-same-as-hairline special casing |
420 | 424 |
421 // hori_2 is just too slow to enable at the moment | 425 // hori_2 is just too slow to enable at the moment |
422 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kHori_LineType, 2); ) | 426 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kHori_LineType, 2); ) |
423 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kVert_LineType, 2); ) | 427 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kVert_LineType, 2); ) |
424 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kDiag_LineType, 2); ) | 428 DEF_BENCH( return new GiantDashBench(p, GiantDashBench::kDiag_LineType, 2); ) |
OLD | NEW |