blob: 0d85fefe1fbb9bc48973b5bfe8a23351b1818d80 [file] [log] [blame]
commit-bot@chromium.orgd7aaf602013-04-01 12:51:34 +00001
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
17class XfermodeBench : public SkBenchmark {
18public:
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
25protected:
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
47private:
48 enum {
bsalomon@google.com292ce732013-05-03 16:28:33 +000049 kNumRects = SkBENCHLOOP(75),
50 kMinSize = 50,
51 kMaxSize = 100,
commit-bot@chromium.orgd7aaf602013-04-01 12:51:34 +000052 };
53 SkAutoTUnref<SkXfermode> fXfermode;
54 SkString fName;
skia.committer@gmail.com05a2ee02013-04-02 07:01:34 +000055
commit-bot@chromium.orgd7aaf602013-04-01 12:51:34 +000056 typedef SkBenchmark INHERITED;
57};
58
59//////////////////////////////////////////////////////////////////////////////
60
bsalomon@google.com292ce732013-05-03 16:28:33 +000061static SkBenchmark* Fact00(void* p) { return new XfermodeBench(p, SkXfermode::kClear_Mode); }
62static SkBenchmark* Fact01(void* p) { return new XfermodeBench(p, SkXfermode::kSrc_Mode); }
63static SkBenchmark* Fact02(void* p) { return new XfermodeBench(p, SkXfermode::kDst_Mode); }
64static SkBenchmark* Fact03(void* p) { return new XfermodeBench(p, SkXfermode::kSrcOver_Mode); }
65static SkBenchmark* Fact04(void* p) { return new XfermodeBench(p, SkXfermode::kDstOver_Mode); }
66static SkBenchmark* Fact05(void* p) { return new XfermodeBench(p, SkXfermode::kSrcIn_Mode); }
67static SkBenchmark* Fact06(void* p) { return new XfermodeBench(p, SkXfermode::kDstIn_Mode); }
68static SkBenchmark* Fact07(void* p) { return new XfermodeBench(p, SkXfermode::kSrcOut_Mode); }
69static SkBenchmark* Fact08(void* p) { return new XfermodeBench(p, SkXfermode::kDstOut_Mode); }
70static SkBenchmark* Fact09(void* p) { return new XfermodeBench(p, SkXfermode::kSrcATop_Mode); }
71static SkBenchmark* Fact10(void* p) { return new XfermodeBench(p, SkXfermode::kDstATop_Mode); }
72static SkBenchmark* Fact11(void* p) { return new XfermodeBench(p, SkXfermode::kXor_Mode); }
73static SkBenchmark* Fact12(void* p) { return new XfermodeBench(p, SkXfermode::kPlus_Mode); }
74static SkBenchmark* Fact13(void* p) { return new XfermodeBench(p, SkXfermode::kModulate_Mode); }
75static SkBenchmark* Fact14(void* p) { return new XfermodeBench(p, SkXfermode::kScreen_Mode); }
76static SkBenchmark* Fact15(void* p) { return new XfermodeBench(p, SkXfermode::kOverlay_Mode); }
77static SkBenchmark* Fact16(void* p) { return new XfermodeBench(p, SkXfermode::kDarken_Mode); }
78static SkBenchmark* Fact17(void* p) { return new XfermodeBench(p, SkXfermode::kLighten_Mode); }
79static SkBenchmark* Fact18(void* p) { return new XfermodeBench(p, SkXfermode::kColorDodge_Mode); }
80static SkBenchmark* Fact19(void* p) { return new XfermodeBench(p, SkXfermode::kColorBurn_Mode); }
81static SkBenchmark* Fact20(void* p) { return new XfermodeBench(p, SkXfermode::kHardLight_Mode); }
82static SkBenchmark* Fact21(void* p) { return new XfermodeBench(p, SkXfermode::kSoftLight_Mode); }
83static SkBenchmark* Fact22(void* p) { return new XfermodeBench(p, SkXfermode::kDifference_Mode); }
84static SkBenchmark* Fact23(void* p) { return new XfermodeBench(p, SkXfermode::kExclusion_Mode); }
85static SkBenchmark* Fact24(void* p) { return new XfermodeBench(p, SkXfermode::kMultiply_Mode); }
86static SkBenchmark* Fact25(void* p) { return new XfermodeBench(p, SkXfermode::kHue_Mode); }
87static SkBenchmark* Fact26(void* p) { return new XfermodeBench(p, SkXfermode::kSaturation_Mode); }
88static SkBenchmark* Fact27(void* p) { return new XfermodeBench(p, SkXfermode::kColor_Mode); }
89static SkBenchmark* Fact28(void* p) { return new XfermodeBench(p, SkXfermode::kLuminosity_Mode); }
commit-bot@chromium.orgd7aaf602013-04-01 12:51:34 +000090
bsalomon@google.com292ce732013-05-03 16:28:33 +000091static BenchRegistry gReg00(Fact00);
92static BenchRegistry gReg01(Fact01);
93static BenchRegistry gReg02(Fact02);
94static BenchRegistry gReg03(Fact03);
95static BenchRegistry gReg04(Fact04);
96static BenchRegistry gReg05(Fact05);
97static BenchRegistry gReg06(Fact06);
98static BenchRegistry gReg07(Fact07);
99static BenchRegistry gReg08(Fact08);
100static BenchRegistry gReg09(Fact09);
101static BenchRegistry gReg10(Fact10);
102static BenchRegistry gReg11(Fact11);
103static BenchRegistry gReg12(Fact12);
104static BenchRegistry gReg13(Fact13);
105static BenchRegistry gReg14(Fact14);
106static BenchRegistry gReg15(Fact15);
107static BenchRegistry gReg16(Fact16);
108static BenchRegistry gReg17(Fact17);
109static BenchRegistry gReg18(Fact18);
110static BenchRegistry gReg19(Fact19);
111static BenchRegistry gReg20(Fact20);
112static BenchRegistry gReg21(Fact21);
113static BenchRegistry gReg22(Fact22);
114static BenchRegistry gReg23(Fact23);
115static BenchRegistry gReg24(Fact24);
116static BenchRegistry gReg25(Fact25);
117static BenchRegistry gReg26(Fact26);
118static BenchRegistry gReg27(Fact27);
119static BenchRegistry gReg28(Fact28);