blob: 8668513979ee082c02df7756d85510bfbc05d32e [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,
29 N = SkBENCHLOOP(20000)
30 };
31
32 SkIRect randrect(SkRandom& rand, int i) {
33 int w = rand.nextU() % W;
34 return SkIRect::MakeXYWH(0, i*H/COUNT, w, H/COUNT);
35 }
36
37 RegionContainBench(void* param, Proc proc, const char name[]) : INHERITED(param) {
38 fProc = proc;
39 fName.printf("region_contains_%s", name);
40
41 SkRandom rand;
42 for (int i = 0; i < COUNT; i++) {
43 fA.op(randrect(rand, i), SkRegion::kXOR_Op);
44 }
45
46 fB.setRect(0, 0, H, W);
47
48 fIsRendering = false;
49 }
50
51protected:
52 virtual const char* onGetName() { return fName.c_str(); }
53
sugoi@google.com77472f02013-03-05 18:50:01 +000054 virtual void onDraw(SkCanvas*) {
reed@google.coma3c13482013-01-31 15:23:44 +000055 Proc proc = fProc;
56
57 for (int i = 0; i < N; ++i) {
58 proc(fA, fB);
59 }
60 }
61
62private:
63 typedef SkBenchmark INHERITED;
64};
65
66static SkBenchmark* gF0(void* p) { return SkNEW_ARGS(RegionContainBench, (p, sect_proc, "sect")); }
67
68static BenchRegistry gR0(gF0);