2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "bench/Benchmark.h"
9 #include "include/core/SkRegion.h"
10 #include "include/core/SkString.h"
11 #include "include/utils/SkRandom.h"
13 static bool sect_proc(SkRegion& a, SkRegion& b) {
15 return result.op(a, b, SkRegion::kIntersect_Op);
18 class RegionContainBench : public Benchmark {
20 typedef bool (*Proc)(SkRegion& a, SkRegion& b);
31 SkIRect randrect(SkRandom& rand, int i) {
32 int w = rand.nextU() % W;
33 return SkIRect::MakeXYWH(0, i*H/COUNT, w, H/COUNT);
36 RegionContainBench(Proc proc, const char name[]) {
38 fName.printf("region_contains_%s", name);
41 for (int i = 0; i < COUNT; i++) {
42 fA.op(randrect(rand, i), SkRegion::kXOR_Op);
45 fB.setRect({0, 0, H, W});
48 bool isSuitableFor(Backend backend) override {
49 return backend == kNonRendering_Backend;
53 const char* onGetName() override { return fName.c_str(); }
55 void onDraw(int loops, SkCanvas*) override {
58 for (int i = 0; i < loops; ++i) {
64 using INHERITED = Benchmark;
67 DEF_BENCH(return new RegionContainBench(sect_proc, "sect");)