blob: c94fa506d0130c9f9400313e9106f1bc8e996e9b [file] [log] [blame]
reed@google.com126f7f52013-11-07 16:06:53 +00001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#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"
Herb Derbya08bde62020-06-12 15:46:06 -040016#include "src/core/SkMatrixProvider.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "src/core/SkRasterClip.h"
reed@google.com126f7f52013-11-07 16:06:53 +000018
tfarinaf168b862014-06-19 12:32:29 -070019class DrawPathBench : public Benchmark {
reed@google.com126f7f52013-11-07 16:06:53 +000020 SkPaint fPaint;
21 SkString fName;
22 SkPath fPath;
23 SkRasterClip fRC;
reed41e010c2015-06-09 12:16:53 -070024 SkAutoPixmapStorage fPixmap;
Brian Osman9aaec362020-05-08 14:54:37 -040025 SkSimpleMatrixProvider fIdentityMatrixProvider;
reed@google.com126f7f52013-11-07 16:06:53 +000026 SkDraw fDraw;
27 bool fDrawCoverage;
28public:
Brian Osman9aaec362020-05-08 14:54:37 -040029 DrawPathBench(bool drawCoverage)
30 : fIdentityMatrixProvider(SkMatrix::I()), fDrawCoverage(drawCoverage) {
reed@google.com126f7f52013-11-07 16:06:53 +000031 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
reed41e010c2015-06-09 12:16:53 -070038 fPixmap.alloc(SkImageInfo::MakeA8(500, 500));
Mike Kleine71b1672017-01-13 07:59:23 -050039 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 }
reed@google.com126f7f52013-11-07 16:06:53 +000044
reed@google.com126f7f52013-11-07 16:06:53 +000045 fRC.setRect(fPath.getBounds().round());
46
Brian Osman9aaec362020-05-08 14:54:37 -040047 fDraw.fDst = fPixmap;
48 fDraw.fMatrixProvider = &fIdentityMatrixProvider;
49 fDraw.fRC = &fRC;
reed@google.com126f7f52013-11-07 16:06:53 +000050 }
skia.committer@gmail.comab7442c2013-11-08 07:01:56 +000051
reed@google.com126f7f52013-11-07 16:06:53 +000052protected:
mtklein36352bf2015-03-25 18:17:31 -070053 const char* onGetName() override {
reed@google.com126f7f52013-11-07 16:06:53 +000054 return fName.c_str();
55 }
skia.committer@gmail.comab7442c2013-11-08 07:01:56 +000056
mtkleina1ebeb22015-10-01 09:43:39 -070057 void onDraw(int loops, SkCanvas* canvas) override {
reed@google.com126f7f52013-11-07 16:06:53 +000058 if (fDrawCoverage) {
commit-bot@chromium.org33614712013-12-03 18:17:16 +000059 for (int i = 0; i < loops; ++i) {
reed@google.com126f7f52013-11-07 16:06:53 +000060 fDraw.drawPathCoverage(fPath, fPaint);
61 }
62 } else {
commit-bot@chromium.org33614712013-12-03 18:17:16 +000063 for (int i = 0; i < loops; ++i) {
reed@google.com126f7f52013-11-07 16:06:53 +000064 fDraw.drawPath(fPath, fPaint);
65 }
66 }
67 }
skia.committer@gmail.comab7442c2013-11-08 07:01:56 +000068
reed@google.com126f7f52013-11-07 16:06:53 +000069private:
tfarinaf168b862014-06-19 12:32:29 -070070 typedef Benchmark INHERITED;
reed@google.com126f7f52013-11-07 16:06:53 +000071};
72
73///////////////////////////////////////////////////////////////////////////////
74
75DEF_BENCH( return new DrawPathBench(false) )
76DEF_BENCH( return new DrawPathBench(true) )