2012-04-27 19:29:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2012-04-27 19:29:52 +00:00
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
|
|
|
static bool union_proc(SkRegion& a, SkRegion& b) {
|
|
|
|
SkRegion result;
|
|
|
|
return result.op(a, b, SkRegion::kUnion_Op);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool sect_proc(SkRegion& a, SkRegion& b) {
|
|
|
|
SkRegion result;
|
|
|
|
return result.op(a, b, SkRegion::kIntersect_Op);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool diff_proc(SkRegion& a, SkRegion& b) {
|
|
|
|
SkRegion result;
|
|
|
|
return result.op(a, b, SkRegion::kDifference_Op);
|
|
|
|
}
|
|
|
|
|
2012-05-31 18:28:59 +00:00
|
|
|
static bool diffrect_proc(SkRegion& a, SkRegion& b) {
|
|
|
|
SkRegion result;
|
|
|
|
return result.op(a, b.getBounds(), SkRegion::kDifference_Op);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool diffrectbig_proc(SkRegion& a, SkRegion& b) {
|
|
|
|
SkRegion result;
|
|
|
|
return result.op(a, a.getBounds(), SkRegion::kDifference_Op);
|
|
|
|
}
|
|
|
|
|
2012-05-02 16:45:36 +00:00
|
|
|
static bool containsrect_proc(SkRegion& a, SkRegion& b) {
|
2012-04-30 12:07:55 +00:00
|
|
|
SkIRect r = a.getBounds();
|
2012-04-27 19:29:52 +00:00
|
|
|
r.inset(r.width()/4, r.height()/4);
|
2012-04-30 12:07:55 +00:00
|
|
|
(void)a.contains(r);
|
|
|
|
|
|
|
|
r = b.getBounds();
|
|
|
|
r.inset(r.width()/4, r.height()/4);
|
2012-04-30 13:54:36 +00:00
|
|
|
return b.contains(r);
|
2012-04-27 19:29:52 +00:00
|
|
|
}
|
|
|
|
|
2012-05-02 17:20:02 +00:00
|
|
|
static bool sectsrgn_proc(SkRegion& a, SkRegion& b) {
|
2012-04-27 19:29:52 +00:00
|
|
|
return a.intersects(b);
|
|
|
|
}
|
|
|
|
|
2012-05-02 17:20:02 +00:00
|
|
|
static bool sectsrect_proc(SkRegion& a, SkRegion& b) {
|
|
|
|
SkIRect r = a.getBounds();
|
|
|
|
r.inset(r.width()/4, r.height()/4);
|
2012-05-02 17:41:13 +00:00
|
|
|
return a.intersects(r);
|
2012-05-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2012-04-30 12:07:55 +00:00
|
|
|
static bool containsxy_proc(SkRegion& a, SkRegion& b) {
|
|
|
|
const SkIRect& r = a.getBounds();
|
|
|
|
const int dx = r.width() / 8;
|
|
|
|
const int dy = r.height() / 8;
|
|
|
|
for (int y = r.fTop; y < r.fBottom; y += dy) {
|
|
|
|
for (int x = r.fLeft; x < r.fRight; x += dx) {
|
|
|
|
(void)a.contains(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class RegionBench : public Benchmark {
|
2012-04-27 19:29:52 +00:00
|
|
|
public:
|
|
|
|
typedef bool (*Proc)(SkRegion& a, SkRegion& b);
|
|
|
|
|
|
|
|
SkRegion fA, fB;
|
|
|
|
Proc fProc;
|
|
|
|
SkString fName;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-04-27 19:29:52 +00:00
|
|
|
enum {
|
|
|
|
W = 1024,
|
|
|
|
H = 768,
|
|
|
|
};
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkIRect randrect(SkRandom& rand) {
|
2012-04-27 19:29:52 +00:00
|
|
|
int x = rand.nextU() % W;
|
|
|
|
int y = rand.nextU() % H;
|
|
|
|
int w = rand.nextU() % W;
|
|
|
|
int h = rand.nextU() % H;
|
|
|
|
return SkIRect::MakeXYWH(x, y, w >> 1, h >> 1);
|
|
|
|
}
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
RegionBench(int count, Proc proc, const char name[]) {
|
2012-04-27 19:29:52 +00:00
|
|
|
fProc = proc;
|
2012-04-30 14:43:46 +00:00
|
|
|
fName.printf("region_%s_%d", name, count);
|
2012-04-27 19:29:52 +00:00
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-04-30 12:07:55 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
fA.op(randrect(rand), SkRegion::kXOR_Op);
|
|
|
|
fB.op(randrect(rand), SkRegion::kXOR_Op);
|
2012-04-27 19:29:52 +00:00
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
|
|
return backend == kNonRendering_Backend;
|
2012-04-27 19:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() { return fName.c_str(); }
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas* canvas) {
|
2012-04-27 19:29:52 +00:00
|
|
|
Proc proc = fProc;
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-04-27 19:29:52 +00:00
|
|
|
proc(fA, fB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-04-27 19:29:52 +00:00
|
|
|
};
|
|
|
|
|
2014-01-01 20:32:45 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-04-30 12:07:55 +00:00
|
|
|
#define SMALL 16
|
2012-04-27 19:29:52 +00:00
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, union_proc, "union")); )
|
|
|
|
DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sect_proc, "intersect")); )
|
|
|
|
DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diff_proc, "difference")); )
|
|
|
|
DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diffrect_proc, "differencerect")); )
|
|
|
|
DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, diffrectbig_proc, "differencerectbig")); )
|
|
|
|
DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, containsrect_proc, "containsrect")); )
|
|
|
|
DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sectsrgn_proc, "intersectsrgn")); )
|
|
|
|
DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, sectsrect_proc, "intersectsrect")); )
|
|
|
|
DEF_BENCH( return SkNEW_ARGS(RegionBench, (SMALL, containsxy_proc, "containsxy")); )
|