Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
62 SkPath path;
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}
71 SkPath path;
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}
80 SkPath path;
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}
89 SkPath path;
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);)
#define DEF_BENCH(code)
Definition Benchmark.h:20
const char * backend
static SkPoint rand_pt(SkRandom &rand)
static const SkScalar Y
static SkPath cubic_path_maker()
static SkPath quad_path_maker()
static const int N
static SkPath conic_path_maker()
static const SkScalar X
static SkPaint paint_maker()
static SkPath line_path_maker()
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
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
void onDraw(int loops, SkCanvas *canvas) override
StrokeBench(const SkPath &path, const SkPaint &paint, const char pathType[], SkScalar res)
const char * onGetName() override
const Paint & paint
float SkScalar
Definition extension.cpp:12
GAsyncResult * result
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)
static constexpr SkPoint Make(float x, float y)