1 /* 2 * Copyright 2015 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 */ 7 8 #include "bench/Benchmark.h" 9 #include "bench/BigPath.h" 10 #include "include/core/SkCanvas.h" 11 #include "include/core/SkPath.h" 12 #include "tools/ToolUtils.h" 13 14 enum Align { 15 kLeft_Align, 16 kMiddle_Align, 17 kRight_Align 18 }; 19 20 const char* gAlignName[] = { "left", "middle", "right" }; 21 22 // Inspired by crbug.com/455429 23 class BigPathBench : public Benchmark { 24 SkPath fPath; 25 SkString fName; 26 Align fAlign; 27 bool fRound; 28 29 public: BigPathBench(Align align,bool round)30 BigPathBench(Align align, bool round) : fAlign(align), fRound(round) { 31 fName.printf("bigpath_%s", gAlignName[fAlign]); 32 if (round) { 33 fName.append("_round"); 34 } 35 } 36 37 protected: onGetName()38 const char* onGetName() override { 39 return fName.c_str(); 40 } 41 onGetSize()42 SkIPoint onGetSize() override { 43 return SkIPoint::Make(640, 100); 44 } 45 onDelayedSetup()46 void onDelayedSetup() override { fPath = BenchUtils::make_big_path(); } 47 onDraw(int loops,SkCanvas * canvas)48 void onDraw(int loops, SkCanvas* canvas) override { 49 SkPaint paint; 50 paint.setAntiAlias(true); 51 paint.setStyle(SkPaint::kStroke_Style); 52 paint.setStrokeWidth(2); 53 if (fRound) { 54 paint.setStrokeJoin(SkPaint::kRound_Join); 55 } 56 this->setupPaint(&paint); 57 58 const SkRect r = fPath.getBounds(); 59 switch (fAlign) { 60 case kLeft_Align: 61 canvas->translate(-r.left(), 0); 62 break; 63 case kMiddle_Align: 64 break; 65 case kRight_Align: 66 canvas->translate(640 - r.right(), 0); 67 break; 68 } 69 70 for (int i = 0; i < loops; i++) { 71 canvas->drawPath(fPath, paint); 72 } 73 } 74 75 private: 76 using INHERITED = Benchmark; 77 }; 78 79 DEF_BENCH( return new BigPathBench(kLeft_Align, false); ) 80 DEF_BENCH( return new BigPathBench(kMiddle_Align, false); ) 81 DEF_BENCH( return new BigPathBench(kRight_Align, false); ) 82 83 DEF_BENCH( return new BigPathBench(kLeft_Align, true); ) 84 DEF_BENCH( return new BigPathBench(kMiddle_Align, true); ) 85 DEF_BENCH( return new BigPathBench(kRight_Align, true); ) 86