Flutter Engine
The Flutter Engine
RegionBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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#include "bench/Benchmark.h"
10#include "src/base/SkRandom.h"
11
12static bool union_proc(SkRegion& a, SkRegion& b) {
14 return result.op(a, b, SkRegion::kUnion_Op);
15}
16
17static bool sect_proc(SkRegion& a, SkRegion& b) {
19 return result.op(a, b, SkRegion::kIntersect_Op);
20}
21
22static bool diff_proc(SkRegion& a, SkRegion& b) {
25}
26
29 return result.op(a, b.getBounds(), SkRegion::kDifference_Op);
30}
31
34 return result.op(a, a.getBounds(), SkRegion::kDifference_Op);
35}
36
38 SkIRect r = a.getBounds();
39 r.inset(r.width()/4, r.height()/4);
40 (void)a.contains(r);
41
42 r = b.getBounds();
43 r.inset(r.width()/4, r.height()/4);
44 return b.contains(r);
45}
46
48 return a.intersects(b);
49}
50
52 SkIRect r = a.getBounds();
53 r.inset(r.width()/4, r.height()/4);
54 return a.intersects(r);
55}
56
58 const SkIRect& r = a.getBounds();
59 const int dx = r.width() / 8;
60 const int dy = r.height() / 8;
61 for (int y = r.fTop; y < r.fBottom; y += dy) {
62 for (int x = r.fLeft; x < r.fRight; x += dx) {
63 (void)a.contains(x, y);
64 }
65 }
66 return true;
67}
68
69class RegionBench : public Benchmark {
70public:
71 typedef bool (*Proc)(SkRegion& a, SkRegion& b);
72
76
77 enum {
78 W = 1024,
79 H = 768,
80 };
81
83 int x = rand.nextU() % W;
84 int y = rand.nextU() % H;
85 int w = rand.nextU() % W;
86 int h = rand.nextU() % H;
87 return SkIRect::MakeXYWH(x, y, w >> 1, h >> 1);
88 }
89
90 RegionBench(int count, Proc proc, const char name[]) {
91 fProc = proc;
92 fName.printf("region_%s_%d", name, count);
93
94 SkRandom rand;
95 for (int i = 0; i < count; i++) {
98 }
99 }
100
103 }
104
105protected:
106 const char* onGetName() override { return fName.c_str(); }
107
108 void onDraw(int loops, SkCanvas* canvas) override {
109 Proc proc = fProc;
110 for (int i = 0; i < loops; ++i) {
111 proc(fA, fB);
112 }
113 }
114
115private:
116 using INHERITED = Benchmark;
117};
118
119///////////////////////////////////////////////////////////////////////////////
120
121#define SMALL 16
122
123DEF_BENCH(return new RegionBench(SMALL, union_proc, "union");)
124DEF_BENCH(return new RegionBench(SMALL, sect_proc, "intersect");)
125DEF_BENCH(return new RegionBench(SMALL, diff_proc, "difference");)
126DEF_BENCH(return new RegionBench(SMALL, diffrect_proc, "differencerect");)
127DEF_BENCH(return new RegionBench(SMALL, diffrectbig_proc, "differencerectbig");)
128DEF_BENCH(return new RegionBench(SMALL, containsrect_proc, "containsrect");)
129DEF_BENCH(return new RegionBench(SMALL, sectsrgn_proc, "intersectsrgn");)
130DEF_BENCH(return new RegionBench(SMALL, sectsrect_proc, "intersectsrect");)
131DEF_BENCH(return new RegionBench(SMALL, containsxy_proc, "containsxy");)
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * backend
int count
Definition: FontMgrTest.cpp:50
#define SMALL
static bool diff_proc(SkRegion &a, SkRegion &b)
Definition: RegionBench.cpp:22
static bool diffrect_proc(SkRegion &a, SkRegion &b)
Definition: RegionBench.cpp:27
static bool containsrect_proc(SkRegion &a, SkRegion &b)
Definition: RegionBench.cpp:37
static bool union_proc(SkRegion &a, SkRegion &b)
Definition: RegionBench.cpp:12
static bool diffrectbig_proc(SkRegion &a, SkRegion &b)
Definition: RegionBench.cpp:32
static bool sect_proc(SkRegion &a, SkRegion &b)
Definition: RegionBench.cpp:17
static bool sectsrect_proc(SkRegion &a, SkRegion &b)
Definition: RegionBench.cpp:51
static bool sectsrgn_proc(SkRegion &a, SkRegion &b)
Definition: RegionBench.cpp:47
static bool containsxy_proc(SkRegion &a, SkRegion &b)
Definition: RegionBench.cpp:57
bool isSuitableFor(Backend backend) override
SkString fName
Definition: RegionBench.cpp:75
const char * onGetName() override
SkIRect randrect(SkRandom &rand)
Definition: RegionBench.cpp:82
RegionBench(int count, Proc proc, const char name[])
Definition: RegionBench.cpp:90
void onDraw(int loops, SkCanvas *canvas) override
bool(* Proc)(SkRegion &a, SkRegion &b)
Definition: RegionBench.cpp:71
SkRegion fB
Definition: RegionBench.cpp:73
SkRegion fA
Definition: RegionBench.cpp:73
uint32_t nextU()
Definition: SkRandom.h:42
@ kUnion_Op
target unioned with operand
Definition: SkRegion.h:369
@ kIntersect_Op
target intersected with operand
Definition: SkRegion.h:368
@ kDifference_Op
target minus operand
Definition: SkRegion.h:367
@ kXOR_Op
target exclusive or with operand
Definition: SkRegion.h:370
bool op(const SkIRect &rect, Op op)
Definition: SkRegion.h:384
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
const char * c_str() const
Definition: SkString.h:133
static bool b
struct MyStruct a[10]
GAsyncResult * result
double y
double x
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
SkScalar w
SkScalar h
Definition: SkMD5.cpp:130
Definition: SkRect.h:32
void inset(int32_t dx, int32_t dy)
Definition: SkRect.h:411
int32_t fBottom
larger y-axis bounds
Definition: SkRect.h:36
constexpr int32_t height() const
Definition: SkRect.h:165
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
constexpr int32_t width() const
Definition: SkRect.h:158
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition: SkRect.h:35