Flutter Engine
The Flutter Engine
CoverageBench.cpp
Go to the documentation of this file.
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"
13#include "include/core/SkPath.h"
15#include "src/core/SkDraw.h"
17
18class DrawPathBench : public Benchmark {
19 SkPaint fPaint;
20 SkString fName;
21 SkPath fPath;
22 SkRasterClip fRC;
23 SkAutoPixmapStorage fPixmap;
24 SkDraw fDraw;
25 bool fDrawCoverage;
26public:
27 DrawPathBench(bool drawCoverage) : fDrawCoverage(drawCoverage) {
28 fName.printf("draw_coverage_%s", drawCoverage ? "true" : "false");
29 }
30
31protected:
32 const char* onGetName() override {
33 return fName.c_str();
34 }
35
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
51
52 fDraw.fDst = fPixmap;
53 fDraw.fCTM = &SkMatrix::I();
54 fDraw.fRC = &fRC;
55 }
56
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
69private:
70 using INHERITED = Benchmark;
71};
72
73///////////////////////////////////////////////////////////////////////////////
74
75DEF_BENCH( return new DrawPathBench(false) )
76DEF_BENCH( return new DrawPathBench(true) )
SkPath fPath
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * fName
void onDraw(int loops, SkCanvas *canvas) override
DrawPathBench(bool drawCoverage)
void onDelayedSetup() override
const char * onGetName() override
void alloc(const SkImageInfo &)
void drawPath(const SkPath &path, const SkPaint &paint, const SkMatrix *prePathMatrix=nullptr, bool pathIsMutable=false) const
Definition: SkDrawBase.h:60
const SkRasterClip * fRC
Definition: SkDrawBase.h:156
void drawPathCoverage(const SkPath &src, const SkPaint &paint, SkBlitter *customBlitter=nullptr) const
Definition: SkDrawBase.h:71
SkPixmap fDst
Definition: SkDrawBase.h:153
const SkMatrix * fCTM
Definition: SkDrawBase.h:155
Definition: SkDraw.h:38
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
Definition: SkPath.h:59
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
SkPath & quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
Definition: SkPath.cpp:746
const SkRect & getBounds() const
Definition: SkPath.cpp:430
bool erase(SkColor color, const SkIRect &subset) const
Definition: SkPixmap.cpp:742
bool setRect(const SkIRect &)
static SkImageInfo MakeA8(int width, int height)
void round(SkIRect *dst) const
Definition: SkRect.h:1228