Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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) {
15}
16
17static bool sect_proc(SkRegion& a, SkRegion& b) {
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
101 bool isSuitableFor(Backend backend) override {
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
#define SMALL
static bool diff_proc(SkRegion &a, SkRegion &b)
static bool diffrect_proc(SkRegion &a, SkRegion &b)
static bool containsrect_proc(SkRegion &a, SkRegion &b)
static bool union_proc(SkRegion &a, SkRegion &b)
static bool diffrectbig_proc(SkRegion &a, SkRegion &b)
static bool sect_proc(SkRegion &a, SkRegion &b)
static bool sectsrect_proc(SkRegion &a, SkRegion &b)
static bool sectsrgn_proc(SkRegion &a, SkRegion &b)
static bool containsxy_proc(SkRegion &a, SkRegion &b)
bool isSuitableFor(Backend backend) override
SkString fName
const char * onGetName() override
SkIRect randrect(SkRandom &rand)
RegionBench(int count, Proc proc, const char name[])
void onDraw(int loops, SkCanvas *canvas) override
bool(* Proc)(SkRegion &a, SkRegion &b)
SkRegion fB
SkRegion fA
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
const char * name
Definition fuchsia.cc:50
double y
double x
SkScalar w
SkScalar h
Definition SkMD5.cpp:130
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