reed@google.com | a3c1348 | 2013-01-31 15:23:44 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "Benchmark.h" |
reed@google.com | a3c1348 | 2013-01-31 15:23:44 +0000 | [diff] [blame] | 9 | #include "SkRandom.h" |
| 10 | #include "SkRegion.h" |
| 11 | #include "SkString.h" |
| 12 | |
| 13 | static bool sect_proc(SkRegion& a, SkRegion& b) { |
| 14 | SkRegion result; |
| 15 | return result.op(a, b, SkRegion::kIntersect_Op); |
| 16 | } |
| 17 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 18 | class RegionContainBench : public Benchmark { |
reed@google.com | a3c1348 | 2013-01-31 15:23:44 +0000 | [diff] [blame] | 19 | public: |
| 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.com | a3c1348 | 2013-01-31 15:23:44 +0000 | [diff] [blame] | 29 | }; |
| 30 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 31 | SkIRect randrect(SkRandom& rand, int i) { |
reed@google.com | a3c1348 | 2013-01-31 15:23:44 +0000 | [diff] [blame] | 32 | int w = rand.nextU() % W; |
| 33 | return SkIRect::MakeXYWH(0, i*H/COUNT, w, H/COUNT); |
| 34 | } |
| 35 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 36 | RegionContainBench(Proc proc, const char name[]) { |
reed@google.com | a3c1348 | 2013-01-31 15:23:44 +0000 | [diff] [blame] | 37 | fProc = proc; |
| 38 | fName.printf("region_contains_%s", name); |
| 39 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 40 | SkRandom rand; |
reed@google.com | a3c1348 | 2013-01-31 15:23:44 +0000 | [diff] [blame] | 41 | 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.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 46 | } |
reed@google.com | a3c1348 | 2013-01-31 15:23:44 +0000 | [diff] [blame] | 47 | |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 48 | virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 49 | return backend == kNonRendering_Backend; |
reed@google.com | a3c1348 | 2013-01-31 15:23:44 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | protected: |
| 53 | virtual const char* onGetName() { return fName.c_str(); } |
| 54 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 55 | virtual void onDraw(const int loops, SkCanvas*) { |
reed@google.com | a3c1348 | 2013-01-31 15:23:44 +0000 | [diff] [blame] | 56 | Proc proc = fProc; |
| 57 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 58 | for (int i = 0; i < loops; ++i) { |
reed@google.com | a3c1348 | 2013-01-31 15:23:44 +0000 | [diff] [blame] | 59 | proc(fA, fB); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 64 | typedef Benchmark INHERITED; |
reed@google.com | a3c1348 | 2013-01-31 15:23:44 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 67 | DEF_BENCH( return SkNEW_ARGS(RegionContainBench, (sect_proc, "sect")); ) |