Flutter Engine
The Flutter Engine
RegionContainBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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
8#include "bench/Benchmark.h"
11#include "src/base/SkRandom.h"
12
13static bool sect_proc(SkRegion& a, SkRegion& b) {
15 return result.op(a, b, SkRegion::kIntersect_Op);
16}
17
19public:
20 typedef bool (*Proc)(SkRegion& a, SkRegion& b);
24
25 enum {
26 W = 200,
27 H = 200,
28 COUNT = 10,
29 };
30
31 SkIRect randrect(SkRandom& rand, int i) {
32 int w = rand.nextU() % W;
33 return SkIRect::MakeXYWH(0, i*H/COUNT, w, H/COUNT);
34 }
35
36 RegionContainBench(Proc proc, const char name[]) {
37 fProc = proc;
38 fName.printf("region_contains_%s", name);
39
40 SkRandom rand;
41 for (int i = 0; i < COUNT; i++) {
43 }
44
45 fB.setRect({0, 0, H, W});
46 }
47
48 bool isSuitableFor(Backend backend) override {
50 }
51
52protected:
53 const char* onGetName() override { return fName.c_str(); }
54
55 void onDraw(int loops, SkCanvas*) override {
56 Proc proc = fProc;
57
58 for (int i = 0; i < loops; ++i) {
59 proc(fA, fB);
60 }
61 }
62
63private:
64 using INHERITED = Benchmark;
65};
66
67DEF_BENCH(return new RegionContainBench(sect_proc, "sect");)
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * backend
static bool sect_proc(SkRegion &a, SkRegion &b)
bool(* Proc)(SkRegion &a, SkRegion &b)
bool isSuitableFor(Backend backend) override
RegionContainBench(Proc proc, const char name[])
SkIRect randrect(SkRandom &rand, int i)
void onDraw(int loops, SkCanvas *) override
const char * onGetName() override
uint32_t nextU()
Definition: SkRandom.h:42
@ kIntersect_Op
target intersected with operand
Definition: SkRegion.h:368
@ kXOR_Op
target exclusive or with operand
Definition: SkRegion.h:370
bool op(const SkIRect &rect, Op op)
Definition: SkRegion.h:384
bool setRect(const SkIRect &rect)
Definition: SkRegion.cpp:192
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
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
SkScalar w
Definition: SkMD5.cpp:130
Definition: SkRect.h:32
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104