OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 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 "Benchmark.h" | |
9 #include "SkBitmap.h" | |
10 #include "SkCanvas.h" | |
11 #include "SkColorPriv.h" | |
12 #include "SkPaint.h" | |
13 #include "SkRandom.h" | |
14 #include "SkShader.h" | |
15 #include "SkString.h" | |
16 #include "SkTArray.h" | |
17 | |
18 | |
19 class StraightLineBench : public Benchmark { | |
20 SkScalar fStrokeWidth; | |
21 bool fDoAA; | |
22 SkString fName; | |
23 enum { | |
24 LINES = 500; | |
25 }; | |
26 SkPoint fStartPts[LINES]; | |
27 SkPoint fEndPts[LINES]; | |
28 | |
29 public: | |
30 StraightLineBench(SkScalar width, bool doAA) { | |
31 fStrokeWidth = width; | |
32 fDoAA = doAA; | |
robertphillips
2016/05/02 15:33:40
I think you want this to be: straightline_%g_%s
xidachen
2016/05/02 15:54:10
Thank you, changed to straightline, and compilatio
| |
33 fName.printf("lines_%g_%s", width, doAA ? "AA" : "BW"); | |
34 | |
35 SkRandom rand; | |
36 for (int i = 0; i < LINES; ++i) { | |
37 fStartPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 48 0); | |
38 // Half of lines start straight horizontally and half of them vertic ally | |
39 if (i < LINES / 2) { | |
40 fEndPts[i].set(fStartPts[i].x(), rand.nextUScalar1() * 480); | |
41 } else { | |
42 fEndPts[i].set(rand.nextUScalar1() * 640, fStartPts[i].y()); | |
43 } | |
44 } | |
45 } | |
46 | |
47 protected: | |
48 const char* onGetName() override { | |
49 return fName.c_str(); | |
50 } | |
51 | |
52 void onDraw(int loops, SkCanvas* canvas) override { | |
53 SkPaint paint; | |
54 this->setupPaint(&paint); | |
55 | |
56 paint.setStyle(SkPaint::kStroke_Style); | |
57 paint.setAntiAlias(fDoAA); | |
58 paint.setStrokeWidth(fStrokeWidth); | |
59 | |
60 for (int i = 0; i < loops; i++) { | |
61 canvas->drawLine(fStartPts[i].x(), fStartPts[i].y(), fEndPts[i].x(), fEndPts[i].y(), paint); | |
62 } | |
63 } | |
64 | |
65 private: | |
66 typedef Benchmark INHERITED; | |
67 }; | |
68 | |
69 DEF_BENCH(return new StraightLineBench(0, false);) | |
70 DEF_BENCH(return new StraightLineBench(SK_Scalar1, false);) | |
71 DEF_BENCH(return new StraightLineBench(0, true);) | |
72 DEF_BENCH(return new StraightLineBench(SK_Scalar1/2, true);) | |
73 DEF_BENCH(return new StraightLineBench(SK_Scalar1, true);) | |
OLD | NEW |