blob: eca45184a6975624e4a6407488bea0516b3ab869 [file] [log] [blame]
reed@google.com57c49572011-10-31 14:33:35 +00001/*
2 * Copyright 2011 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 "SkAAClip.h"
10#include "SkPath.h"
11#include "SkRegion.h"
12#include "SkString.h"
13
14class AAClipBuilderBench : public SkBenchmark {
15 SkString fName;
16 SkPath fPath;
17 SkRect fRect;
18 SkRegion fRegion;
19 bool fDoPath;
20 bool fDoAA;
21
22 enum {
23 N = SkBENCHLOOP(200),
24 };
25
26public:
27 AAClipBuilderBench(void* param, bool doPath, bool doAA) : INHERITED(param) {
28 fDoPath = doPath;
29 fDoAA = doAA;
30
31 fName.printf("aaclip_build_%s_%s", doPath ? "path" : "rect",
32 doAA ? "AA" : "BW");
33
34 fRegion.setRect(0, 0, 640, 480);
35 fRect.set(fRegion.getBounds());
36 fRect.inset(SK_Scalar1/4, SK_Scalar1/4);
37 fPath.addRoundRect(fRect, SkIntToScalar(20), SkIntToScalar(20));
38 }
39
40protected:
41 virtual const char* onGetName() { return fName.c_str(); }
42 virtual void onDraw(SkCanvas* canvas) {
43 SkPaint paint;
44 this->setupPaint(&paint);
45
46 for (int i = 0; i < N; ++i) {
47 SkAAClip clip;
48 if (fDoPath) {
49 clip.setPath(fPath, &fRegion, fDoAA);
50 } else {
51 clip.setRect(fRect, fDoAA);
52 }
53 }
54 }
55private:
56 typedef SkBenchmark INHERITED;
57};
58
59///////////////////////////////////////////////////////////////////////////////
60
61static SkBenchmark* Fact0(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, false, false)); }
62static SkBenchmark* Fact1(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, false, true)); }
63static SkBenchmark* Fact2(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, true, false)); }
64static SkBenchmark* Fact3(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, true, true)); }
65
66static BenchRegistry gReg0(Fact0);
67static BenchRegistry gReg1(Fact1);
68static BenchRegistry gReg2(Fact2);
69static BenchRegistry gReg3(Fact3);