blob: a7998951bf1591b94c5a4983dc1b233d8734b95f [file] [log] [blame]
reed@google.coma3c13482013-01-31 15:23:44 +00001/*
2 * Copyright 2013 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 "SkRandom.h"
10#include "SkRegion.h"
11#include "SkString.h"
12
13static bool sect_proc(SkRegion& a, SkRegion& b) {
14 SkRegion result;
15 return result.op(a, b, SkRegion::kIntersect_Op);
16}
17
18class RegionContainBench : public SkBenchmark {
19public:
20 typedef bool (*Proc)(SkRegion& a, SkRegion& b);
21 SkRegion fA, fB;
22 Proc fProc;
23 SkString fName;
24
25 enum {
26 W = 200,
27 H = 200,
28 COUNT = 10,
reed@google.coma3c13482013-01-31 15:23:44 +000029 };
30
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000031 SkIRect randrect(SkRandom& rand, int i) {
reed@google.coma3c13482013-01-31 15:23:44 +000032 int w = rand.nextU() % W;
33 return SkIRect::MakeXYWH(0, i*H/COUNT, w, H/COUNT);
34 }
35
mtklein@google.com410e6e82013-09-13 19:52:27 +000036 RegionContainBench(Proc proc, const char name[]) {
reed@google.coma3c13482013-01-31 15:23:44 +000037 fProc = proc;
38 fName.printf("region_contains_%s", name);
39
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000040 SkRandom rand;
reed@google.coma3c13482013-01-31 15:23:44 +000041 for (int i = 0; i < COUNT; i++) {
42 fA.op(randrect(rand, i), SkRegion::kXOR_Op);
43 }
44
45 fB.setRect(0, 0, H, W);
46
47 fIsRendering = false;
48 }
49
50protected:
51 virtual const char* onGetName() { return fName.c_str(); }
52
sugoi@google.com77472f02013-03-05 18:50:01 +000053 virtual void onDraw(SkCanvas*) {
reed@google.coma3c13482013-01-31 15:23:44 +000054 Proc proc = fProc;
55
mtklein@google.comc2897432013-09-10 19:23:38 +000056 for (int i = 0; i < this->getLoops(); ++i) {
reed@google.coma3c13482013-01-31 15:23:44 +000057 proc(fA, fB);
58 }
59 }
60
61private:
62 typedef SkBenchmark INHERITED;
63};
64
mtklein@google.com410e6e82013-09-13 19:52:27 +000065DEF_BENCH( return SkNEW_ARGS(RegionContainBench, (sect_proc, "sect")); )