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