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 | |
| 8 | #include "SkBenchmark.h" |
| 9 | #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 | |
| 17 | class DrawPathBench : public SkBenchmark { |
| 18 | SkPaint fPaint; |
| 19 | SkString fName; |
| 20 | SkPath fPath; |
| 21 | SkRasterClip fRC; |
| 22 | SkBitmap fBitmap; |
| 23 | SkMatrix fIdentity; |
| 24 | SkDraw fDraw; |
| 25 | bool fDrawCoverage; |
| 26 | public: |
| 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 | |
reed | 6c22573 | 2014-06-09 19:52:07 -0700 | [diff] [blame] | 35 | fBitmap.allocPixels(SkImageInfo::MakeA8(500, 500)); |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 36 | |
| 37 | fIdentity.setIdentity(); |
| 38 | fRC.setRect(fPath.getBounds().round()); |
| 39 | |
| 40 | fDraw.fBitmap = &fBitmap; |
| 41 | fDraw.fMatrix = &fIdentity; |
| 42 | fDraw.fClip = &fRC.bwRgn(); |
| 43 | fDraw.fRC = &fRC; |
| 44 | } |
skia.committer@gmail.com | ab7442c | 2013-11-08 07:01:56 +0000 | [diff] [blame] | 45 | |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 46 | protected: |
| 47 | virtual const char* onGetName() SK_OVERRIDE { |
| 48 | return fName.c_str(); |
| 49 | } |
skia.committer@gmail.com | ab7442c | 2013-11-08 07:01:56 +0000 | [diff] [blame] | 50 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 51 | virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 52 | if (fDrawCoverage) { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 53 | for (int i = 0; i < loops; ++i) { |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 54 | fDraw.drawPathCoverage(fPath, fPaint); |
| 55 | } |
| 56 | } else { |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 57 | for (int i = 0; i < loops; ++i) { |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 58 | fDraw.drawPath(fPath, fPaint); |
| 59 | } |
| 60 | } |
| 61 | } |
skia.committer@gmail.com | ab7442c | 2013-11-08 07:01:56 +0000 | [diff] [blame] | 62 | |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 63 | private: |
| 64 | typedef SkBenchmark INHERITED; |
| 65 | }; |
| 66 | |
| 67 | /////////////////////////////////////////////////////////////////////////////// |
| 68 | |
| 69 | DEF_BENCH( return new DrawPathBench(false) ) |
| 70 | DEF_BENCH( return new DrawPathBench(true) ) |