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.
|
|
|
|
*/
|
|
|
|
#include "SkBenchmark.h"
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2012-04-27 19:29:52 +00:00
|
|
|
class RegionBench : public SkBenchmark {
|
|
|
|
public:
|
|
|
|
typedef bool (*Proc)(SkRegion& a, SkRegion& b);
|
|
|
|
|
|
|
|
SkRegion fA, fB;
|
|
|
|
Proc fProc;
|
|
|
|
SkString fName;
|
2012-05-02 16:56:49 +00:00
|
|
|
int fLoopMul;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-04-27 19:29:52 +00:00
|
|
|
enum {
|
|
|
|
W = 1024,
|
|
|
|
H = 768,
|
2012-04-30 12:07:55 +00:00
|
|
|
N = SkBENCHLOOP(2000)
|
2012-04-27 19:29:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SkIRect randrect(SkRandom& rand) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-05-02 16:56:49 +00:00
|
|
|
RegionBench(void* param, int count, Proc proc, const char name[], int mul = 1) : INHERITED(param) {
|
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-05-02 16:56:49 +00:00
|
|
|
fLoopMul = mul;
|
2012-04-27 19:29:52 +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
|
|
|
}
|
2012-09-13 15:50:24 +00:00
|
|
|
fIsRendering = false;
|
2012-04-27 19:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() { return fName.c_str(); }
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
Proc proc = fProc;
|
2012-05-02 16:56:49 +00:00
|
|
|
int n = fLoopMul * N;
|
|
|
|
for (int i = 0; i < n; ++i) {
|
2012-04-27 19:29:52 +00:00
|
|
|
proc(fA, fB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-04-30 12:07:55 +00:00
|
|
|
#define SMALL 16
|
2012-04-27 19:29:52 +00:00
|
|
|
|
|
|
|
static SkBenchmark* gF0(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, union_proc, "union")); }
|
|
|
|
static SkBenchmark* gF1(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, sect_proc, "intersect")); }
|
|
|
|
static SkBenchmark* gF2(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, diff_proc, "difference")); }
|
2012-05-31 18:28:59 +00:00
|
|
|
static SkBenchmark* gF3(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, diffrect_proc, "differencerect")); }
|
|
|
|
static SkBenchmark* gF4(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, diffrectbig_proc, "differencerectbig")); }
|
|
|
|
static SkBenchmark* gF5(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, containsrect_proc, "containsrect", 100)); }
|
|
|
|
static SkBenchmark* gF6(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, sectsrgn_proc, "intersectsrgn", 10)); }
|
|
|
|
static SkBenchmark* gF7(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, sectsrect_proc, "intersectsrect", 200)); }
|
|
|
|
static SkBenchmark* gF8(void* p) { return SkNEW_ARGS(RegionBench, (p, SMALL, containsxy_proc, "containsxy")); }
|
2012-04-27 19:29:52 +00:00
|
|
|
|
|
|
|
static BenchRegistry gR0(gF0);
|
|
|
|
static BenchRegistry gR1(gF1);
|
|
|
|
static BenchRegistry gR2(gF2);
|
|
|
|
static BenchRegistry gR3(gF3);
|
|
|
|
static BenchRegistry gR4(gF4);
|
2012-04-30 12:07:55 +00:00
|
|
|
static BenchRegistry gR5(gF5);
|
2012-05-02 17:20:02 +00:00
|
|
|
static BenchRegistry gR6(gF6);
|
2012-05-31 18:28:59 +00:00
|
|
|
static BenchRegistry gR7(gF7);
|
|
|
|
static BenchRegistry gR8(gF8);
|