Debian Codegraph @

bench/CoverageBench.cpp

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