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" |
| 15 | |
| 16 | // Benchmark that draws non-AA rects with an SkXfermode::Mode |
| 17 | class XfermodeBench : public SkBenchmark { |
| 18 | public: |
| 19 | XfermodeBench(void* param, SkXfermode::Mode mode) : SkBenchmark(param) { |
| 20 | fXfermode.reset(SkXfermode::Create(mode)); |
| 21 | SkASSERT(NULL != fXfermode.get() || SkXfermode::kSrcOver_Mode == mode); |
| 22 | fName.printf("Xfermode_%s", SkXfermode::ModeName(mode)); |
| 23 | } |
| 24 | |
| 25 | protected: |
| 26 | virtual const char* onGetName() SK_OVERRIDE { return fName.c_str(); } |
| 27 | |
| 28 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 29 | SkISize size = canvas->getDeviceSize(); |
| 30 | SkMWCRandom random; |
| 31 | for (int i = 0; i < kNumRects; ++i) { |
| 32 | SkPaint paint; |
| 33 | paint.setXfermode(fXfermode.get()); |
| 34 | paint.setColor(random.nextU()); |
| 35 | SkScalar w = random.nextRangeScalar(SkIntToScalar(kMinSize), SkIntToScalar(kMaxSize)); |
| 36 | SkScalar h = random.nextRangeScalar(SkIntToScalar(kMinSize), SkIntToScalar(kMaxSize)); |
| 37 | SkRect rect = SkRect::MakeXYWH( |
| 38 | random.nextUScalar1() * (size.fWidth - w), |
| 39 | random.nextUScalar1() * (size.fHeight - h), |
| 40 | w, |
| 41 | h |
| 42 | ); |
| 43 | canvas->drawRect(rect, paint); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | private: |
| 48 | enum { |
bsalomon@google.com | 292ce73 | 2013-05-03 16:28:33 +0000 | [diff] [blame] | 49 | kNumRects = SkBENCHLOOP(75), |
| 50 | kMinSize = 50, |
| 51 | kMaxSize = 100, |
commit-bot@chromium.org | d7aaf60 | 2013-04-01 12:51:34 +0000 | [diff] [blame] | 52 | }; |
| 53 | SkAutoTUnref<SkXfermode> fXfermode; |
| 54 | SkString fName; |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 55 | |
commit-bot@chromium.org | d7aaf60 | 2013-04-01 12:51:34 +0000 | [diff] [blame] | 56 | typedef SkBenchmark INHERITED; |
| 57 | }; |
| 58 | |
| 59 | ////////////////////////////////////////////////////////////////////////////// |
| 60 | |
bsalomon@google.com | 292ce73 | 2013-05-03 16:28:33 +0000 | [diff] [blame] | 61 | static SkBenchmark* Fact00(void* p) { return new XfermodeBench(p, SkXfermode::kClear_Mode); } |
| 62 | static SkBenchmark* Fact01(void* p) { return new XfermodeBench(p, SkXfermode::kSrc_Mode); } |
| 63 | static SkBenchmark* Fact02(void* p) { return new XfermodeBench(p, SkXfermode::kDst_Mode); } |
| 64 | static SkBenchmark* Fact03(void* p) { return new XfermodeBench(p, SkXfermode::kSrcOver_Mode); } |
| 65 | static SkBenchmark* Fact04(void* p) { return new XfermodeBench(p, SkXfermode::kDstOver_Mode); } |
| 66 | static SkBenchmark* Fact05(void* p) { return new XfermodeBench(p, SkXfermode::kSrcIn_Mode); } |
| 67 | static SkBenchmark* Fact06(void* p) { return new XfermodeBench(p, SkXfermode::kDstIn_Mode); } |
| 68 | static SkBenchmark* Fact07(void* p) { return new XfermodeBench(p, SkXfermode::kSrcOut_Mode); } |
| 69 | static SkBenchmark* Fact08(void* p) { return new XfermodeBench(p, SkXfermode::kDstOut_Mode); } |
| 70 | static SkBenchmark* Fact09(void* p) { return new XfermodeBench(p, SkXfermode::kSrcATop_Mode); } |
| 71 | static SkBenchmark* Fact10(void* p) { return new XfermodeBench(p, SkXfermode::kDstATop_Mode); } |
| 72 | static SkBenchmark* Fact11(void* p) { return new XfermodeBench(p, SkXfermode::kXor_Mode); } |
| 73 | static SkBenchmark* Fact12(void* p) { return new XfermodeBench(p, SkXfermode::kPlus_Mode); } |
| 74 | static SkBenchmark* Fact13(void* p) { return new XfermodeBench(p, SkXfermode::kModulate_Mode); } |
| 75 | static SkBenchmark* Fact14(void* p) { return new XfermodeBench(p, SkXfermode::kScreen_Mode); } |
| 76 | static SkBenchmark* Fact15(void* p) { return new XfermodeBench(p, SkXfermode::kOverlay_Mode); } |
| 77 | static SkBenchmark* Fact16(void* p) { return new XfermodeBench(p, SkXfermode::kDarken_Mode); } |
| 78 | static SkBenchmark* Fact17(void* p) { return new XfermodeBench(p, SkXfermode::kLighten_Mode); } |
| 79 | static SkBenchmark* Fact18(void* p) { return new XfermodeBench(p, SkXfermode::kColorDodge_Mode); } |
| 80 | static SkBenchmark* Fact19(void* p) { return new XfermodeBench(p, SkXfermode::kColorBurn_Mode); } |
| 81 | static SkBenchmark* Fact20(void* p) { return new XfermodeBench(p, SkXfermode::kHardLight_Mode); } |
| 82 | static SkBenchmark* Fact21(void* p) { return new XfermodeBench(p, SkXfermode::kSoftLight_Mode); } |
| 83 | static SkBenchmark* Fact22(void* p) { return new XfermodeBench(p, SkXfermode::kDifference_Mode); } |
| 84 | static SkBenchmark* Fact23(void* p) { return new XfermodeBench(p, SkXfermode::kExclusion_Mode); } |
| 85 | static SkBenchmark* Fact24(void* p) { return new XfermodeBench(p, SkXfermode::kMultiply_Mode); } |
| 86 | static SkBenchmark* Fact25(void* p) { return new XfermodeBench(p, SkXfermode::kHue_Mode); } |
| 87 | static SkBenchmark* Fact26(void* p) { return new XfermodeBench(p, SkXfermode::kSaturation_Mode); } |
| 88 | static SkBenchmark* Fact27(void* p) { return new XfermodeBench(p, SkXfermode::kColor_Mode); } |
| 89 | static SkBenchmark* Fact28(void* p) { return new XfermodeBench(p, SkXfermode::kLuminosity_Mode); } |
commit-bot@chromium.org | d7aaf60 | 2013-04-01 12:51:34 +0000 | [diff] [blame] | 90 | |
bsalomon@google.com | 292ce73 | 2013-05-03 16:28:33 +0000 | [diff] [blame] | 91 | static BenchRegistry gReg00(Fact00); |
| 92 | static BenchRegistry gReg01(Fact01); |
| 93 | static BenchRegistry gReg02(Fact02); |
| 94 | static BenchRegistry gReg03(Fact03); |
| 95 | static BenchRegistry gReg04(Fact04); |
| 96 | static BenchRegistry gReg05(Fact05); |
| 97 | static BenchRegistry gReg06(Fact06); |
| 98 | static BenchRegistry gReg07(Fact07); |
| 99 | static BenchRegistry gReg08(Fact08); |
| 100 | static BenchRegistry gReg09(Fact09); |
| 101 | static BenchRegistry gReg10(Fact10); |
| 102 | static BenchRegistry gReg11(Fact11); |
| 103 | static BenchRegistry gReg12(Fact12); |
| 104 | static BenchRegistry gReg13(Fact13); |
| 105 | static BenchRegistry gReg14(Fact14); |
| 106 | static BenchRegistry gReg15(Fact15); |
| 107 | static BenchRegistry gReg16(Fact16); |
| 108 | static BenchRegistry gReg17(Fact17); |
| 109 | static BenchRegistry gReg18(Fact18); |
| 110 | static BenchRegistry gReg19(Fact19); |
| 111 | static BenchRegistry gReg20(Fact20); |
| 112 | static BenchRegistry gReg21(Fact21); |
| 113 | static BenchRegistry gReg22(Fact22); |
| 114 | static BenchRegistry gReg23(Fact23); |
| 115 | static BenchRegistry gReg24(Fact24); |
| 116 | static BenchRegistry gReg25(Fact25); |
| 117 | static BenchRegistry gReg26(Fact26); |
| 118 | static BenchRegistry gReg27(Fact27); |
| 119 | static BenchRegistry gReg28(Fact28); |