2013-01-31 15:23:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkRegion.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
2013-01-31 15:23:44 +00:00
|
|
|
|
|
|
|
static bool sect_proc(SkRegion& a, SkRegion& b) {
|
|
|
|
SkRegion result;
|
|
|
|
return result.op(a, b, SkRegion::kIntersect_Op);
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class RegionContainBench : public Benchmark {
|
2013-01-31 15:23:44 +00:00
|
|
|
public:
|
|
|
|
typedef bool (*Proc)(SkRegion& a, SkRegion& b);
|
|
|
|
SkRegion fA, fB;
|
|
|
|
Proc fProc;
|
|
|
|
SkString fName;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
W = 200,
|
|
|
|
H = 200,
|
|
|
|
COUNT = 10,
|
|
|
|
};
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkIRect randrect(SkRandom& rand, int i) {
|
2013-01-31 15:23:44 +00:00
|
|
|
int w = rand.nextU() % W;
|
|
|
|
return SkIRect::MakeXYWH(0, i*H/COUNT, w, H/COUNT);
|
|
|
|
}
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
RegionContainBench(Proc proc, const char name[]) {
|
2013-01-31 15:23:44 +00:00
|
|
|
fProc = proc;
|
|
|
|
fName.printf("region_contains_%s", name);
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-01-31 15:23:44 +00:00
|
|
|
for (int i = 0; i < COUNT; i++) {
|
|
|
|
fA.op(randrect(rand, i), SkRegion::kXOR_Op);
|
|
|
|
}
|
|
|
|
|
2019-08-24 23:39:13 +00:00
|
|
|
fB.setRect({0, 0, H, W});
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
2013-01-31 15:23:44 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2013-01-31 15:23:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override { return fName.c_str(); }
|
2013-01-31 15:23:44 +00:00
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-01-31 15:23:44 +00:00
|
|
|
Proc proc = fProc;
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2013-01-31 15:23:44 +00:00
|
|
|
proc(fA, fB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-01-31 15:23:44 +00:00
|
|
|
};
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_BENCH(return new RegionContainBench(sect_proc, "sect");)
|