1 /* 2 * Copyright 2013 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/SkMatrix.h" 13 #include "include/core/SkPath.h" 14 #include "src/core/SkAutoPixmapStorage.h" 15 #include "src/core/SkDraw.h" 16 #include "src/core/SkRasterClip.h" 17 18 class DrawPathBench : public Benchmark { 19 SkPaint fPaint; 20 SkString fName; 21 SkPath fPath; 22 SkRasterClip fRC; 23 SkAutoPixmapStorage fPixmap; 24 SkDraw fDraw; 25 bool fDrawCoverage; 26 public: DrawPathBench(bool drawCoverage)27 DrawPathBench(bool drawCoverage) : fDrawCoverage(drawCoverage) { 28 fName.printf("draw_coverage_%s", drawCoverage ? "true" : "false"); 29 } 30 31 protected: onGetName()32 const char* onGetName() override { 33 return fName.c_str(); 34 } 35 onDelayedSetup()36 void onDelayedSetup() override { 37 fPaint.setAntiAlias(true); 38 39 fPath.moveTo(0, 0); 40 fPath.quadTo(500, 0, 500, 500); 41 fPath.quadTo(250, 0, 0, 500); 42 43 fPixmap.alloc(SkImageInfo::MakeA8(500, 500)); 44 if (!fDrawCoverage) { 45 // drawPathCoverage() goes out of its way to work fine with an uninitialized 46 // dst buffer, even in "SrcOver" mode, but ordinary drawing sure doesn't. 47 fPixmap.erase(0); 48 } 49 50 fRC.setRect(fPath.getBounds().round()); 51 52 fDraw.fDst = fPixmap; 53 fDraw.fCTM = &SkMatrix::I(); 54 fDraw.fRC = &fRC; 55 } 56 onDraw(int loops,SkCanvas * canvas)57 void onDraw(int loops, SkCanvas* canvas) override { 58 if (fDrawCoverage) { 59 for (int i = 0; i < loops; ++i) { 60 fDraw.drawPathCoverage(fPath, fPaint); 61 } 62 } else { 63 for (int i = 0; i < loops; ++i) { 64 fDraw.drawPath(fPath, fPaint); 65 } 66 } 67 } 68 69 private: 70 using INHERITED = Benchmark; 71 }; 72 73 /////////////////////////////////////////////////////////////////////////////// 74 75 DEF_BENCH( return new DrawPathBench(false) ) 76 DEF_BENCH( return new DrawPathBench(true) ) 77