• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/SkMatrixProvider.h"
17 #include "src/core/SkRasterClip.h"
18 
19 class DrawPathBench : public Benchmark {
20     SkPaint     fPaint;
21     SkString    fName;
22     SkPath      fPath;
23     SkRasterClip fRC;
24     SkAutoPixmapStorage fPixmap;
25     SkSimpleMatrixProvider fIdentityMatrixProvider;
26     SkDraw      fDraw;
27     bool        fDrawCoverage;
28 public:
DrawPathBench(bool drawCoverage)29     DrawPathBench(bool drawCoverage)
30             : fIdentityMatrixProvider(SkMatrix::I()), fDrawCoverage(drawCoverage) {
31         fPaint.setAntiAlias(true);
32         fName.printf("draw_coverage_%s", drawCoverage ? "true" : "false");
33 
34         fPath.moveTo(0, 0);
35         fPath.quadTo(500, 0, 500, 500);
36         fPath.quadTo(250, 0, 0, 500);
37 
38         fPixmap.alloc(SkImageInfo::MakeA8(500, 500));
39         if (!drawCoverage) {
40             // drawPathCoverage() goes out of its way to work fine with an uninitialized
41             // dst buffer, even in "SrcOver" mode, but ordinary drawing sure doesn't.
42             fPixmap.erase(0);
43         }
44 
45         fRC.setRect(fPath.getBounds().round());
46 
47         fDraw.fDst            = fPixmap;
48         fDraw.fMatrixProvider = &fIdentityMatrixProvider;
49         fDraw.fRC             = &fRC;
50     }
51 
52 protected:
onGetName()53     const char* onGetName() override {
54         return fName.c_str();
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