Flutter Engine
The Flutter Engine
GeometryBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 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"
10#include "include/core/SkRect.h"
11#include "src/base/SkRandom.h"
12#include "src/core/SkGeometry.h"
13#include "src/core/SkPathPriv.h"
14
15class GeometryBench : public Benchmark {
16public:
17 GeometryBench(const char suffix[]) : fVolatileInt(0) {
18 fName.printf("geo_%s", suffix);
19 }
20
21 const char* onGetName() override {
22 return fName.c_str();
23 }
24
25 bool isSuitableFor(Backend backend) override {
27 }
28
29protected:
30 volatile int fVolatileInt;
31
32 /**
33 * Subclasses can call this to try to defeat the optimizer (with some result of their
34 * inner loop), since it will fool the compiler into assuming that "n" is actually
35 * needed somewhere, and since this method is not const, the member fields cannot
36 * be assumed to be const before and after the call.
37 */
38 virtual void virtualCallToFoilOptimizers(int n) {
39 fVolatileInt = n;
40 }
41
42private:
43 SkString fName;
44};
45
47public:
49
50protected:
52
53 void onDelayedSetup() override {
54 const SkScalar min = -100;
55 const SkScalar max = 100;
56 SkRandom rand;
57 for (size_t i = 0; i < std::size(fRects); ++i) {
62 fRects[i].setXYWH(x, y, w, h);
63 }
64 }
65};
66
68public:
69 GeoRectBench_intersect() : GeoRectBench("rect_intersect") {}
70
71protected:
72 void onDraw(int loops, SkCanvas* canvas) override {
73 for (int outer = 0; outer < loops; ++outer) {
74 int count = 0;
75 for (size_t i = 0; i < std::size(fRects); ++i) {
76 SkRect r = fRects[0];
77 count += r.intersect(fRects[i]);
78 }
79 this->virtualCallToFoilOptimizers(count);
80 }
81 }
82};
83
85public:
86 GeoRectBench_intersect_rect() : GeoRectBench("rect_intersect_rect") {}
87
88protected:
89 void onDraw(int loops, SkCanvas* canvas) override {
90 for (int outer = 0; outer < loops; ++outer) {
91 int count = 0;
92 SkRect r;
93 for (size_t i = 0; i < std::size(fRects); ++i) {
94 count += r.intersect(fRects[0], fRects[i]);
95 }
96 this->virtualCallToFoilOptimizers(count);
97 }
98 }
99};
100
102public:
103 GeoRectBench_Intersects() : GeoRectBench("rect_Intersects") {}
104
105protected:
106 void onDraw(int loops, SkCanvas* canvas) override {
107 for (int outer = 0; outer < loops; ++outer) {
108 int count = 0;
109 for (size_t i = 0; i < std::size(fRects); ++i) {
110 count += SkRect::Intersects(fRects[0], fRects[i]);
111 }
112 this->virtualCallToFoilOptimizers(count);
113 }
114 }
115};
116
118public:
119 GeoRectBench_sort() : GeoRectBench("rect_sort") {}
120
121protected:
122 void onDraw(int loops, SkCanvas* canvas) override {
123 for (int outer = 0; outer < loops; ++outer) {
124 for (size_t i = 0; i < std::size(fRects); ++i) {
125 fRects[i].sort();
126 }
127 }
128 }
129};
130
134
135DEF_BENCH( return new GeoRectBench_sort; )
136
137///////////////////////////////////////////////////////////////////////////////////////////////////
138
140protected:
142public:
144 SkRandom rand;
145 for (int i = 0; i < 4; ++i) {
146 fPts[i].set(rand.nextUScalar1(), rand.nextUScalar1());
147 }
148 }
149};
150
152public:
153 EvalQuadAt0() : QuadBenchBase("evalquadat0") {}
154protected:
155 void onDraw(int loops, SkCanvas* canvas) override {
157 for (int outer = 0; outer < loops; ++outer) {
158 SkEvalQuadAt(fPts, 0.5f, &result);
159 SkEvalQuadAt(fPts, 0.5f, &result);
160 SkEvalQuadAt(fPts, 0.5f, &result);
161 SkEvalQuadAt(fPts, 0.5f, &result);
162 }
163 }
164};
165DEF_BENCH( return new EvalQuadAt0; )
166
168public:
169 EvalQuadAt1() : QuadBenchBase("evalquadat1") {}
170protected:
171 void onDraw(int loops, SkCanvas* canvas) override {
173 for (int outer = 0; outer < loops; ++outer) {
174 result = SkEvalQuadAt(fPts, 0.5f);
175 result = SkEvalQuadAt(fPts, 0.5f);
176 result = SkEvalQuadAt(fPts, 0.5f);
177 result = SkEvalQuadAt(fPts, 0.5f);
178 }
179 }
180};
181DEF_BENCH( return new EvalQuadAt1; )
182
183////////
184
186public:
187 EvalQuadTangentAt0() : QuadBenchBase("evalquadtangentat0") {}
188protected:
189 void onDraw(int loops, SkCanvas* canvas) override {
191 for (int outer = 0; outer < loops; ++outer) {
192 SkEvalQuadAt(fPts, 0.5f, nullptr, &result);
193 SkEvalQuadAt(fPts, 0.5f, nullptr, &result);
194 SkEvalQuadAt(fPts, 0.5f, nullptr, &result);
195 SkEvalQuadAt(fPts, 0.5f, nullptr, &result);
196 }
197 }
198};
199DEF_BENCH( return new EvalQuadTangentAt0; )
200
202public:
203 EvalQuadTangentAt1() : QuadBenchBase("evalquadtangentat1") {}
204protected:
205 void onDraw(int loops, SkCanvas* canvas) override {
207 for (int outer = 0; outer < loops; ++outer) {
212 }
213 }
214};
215DEF_BENCH( return new EvalQuadTangentAt1; )
216
217////////
218
219class ChopQuadAt : public QuadBenchBase {
220public:
221 ChopQuadAt() : QuadBenchBase("chopquadat") {}
222protected:
223 void onDraw(int loops, SkCanvas* canvas) override {
224 SkPoint dst[5];
225 for (int outer = 0; outer < loops; ++outer) {
226 SkChopQuadAt(fPts, dst, 0.5f);
227 SkChopQuadAt(fPts, dst, 0.5f);
228 SkChopQuadAt(fPts, dst, 0.5f);
229 SkChopQuadAt(fPts, dst, 0.5f);
230 }
231 }
232};
233DEF_BENCH( return new ChopQuadAt; )
234
236public:
237 ChopCubicAt() : QuadBenchBase("chopcubicat0") {}
238protected:
239 void onDraw(int loops, SkCanvas* canvas) override {
240 SkPoint dst[7];
241 for (int outer = 0; outer < loops; ++outer) {
242 SkChopCubicAt(fPts, dst, 0.5f);
243 SkChopCubicAt(fPts, dst, 0.5f);
244 SkChopCubicAt(fPts, dst, 0.5f);
245 SkChopCubicAt(fPts, dst, 0.5f);
246 }
247 }
248};
249DEF_BENCH( return new ChopCubicAt; )
250
251#include "include/core/SkPath.h"
252
253class ConvexityBench : public Benchmark {
255
256public:
257 ConvexityBench(const char suffix[]) {
258 fName.printf("convexity_%s", suffix);
259 }
260
261 const char* onGetName() override {
262 return fName.c_str();
263 }
264
266 return Backend::kNonRendering == backend;
267 }
268
269 virtual void preparePath(SkPath*) = 0;
270
271protected:
272 void onPreDraw(SkCanvas*) override {
273 this->preparePath(&fPath);
274 }
275
276 void onDraw(int loops, SkCanvas* canvas) override {
277 for (int i = 0; i < loops; ++i) {
279 }
280 }
281
282private:
284};
285
287public:
289
290 void preparePath(SkPath* path) override {
291 SkRRect rr;
292 rr.setRectXY({0, 0, 100, 100}, 20, 30);
293 path->addRRect(rr);
294 }
295};
296DEF_BENCH( return new RRectConvexityBench; )
297
SkPoint fPts[2]
SkPath fPath
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * backend
const char * fName
int count
Definition: FontMgrTest.cpp:50
void SkChopQuadAt(const SkPoint src[3], SkPoint dst[5], SkScalar t)
Definition: SkGeometry.cpp:175
void SkChopCubicAt(const SkPoint src[4], SkPoint dst[7], SkScalar t)
Definition: SkGeometry.cpp:473
SkVector SkEvalQuadTangentAt(const SkPoint src[3], SkScalar t)
Definition: SkGeometry.cpp:148
void SkEvalQuadAt(const SkPoint src[3], SkScalar t, SkPoint *pt, SkVector *tangent)
Definition: SkGeometry.cpp:132
void onDraw(int loops, SkCanvas *canvas) override
void onDraw(int loops, SkCanvas *canvas) override
ConvexityBench(const char suffix[])
void onDraw(int loops, SkCanvas *canvas) override
const char * onGetName() override
void onPreDraw(SkCanvas *) override
virtual void preparePath(SkPath *)=0
bool isSuitableFor(Backend backend) override
void onDraw(int loops, SkCanvas *canvas) override
void onDraw(int loops, SkCanvas *canvas) override
void onDraw(int loops, SkCanvas *canvas) override
void onDraw(int loops, SkCanvas *canvas) override
void onDraw(int loops, SkCanvas *canvas) override
void onDraw(int loops, SkCanvas *canvas) override
void onDraw(int loops, SkCanvas *canvas) override
void onDraw(int loops, SkCanvas *canvas) override
void onDelayedSetup() override
GeoRectBench(const char suffix[])
SkRect fRects[2048]
bool isSuitableFor(Backend backend) override
GeometryBench(const char suffix[])
const char * onGetName() override
virtual void virtualCallToFoilOptimizers(int n)
volatile int fVolatileInt
QuadBenchBase(const char name[])
SkPoint fPts[4]
void preparePath(SkPath *path) override
static void ForceComputeConvexity(const SkPath &path)
Definition: SkPathPriv.h:416
Definition: SkPath.h:59
void setRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition: SkRRect.cpp:52
SkScalar nextUScalar1()
Definition: SkRandom.h:101
SkScalar nextRangeScalar(SkScalar min, SkScalar max)
Definition: SkRandom.h:106
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
const char * c_str() const
Definition: SkString.h:133
float SkScalar
Definition: extension.cpp:12
GAsyncResult * result
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48
double y
double x
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
dst
Definition: cp.py:12
SkScalar w
SkScalar h
void set(float x, float y)
Definition: SkPoint_impl.h:200
void setXYWH(float x, float y, float width, float height)
Definition: SkRect.h:931
bool intersect(const SkRect &r)
Definition: SkRect.cpp:114
void sort()
Definition: SkRect.h:1313