1 /* 2 * Copyright 2012 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 "include/core/SkBitmap.h" 10 #include "include/core/SkCanvas.h" 11 #include "include/core/SkColorPriv.h" 12 #include "include/core/SkPaint.h" 13 #include "include/core/SkShader.h" 14 #include "include/core/SkString.h" 15 #include "include/private/SkTArray.h" 16 #include "include/utils/SkRandom.h" 17 18 19 class LineBench : public Benchmark { 20 SkScalar fStrokeWidth; 21 bool fDoAA; 22 SkString fName; 23 enum { 24 PTS = 500, 25 }; 26 SkPoint fPts[PTS]; 27 28 public: LineBench(SkScalar width,bool doAA)29 LineBench(SkScalar width, bool doAA) { 30 fStrokeWidth = width; 31 fDoAA = doAA; 32 fName.printf("lines_%g_%s", width, doAA ? "AA" : "BW"); 33 34 SkRandom rand; 35 for (int i = 0; i < PTS; ++i) { 36 fPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); 37 } 38 } 39 40 protected: onGetName()41 const char* onGetName() override { 42 return fName.c_str(); 43 } 44 onDraw(int loops,SkCanvas * canvas)45 void onDraw(int loops, SkCanvas* canvas) override { 46 SkPaint paint; 47 this->setupPaint(&paint); 48 49 paint.setStyle(SkPaint::kStroke_Style); 50 paint.setAntiAlias(fDoAA); 51 paint.setStrokeWidth(fStrokeWidth); 52 53 for (int i = 0; i < loops; i++) { 54 canvas->drawPoints(SkCanvas::kLines_PointMode, PTS, fPts, paint); 55 } 56 } 57 58 private: 59 using INHERITED = Benchmark; 60 }; 61 62 DEF_BENCH(return new LineBench(0, false);) 63 DEF_BENCH(return new LineBench(SK_Scalar1, false);) 64 DEF_BENCH(return new LineBench(0, true);) 65 DEF_BENCH(return new LineBench(SK_Scalar1/2, true);) 66 DEF_BENCH(return new LineBench(SK_Scalar1, true);) 67