blob: 3dee66836f190863be4192b2eb9e72b7e3dfd520 [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"
reed@google.com126f7f52013-11-07 16:06:53 +00009#include "SkBitmap.h"
10#include "SkCanvas.h"
11#include "SkColorPriv.h"
12#include "SkDraw.h"
13#include "SkMatrix.h"
14#include "SkPath.h"
15#include "SkRasterClip.h"
16
tfarinaf168b862014-06-19 12:32:29 -070017class DrawPathBench : public Benchmark {
reed@google.com126f7f52013-11-07 16:06:53 +000018 SkPaint fPaint;
19 SkString fName;
20 SkPath fPath;
21 SkRasterClip fRC;
reed41e010c2015-06-09 12:16:53 -070022 SkAutoPixmapStorage fPixmap;
reed@google.com126f7f52013-11-07 16:06:53 +000023 SkMatrix fIdentity;
24 SkDraw fDraw;
25 bool fDrawCoverage;
26public:
27 DrawPathBench(bool drawCoverage) : fDrawCoverage(drawCoverage) {
28 fPaint.setAntiAlias(true);
29 fName.printf("draw_coverage_%s", drawCoverage ? "true" : "false");
30
31 fPath.moveTo(0, 0);
32 fPath.quadTo(500, 0, 500, 500);
33 fPath.quadTo(250, 0, 0, 500);
34
reed41e010c2015-06-09 12:16:53 -070035 fPixmap.alloc(SkImageInfo::MakeA8(500, 500));
reed@google.com126f7f52013-11-07 16:06:53 +000036
37 fIdentity.setIdentity();
38 fRC.setRect(fPath.getBounds().round());
39
reed41e010c2015-06-09 12:16:53 -070040 fDraw.fDst = fPixmap;
reed@google.com126f7f52013-11-07 16:06:53 +000041 fDraw.fMatrix = &fIdentity;
42 fDraw.fClip = &fRC.bwRgn();
43 fDraw.fRC = &fRC;
44 }
skia.committer@gmail.comab7442c2013-11-08 07:01:56 +000045
reed@google.com126f7f52013-11-07 16:06:53 +000046protected:
mtklein36352bf2015-03-25 18:17:31 -070047 const char* onGetName() override {
reed@google.com126f7f52013-11-07 16:06:53 +000048 return fName.c_str();
49 }
skia.committer@gmail.comab7442c2013-11-08 07:01:56 +000050
mtkleina1ebeb22015-10-01 09:43:39 -070051 void onDraw(int loops, SkCanvas* canvas) override {
reed@google.com126f7f52013-11-07 16:06:53 +000052 if (fDrawCoverage) {
commit-bot@chromium.org33614712013-12-03 18:17:16 +000053 for (int i = 0; i < loops; ++i) {
reed@google.com126f7f52013-11-07 16:06:53 +000054 fDraw.drawPathCoverage(fPath, fPaint);
55 }
56 } else {
commit-bot@chromium.org33614712013-12-03 18:17:16 +000057 for (int i = 0; i < loops; ++i) {
reed@google.com126f7f52013-11-07 16:06:53 +000058 fDraw.drawPath(fPath, fPaint);
59 }
60 }
61 }
skia.committer@gmail.comab7442c2013-11-08 07:01:56 +000062
reed@google.com126f7f52013-11-07 16:06:53 +000063private:
tfarinaf168b862014-06-19 12:32:29 -070064 typedef Benchmark INHERITED;
reed@google.com126f7f52013-11-07 16:06:53 +000065};
66
67///////////////////////////////////////////////////////////////////////////////
68
69DEF_BENCH( return new DrawPathBench(false) )
70DEF_BENCH( return new DrawPathBench(true) )