blob: ce590e5c494443f8adf816a475d413bf02138e23 [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
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
robertphillipsc5035e72016-03-17 06:58:39 -07009#include "SkAutoPixmapStorage.h"
reed@google.com126f7f52013-11-07 16:06:53 +000010#include "SkBitmap.h"
11#include "SkCanvas.h"
12#include "SkColorPriv.h"
13#include "SkDraw.h"
14#include "SkMatrix.h"
15#include "SkPath.h"
16#include "SkRasterClip.h"
17
tfarinaf168b862014-06-19 12:32:29 -070018class DrawPathBench : public Benchmark {
reed@google.com126f7f52013-11-07 16:06:53 +000019 SkPaint fPaint;
20 SkString fName;
21 SkPath fPath;
22 SkRasterClip fRC;
reed41e010c2015-06-09 12:16:53 -070023 SkAutoPixmapStorage fPixmap;
reed@google.com126f7f52013-11-07 16:06:53 +000024 SkMatrix fIdentity;
25 SkDraw fDraw;
26 bool fDrawCoverage;
27public:
28 DrawPathBench(bool drawCoverage) : fDrawCoverage(drawCoverage) {
29 fPaint.setAntiAlias(true);
30 fName.printf("draw_coverage_%s", drawCoverage ? "true" : "false");
31
32 fPath.moveTo(0, 0);
33 fPath.quadTo(500, 0, 500, 500);
34 fPath.quadTo(250, 0, 0, 500);
35
reed41e010c2015-06-09 12:16:53 -070036 fPixmap.alloc(SkImageInfo::MakeA8(500, 500));
Mike Kleine71b1672017-01-13 07:59:23 -050037 if (!drawCoverage) {
38 // drawPathCoverage() goes out of its way to work fine with an uninitialized
39 // dst buffer, even in "SrcOver" mode, but ordinary drawing sure doesn't.
40 fPixmap.erase(0);
41 }
reed@google.com126f7f52013-11-07 16:06:53 +000042
43 fIdentity.setIdentity();
44 fRC.setRect(fPath.getBounds().round());
45
reed41e010c2015-06-09 12:16:53 -070046 fDraw.fDst = fPixmap;
reed@google.com126f7f52013-11-07 16:06:53 +000047 fDraw.fMatrix = &fIdentity;
reed@google.com126f7f52013-11-07 16:06:53 +000048 fDraw.fRC = &fRC;
49 }
skia.committer@gmail.comab7442c2013-11-08 07:01:56 +000050
reed@google.com126f7f52013-11-07 16:06:53 +000051protected:
mtklein36352bf2015-03-25 18:17:31 -070052 const char* onGetName() override {
reed@google.com126f7f52013-11-07 16:06:53 +000053 return fName.c_str();
54 }
skia.committer@gmail.comab7442c2013-11-08 07:01:56 +000055
mtkleina1ebeb22015-10-01 09:43:39 -070056 void onDraw(int loops, SkCanvas* canvas) override {
reed@google.com126f7f52013-11-07 16:06:53 +000057 if (fDrawCoverage) {
commit-bot@chromium.org33614712013-12-03 18:17:16 +000058 for (int i = 0; i < loops; ++i) {
reed@google.com126f7f52013-11-07 16:06:53 +000059 fDraw.drawPathCoverage(fPath, fPaint);
60 }
61 } else {
commit-bot@chromium.org33614712013-12-03 18:17:16 +000062 for (int i = 0; i < loops; ++i) {
reed@google.com126f7f52013-11-07 16:06:53 +000063 fDraw.drawPath(fPath, fPaint);
64 }
65 }
66 }
skia.committer@gmail.comab7442c2013-11-08 07:01:56 +000067
reed@google.com126f7f52013-11-07 16:06:53 +000068private:
tfarinaf168b862014-06-19 12:32:29 -070069 typedef Benchmark INHERITED;
reed@google.com126f7f52013-11-07 16:06:53 +000070};
71
72///////////////////////////////////////////////////////////////////////////////
73
74DEF_BENCH( return new DrawPathBench(false) )
75DEF_BENCH( return new DrawPathBench(true) )