Flutter Engine
The Flutter Engine
LineBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2012 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"
16#include "src/base/SkRandom.h"
17
18
19class LineBench : public Benchmark {
20 SkScalar fStrokeWidth;
21 bool fDoAA;
22 SkString fName;
23 enum {
24 PTS = 500,
25 };
26 SkPoint fPts[PTS];
27
28public:
29 LineBench(SkScalar width, bool doAA) {
30 fStrokeWidth = width;
31 fDoAA = doAA;
32 fName.printf("lines_%g_%s", width, doAA ? "AA" : "BW");
33
34 SkRandom rand;
35 for (int i = 0; i < PTS; ++i) {
36 fPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
37 }
38 }
39
40protected:
41 const char* onGetName() override {
42 return fName.c_str();
43 }
44
45 void onDraw(int loops, SkCanvas* canvas) override {
47 this->setupPaint(&paint);
48
50 paint.setAntiAlias(fDoAA);
51 paint.setStrokeWidth(fStrokeWidth);
52
53 for (int i = 0; i < loops; i++) {
55 }
56 }
57
58private:
59 using INHERITED = Benchmark;
60};
61
62DEF_BENCH(return new LineBench(0, false);)
63DEF_BENCH(return new LineBench(SK_Scalar1, false);)
64DEF_BENCH(return new LineBench(0, true);)
65DEF_BENCH(return new LineBench(SK_Scalar1/2, true);)
66DEF_BENCH(return new LineBench(SK_Scalar1, true);)
SkPoint fPts[2]
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * fName
#define SK_Scalar1
Definition: SkScalar.h:18
virtual void setupPaint(SkPaint *paint)
Definition: Benchmark.cpp:55
LineBench(SkScalar width, bool doAA)
Definition: LineBench.cpp:29
const char * onGetName() override
Definition: LineBench.cpp:41
void onDraw(int loops, SkCanvas *canvas) override
Definition: LineBench.cpp:45
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
Definition: SkCanvas.cpp:1710
@ kLines_PointMode
draw each pair of points as a line segment
Definition: SkCanvas.h:1242
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
SkScalar nextUScalar1()
Definition: SkRandom.h:101
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
int32_t width
void set(float x, float y)
Definition: SkPoint_impl.h:200