reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #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" |
| 16 | #include "src/core/SkRasterClip.h" |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 17 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 18 | class DrawPathBench : public Benchmark { |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 19 | SkPaint fPaint; |
| 20 | SkString fName; |
| 21 | SkPath fPath; |
| 22 | SkRasterClip fRC; |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 23 | SkAutoPixmapStorage fPixmap; |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 24 | SkMatrix fIdentity; |
| 25 | SkDraw fDraw; |
| 26 | bool fDrawCoverage; |
| 27 | public: |
| 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 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 36 | fPixmap.alloc(SkImageInfo::MakeA8(500, 500)); |
Mike Klein | e71b167 | 2017-01-13 07:59:23 -0500 | [diff] [blame] | 37 | 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.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 42 | |
| 43 | fIdentity.setIdentity(); |
| 44 | fRC.setRect(fPath.getBounds().round()); |
| 45 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 46 | fDraw.fDst = fPixmap; |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 47 | fDraw.fMatrix = &fIdentity; |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 48 | fDraw.fRC = &fRC; |
| 49 | } |
skia.committer@gmail.com | ab7442c | 2013-11-08 07:01:56 +0000 | [diff] [blame] | 50 | |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 51 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 52 | const char* onGetName() override { |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 53 | return fName.c_str(); |
| 54 | } |
skia.committer@gmail.com | ab7442c | 2013-11-08 07:01:56 +0000 | [diff] [blame] | 55 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 56 | void onDraw(int loops, SkCanvas* canvas) override { |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 57 | if (fDrawCoverage) { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 58 | for (int i = 0; i < loops; ++i) { |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 59 | fDraw.drawPathCoverage(fPath, fPaint); |
| 60 | } |
| 61 | } else { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 62 | for (int i = 0; i < loops; ++i) { |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 63 | fDraw.drawPath(fPath, fPaint); |
| 64 | } |
| 65 | } |
| 66 | } |
skia.committer@gmail.com | ab7442c | 2013-11-08 07:01:56 +0000 | [diff] [blame] | 67 | |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 68 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 69 | typedef Benchmark INHERITED; |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /////////////////////////////////////////////////////////////////////////////// |
| 73 | |
| 74 | DEF_BENCH( return new DrawPathBench(false) ) |
| 75 | DEF_BENCH( return new DrawPathBench(true) ) |