commit-bot@chromium.org | d7aaf60 | 2013-04-01 12:51:34 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2013 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "SkBenchmark.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkPaint.h" |
| 12 | #include "SkRandom.h" |
| 13 | #include "SkString.h" |
| 14 | #include "SkXfermode.h" |
commit-bot@chromium.org | eaa7797 | 2013-08-23 13:13:12 +0000 | [diff] [blame] | 15 | #include "SkLumaXfermode.h" |
commit-bot@chromium.org | d7aaf60 | 2013-04-01 12:51:34 +0000 | [diff] [blame] | 16 | |
| 17 | // Benchmark that draws non-AA rects with an SkXfermode::Mode |
| 18 | class XfermodeBench : public SkBenchmark { |
| 19 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 20 | XfermodeBench(SkXfermode::Mode mode) { |
commit-bot@chromium.org | d7aaf60 | 2013-04-01 12:51:34 +0000 | [diff] [blame] | 21 | fXfermode.reset(SkXfermode::Create(mode)); |
| 22 | SkASSERT(NULL != fXfermode.get() || SkXfermode::kSrcOver_Mode == mode); |
| 23 | fName.printf("Xfermode_%s", SkXfermode::ModeName(mode)); |
| 24 | } |
| 25 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 26 | XfermodeBench(SkXfermode* xferMode, const char* name) { |
commit-bot@chromium.org | eaa7797 | 2013-08-23 13:13:12 +0000 | [diff] [blame] | 27 | SkASSERT(NULL != xferMode); |
| 28 | fXfermode.reset(xferMode); |
| 29 | fName.printf("Xfermode_%s", name); |
| 30 | } |
| 31 | |
commit-bot@chromium.org | d7aaf60 | 2013-04-01 12:51:34 +0000 | [diff] [blame] | 32 | protected: |
| 33 | virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); } |
| 34 | |
| 35 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 36 | SkISize size = canvas->getDeviceSize(); |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 37 | SkRandom random; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 38 | for (int i = 0; i < this->getLoops(); ++i) { |
commit-bot@chromium.org | d7aaf60 | 2013-04-01 12:51:34 +0000 | [diff] [blame] | 39 | SkPaint paint; |
| 40 | paint.setXfermode(fXfermode.get()); |
| 41 | paint.setColor(random.nextU()); |
| 42 | SkScalar w = random.nextRangeScalar(SkIntToScalar(kMinSize), SkIntToScalar(kMaxSize)); |
| 43 | SkScalar h = random.nextRangeScalar(SkIntToScalar(kMinSize), SkIntToScalar(kMaxSize)); |
| 44 | SkRect rect = SkRect::MakeXYWH( |
| 45 | random.nextUScalar1() * (size.fWidth - w), |
| 46 | random.nextUScalar1() * (size.fHeight - h), |
| 47 | w, |
| 48 | h |
| 49 | ); |
| 50 | canvas->drawRect(rect, paint); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | private: |
| 55 | enum { |
bsalomon@google.com | 292ce73 | 2013-05-03 16:28:33 +0000 | [diff] [blame] | 56 | kMinSize = 50, |
| 57 | kMaxSize = 100, |
commit-bot@chromium.org | d7aaf60 | 2013-04-01 12:51:34 +0000 | [diff] [blame] | 58 | }; |
| 59 | SkAutoTUnref<SkXfermode> fXfermode; |
| 60 | SkString fName; |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 61 | |
commit-bot@chromium.org | d7aaf60 | 2013-04-01 12:51:34 +0000 | [diff] [blame] | 62 | typedef SkBenchmark INHERITED; |
| 63 | }; |
| 64 | |
commit-bot@chromium.org | 8649057 | 2013-10-04 16:52:55 +0000 | [diff] [blame] | 65 | class XferCreateBench : public SkBenchmark { |
| 66 | public: |
| 67 | XferCreateBench() { |
| 68 | fIsRendering = false; |
| 69 | } |
skia.committer@gmail.com | d34f058 | 2013-10-05 07:01:34 +0000 | [diff] [blame] | 70 | |
commit-bot@chromium.org | 8649057 | 2013-10-04 16:52:55 +0000 | [diff] [blame] | 71 | protected: |
| 72 | virtual const char* onGetName() SK_OVERRIDE { return "xfermode_create"; } |
| 73 | |
| 74 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 75 | for (int outer = 0; outer < this->getLoops() * 10; ++outer) { |
| 76 | for (int i = 0; i <= SkXfermode::kLastMode; ++i) { |
| 77 | SkXfermode* xfer = SkXfermode::Create(SkXfermode::Mode(i)); |
| 78 | SkSafeUnref(xfer); |
| 79 | } |
| 80 | } |
| 81 | } |
skia.committer@gmail.com | d34f058 | 2013-10-05 07:01:34 +0000 | [diff] [blame] | 82 | |
commit-bot@chromium.org | 8649057 | 2013-10-04 16:52:55 +0000 | [diff] [blame] | 83 | private: |
| 84 | typedef SkBenchmark INHERITED; |
| 85 | }; |
| 86 | |
commit-bot@chromium.org | d7aaf60 | 2013-04-01 12:51:34 +0000 | [diff] [blame] | 87 | ////////////////////////////////////////////////////////////////////////////// |
| 88 | |
commit-bot@chromium.org | eaa7797 | 2013-08-23 13:13:12 +0000 | [diff] [blame] | 89 | #define CONCAT_I(x, y) x ## y |
| 90 | #define CONCAT(x, y) CONCAT_I(x, y) // allow for macro expansion |
| 91 | #define BENCH(...) \ |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 92 | DEF_BENCH( return new XfermodeBench(__VA_ARGS__); );\ |
| 93 | |
commit-bot@chromium.org | d7aaf60 | 2013-04-01 12:51:34 +0000 | [diff] [blame] | 94 | |
commit-bot@chromium.org | eaa7797 | 2013-08-23 13:13:12 +0000 | [diff] [blame] | 95 | BENCH(SkXfermode::kClear_Mode) |
| 96 | BENCH(SkXfermode::kSrc_Mode) |
| 97 | BENCH(SkXfermode::kDst_Mode) |
| 98 | BENCH(SkXfermode::kSrcOver_Mode) |
| 99 | BENCH(SkXfermode::kDstOver_Mode) |
| 100 | BENCH(SkXfermode::kSrcIn_Mode) |
| 101 | BENCH(SkXfermode::kDstIn_Mode) |
| 102 | BENCH(SkXfermode::kSrcOut_Mode) |
| 103 | BENCH(SkXfermode::kDstOut_Mode) |
| 104 | BENCH(SkXfermode::kSrcATop_Mode) |
| 105 | BENCH(SkXfermode::kDstATop_Mode) |
| 106 | BENCH(SkXfermode::kXor_Mode) |
| 107 | |
| 108 | BENCH(SkXfermode::kPlus_Mode) |
| 109 | BENCH(SkXfermode::kModulate_Mode) |
| 110 | BENCH(SkXfermode::kScreen_Mode) |
| 111 | |
| 112 | BENCH(SkXfermode::kOverlay_Mode) |
| 113 | BENCH(SkXfermode::kDarken_Mode) |
| 114 | BENCH(SkXfermode::kLighten_Mode) |
| 115 | BENCH(SkXfermode::kColorDodge_Mode) |
| 116 | BENCH(SkXfermode::kColorBurn_Mode) |
| 117 | BENCH(SkXfermode::kHardLight_Mode) |
| 118 | BENCH(SkXfermode::kSoftLight_Mode) |
| 119 | BENCH(SkXfermode::kDifference_Mode) |
| 120 | BENCH(SkXfermode::kExclusion_Mode) |
| 121 | BENCH(SkXfermode::kMultiply_Mode) |
| 122 | |
| 123 | BENCH(SkXfermode::kHue_Mode) |
| 124 | BENCH(SkXfermode::kSaturation_Mode) |
| 125 | BENCH(SkXfermode::kColor_Mode) |
| 126 | BENCH(SkXfermode::kLuminosity_Mode) |
| 127 | |
| 128 | BENCH(SkLumaMaskXfermode::Create(SkXfermode::kSrcIn_Mode), "SrcInLuma") |
| 129 | BENCH(SkLumaMaskXfermode::Create(SkXfermode::kDstIn_Mode), "DstInLuma") |
fmalita@google.com | ef45a64 | 2013-09-17 13:09:16 +0000 | [diff] [blame] | 130 | BENCH(SkLumaMaskXfermode::Create(SkXfermode::kSrcOver_Mode), "SrcOverLuma") |
commit-bot@chromium.org | 8649057 | 2013-10-04 16:52:55 +0000 | [diff] [blame] | 131 | |
| 132 | DEF_BENCH(return new XferCreateBench;) |