Flutter Engine
The Flutter Engine
StrokeBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 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/SkPath.h"
13#include "src/base/SkRandom.h"
14
15class StrokeBench : public Benchmark {
16public:
17 StrokeBench(const SkPath& path, const SkPaint& paint, const char pathType[], SkScalar res)
18 : fPath(path), fPaint(paint), fRes(res)
19 {
20 fName.printf("build_stroke_%s_%g_%d_%d",
21 pathType, paint.getStrokeWidth(), paint.getStrokeJoin(), paint.getStrokeCap());
22 }
23
24protected:
25 bool isSuitableFor(Backend backend) override {
27 }
28
29 const char* onGetName() override { return fName.c_str(); }
30
31 void onDraw(int loops, SkCanvas* canvas) override {
32 SkPaint paint(fPaint);
33 this->setupPaint(&paint);
34
35 for (int outer = 0; outer < 10; ++outer) {
36 for (int i = 0; i < loops; ++i) {
38 skpathutils::FillPathWithPaint(fPath, paint, &result, nullptr, fRes);
39 }
40 }
41 }
42
43private:
44 SkPath fPath;
45 SkPaint fPaint;
46 SkString fName;
47 SkScalar fRes;
48 using INHERITED = Benchmark;
49};
50
51///////////////////////////////////////////////////////////////////////////////
52
53static const int N = 100;
54static const SkScalar X = 100;
55static const SkScalar Y = 100;
56
57static SkPoint rand_pt(SkRandom& rand) {
58 return SkPoint::Make(rand.nextSScalar1() * X, rand.nextSScalar1() * Y);
59}
60
63 SkRandom rand;
64 path.moveTo(rand_pt(rand));
65 for (int i = 0; i < N; ++i) {
66 path.lineTo(rand_pt(rand));
67 }
68 return path;
69}
72 SkRandom rand;
73 path.moveTo(rand_pt(rand));
74 for (int i = 0; i < N; ++i) {
75 path.quadTo(rand_pt(rand), rand_pt(rand));
76 }
77 return path;
78}
81 SkRandom rand;
82 path.moveTo(rand_pt(rand));
83 for (int i = 0; i < N; ++i) {
84 path.conicTo(rand_pt(rand), rand_pt(rand), rand.nextUScalar1());
85 }
86 return path;
87}
90 SkRandom rand;
91 path.moveTo(rand_pt(rand));
92 for (int i = 0; i < N; ++i) {
93 path.cubicTo(rand_pt(rand), rand_pt(rand), rand_pt(rand));
94 }
95 return path;
96}
97
101 paint.setStrokeWidth(X / 10);
102 paint.setStrokeJoin(SkPaint::kMiter_Join);
103 paint.setStrokeCap(SkPaint::kSquare_Cap);
104 return paint;
105}
106
107DEF_BENCH(return new StrokeBench(line_path_maker(), paint_maker(), "line_1", 1);)
108DEF_BENCH(return new StrokeBench(quad_path_maker(), paint_maker(), "quad_1", 1);)
109DEF_BENCH(return new StrokeBench(conic_path_maker(), paint_maker(), "conic_1", 1);)
110DEF_BENCH(return new StrokeBench(cubic_path_maker(), paint_maker(), "cubic_1", 1);)
111
112DEF_BENCH(return new StrokeBench(line_path_maker(), paint_maker(), "line_4", 4);)
113DEF_BENCH(return new StrokeBench(quad_path_maker(), paint_maker(), "quad_4", 4);)
114DEF_BENCH(return new StrokeBench(conic_path_maker(), paint_maker(), "conic_4", 4);)
115DEF_BENCH(return new StrokeBench(cubic_path_maker(), paint_maker(), "cubic_4", 4);)
116
117DEF_BENCH(return new StrokeBench(line_path_maker(), paint_maker(), "line_.25", .25f);)
118DEF_BENCH(return new StrokeBench(quad_path_maker(), paint_maker(), "quad_.25", .25f);)
119DEF_BENCH(return new StrokeBench(conic_path_maker(), paint_maker(), "conic_.25", .25f);)
120DEF_BENCH(return new StrokeBench(cubic_path_maker(), paint_maker(), "cubic_.25", .25f);)
const char * backend
static SkPoint rand_pt(SkRandom &rand)
Definition: StrokeBench.cpp:57
static const SkScalar Y
Definition: StrokeBench.cpp:55
static SkPath cubic_path_maker()
Definition: StrokeBench.cpp:88
DEF_BENCH(return new StrokeBench(line_path_maker(), paint_maker(), "line_1", 1);) DEF_BENCH(return new StrokeBench(quad_path_maker()
static SkPath quad_path_maker()
Definition: StrokeBench.cpp:70
static const int N
Definition: StrokeBench.cpp:53
static SkPath conic_path_maker()
Definition: StrokeBench.cpp:79
static const SkScalar X
Definition: StrokeBench.cpp:54
static SkPaint paint_maker()
Definition: StrokeBench.cpp:98
static SkPath line_path_maker()
Definition: StrokeBench.cpp:61
virtual void setupPaint(SkPaint *paint)
Definition: Benchmark.cpp:55
@ kSquare_Cap
adds square
Definition: SkPaint.h:336
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kMiter_Join
extends to miter limit
Definition: SkPaint.h:359
Definition: SkPath.h:59
SkScalar nextUScalar1()
Definition: SkRandom.h:101
SkScalar nextSScalar1()
Definition: SkRandom.h:113
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
const char * c_str() const
Definition: SkString.h:133
bool isSuitableFor(Backend backend) override
Definition: StrokeBench.cpp:25
void onDraw(int loops, SkCanvas *canvas) override
Definition: StrokeBench.cpp:31
StrokeBench(const SkPath &path, const SkPaint &paint, const char pathType[], SkScalar res)
Definition: StrokeBench.cpp:17
const char * onGetName() override
Definition: StrokeBench.cpp:29
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
GAsyncResult * result
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
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)
Definition: SkPathUtils.cpp:23
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173