blob: 39088c1a788f0aaffd4475f97fa423a04d48455b [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
reed@google.coma069c8f2011-11-28 19:54:56 +000059class AAClipRegionBench : public SkBenchmark {
60public:
61 AAClipRegionBench(void* param) : INHERITED(param) {
62 SkPath path;
63 // test conversion of a complex clip to a aaclip
64 path.addCircle(0, 0, SkIntToScalar(200));
65 path.addCircle(0, 0, SkIntToScalar(180));
66 // evenodd means we've constructed basically a stroked circle
67 path.setFillType(SkPath::kEvenOdd_FillType);
68
69 SkIRect bounds;
70 path.getBounds().roundOut(&bounds);
71 fRegion.setPath(path, SkRegion(bounds));
72 }
73
74protected:
75 virtual const char* onGetName() { return "aaclip_setregion"; }
76 virtual void onDraw(SkCanvas* canvas) {
77 for (int i = 0; i < N; ++i) {
78 SkAAClip clip;
79 clip.setRegion(fRegion);
80 }
81 }
82
83private:
84 enum {
85 N = SkBENCHLOOP(400),
86 };
87 SkRegion fRegion;
88 typedef SkBenchmark INHERITED;
89};
90
reed@google.com57c49572011-10-31 14:33:35 +000091///////////////////////////////////////////////////////////////////////////////
92
93static SkBenchmark* Fact0(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, false, false)); }
94static SkBenchmark* Fact1(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, false, true)); }
95static SkBenchmark* Fact2(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, true, false)); }
96static SkBenchmark* Fact3(void* p) { return SkNEW_ARGS(AAClipBuilderBench, (p, true, true)); }
97
98static BenchRegistry gReg0(Fact0);
99static BenchRegistry gReg1(Fact1);
100static BenchRegistry gReg2(Fact2);
101static BenchRegistry gReg3(Fact3);
reed@google.coma069c8f2011-11-28 19:54:56 +0000102
103static SkBenchmark* Fact01(void* p) { return SkNEW_ARGS(AAClipRegionBench, (p)); }
104static BenchRegistry gReg01(Fact01);