blob: a47ab3395f8597bde530ba45f7ec9d24ee72b1b9 [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
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
reed@google.coma3c13482013-01-31 15:23:44 +00009#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
tfarinaf168b862014-06-19 12:32:29 -070018class RegionContainBench : public Benchmark {
reed@google.coma3c13482013-01-31 15:23:44 +000019public:
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);
commit-bot@chromium.org644629c2013-11-21 06:21:58 +000046 }
reed@google.coma3c13482013-01-31 15:23:44 +000047
commit-bot@chromium.org644629c2013-11-21 06:21:58 +000048 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
49 return backend == kNonRendering_Backend;
reed@google.coma3c13482013-01-31 15:23:44 +000050 }
51
52protected:
53 virtual const char* onGetName() { return fName.c_str(); }
54
commit-bot@chromium.org33614712013-12-03 18:17:16 +000055 virtual void onDraw(const int loops, SkCanvas*) {
reed@google.coma3c13482013-01-31 15:23:44 +000056 Proc proc = fProc;
57
commit-bot@chromium.org33614712013-12-03 18:17:16 +000058 for (int i = 0; i < loops; ++i) {
reed@google.coma3c13482013-01-31 15:23:44 +000059 proc(fA, fB);
60 }
61 }
62
63private:
tfarinaf168b862014-06-19 12:32:29 -070064 typedef Benchmark INHERITED;
reed@google.coma3c13482013-01-31 15:23:44 +000065};
66
mtklein@google.com410e6e82013-09-13 19:52:27 +000067DEF_BENCH( return SkNEW_ARGS(RegionContainBench, (sect_proc, "sect")); )