Flutter Engine
The Flutter Engine
BezierBench.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"
11#include "include/core/SkPath.h"
13
14struct BezierRec {
19};
20
21typedef const char* (*DrawProc)(const BezierRec*, int);
22
23static const char* draw_quad(const BezierRec* rec, int count) {
24 if (rec) {
25 SkCanvas* canvas = rec->fCanvas;
26 const SkPaint& paint = rec->fPaint;
27 const SkPath& path = rec->fQuad;
28 for (int i = 0; i < count; ++i) {
29 canvas->drawPath(path, paint);
30 }
31 }
32 return "quad";
33}
34
35static const char* draw_cubic(const BezierRec* rec, int count) {
36 if (rec) {
37 SkCanvas* canvas = rec->fCanvas;
38 const SkPaint& paint = rec->fPaint;
39 const SkPath& path = rec->fCubic;
40 for (int i = 0; i < count; ++i) {
41 canvas->drawPath(path, paint);
42 }
43 }
44 return "cubic";
45}
46
47class BezierBench : public Benchmark {
48 SkString fName;
49 SkPaint::Cap fCap;
50 SkPaint::Join fJoin;
51 BezierRec fRec;
52 DrawProc fProc;
53 SkScalar fWidth;
54public:
56 static const char* gCapName[] = {
57 "butt", "round", "square"
58 };
59 static const char* gJoinName[] = {
60 "miter", "round", "bevel"
61 };
62
63 fCap = c;
64 fJoin = j;
65 fProc = proc;
66 fWidth = SkIntToScalar(w);
67 fName.printf("draw_stroke_bezier_%s_%s_%s_%g", proc(nullptr, 0), gCapName[c], gJoinName[j], w);
68
69 fRec.fQuad.moveTo(20, 20);
70 fRec.fQuad.quadTo(60, 20, 60, 60);
71 fRec.fQuad.quadTo(20, 60, 20, 100);
72 fRec.fCubic.moveTo(20, 20);
73 fRec.fCubic.cubicTo(40, 20, 60, 40, 60, 60);
74 fRec.fCubic.cubicTo(40, 60, 20, 80, 20, 100);
75 }
76
77protected:
78 const char* onGetName() override {
79 return fName.c_str();
80 }
81
82 void onDraw(int loops, SkCanvas* canvas) override {
83 fRec.fCanvas = canvas;
84 this->setupPaint(&fRec.fPaint);
86 fRec.fPaint.setStrokeCap(fCap);
88 fRec.fPaint.setStrokeWidth(fWidth);
89 fProc(&fRec, loops);
90 }
91
92private:
93 using INHERITED = Benchmark;
94};
95
99
SkPaint::Join fJoin
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char *(* DrawProc)(const BezierRec *, int)
Definition: BezierBench.cpp:21
static const char * draw_cubic(const BezierRec *rec, int count)
Definition: BezierBench.cpp:35
static const char * draw_quad(const BezierRec *rec, int count)
Definition: BezierBench.cpp:23
const char * fName
int count
Definition: FontMgrTest.cpp:50
IsFiniteProc fProc
Definition: MathBench.cpp:219
#define SkIntToScalar(x)
Definition: SkScalar.h:57
virtual void setupPaint(SkPaint *paint)
Definition: Benchmark.cpp:55
void onDraw(int loops, SkCanvas *canvas) override
Definition: BezierBench.cpp:82
const char * onGetName() override
Definition: BezierBench.cpp:78
BezierBench(SkPaint::Cap c, SkPaint::Join j, SkScalar w, DrawProc proc)
Definition: BezierBench.cpp:55
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
@ kButt_Cap
no stroke extension
Definition: SkPaint.h:334
@ kSquare_Cap
adds square
Definition: SkPaint.h:336
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setStrokeCap(Cap cap)
Definition: SkPaint.cpp:179
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeJoin(Join join)
Definition: SkPaint.cpp:189
@ kRound_Join
adds circle
Definition: SkPaint.h:360
@ kMiter_Join
extends to miter limit
Definition: SkPaint.h:359
@ kBevel_Join
connects outside edges
Definition: SkPaint.h:361
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
Definition: SkPath.h:59
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
SkPath & quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
Definition: SkPath.cpp:746
SkPath & cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
Definition: SkPath.cpp:799
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
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
SkScalar w
SkCanvas * fCanvas
Definition: BezierBench.cpp:15
SkPath fCubic
Definition: BezierBench.cpp:18
SkPaint fPaint
Definition: BezierBench.cpp:16
SkPath fQuad
Definition: BezierBench.cpp:17