Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: bench/LineBench.cpp

Issue 1936153002: Modify LineBench for drawing straight line (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: add change to lineBench Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Benchmark.h" 8 #include "Benchmark.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkPaint.h" 12 #include "SkPaint.h"
13 #include "SkRandom.h" 13 #include "SkRandom.h"
14 #include "SkShader.h" 14 #include "SkShader.h"
15 #include "SkString.h" 15 #include "SkString.h"
16 #include "SkTArray.h" 16 #include "SkTArray.h"
17 17
18 18
19 class LineBench : public Benchmark { 19 class LineBench : public Benchmark {
20 SkScalar fStrokeWidth; 20 SkScalar fStrokeWidth;
21 bool fDoAA; 21 bool fDoAA;
22 SkString fName; 22 SkString fName;
23 enum { 23 enum {
24 PTS = 500, 24 LINES = 500,
25 }; 25 };
26 SkPoint fPts[PTS]; 26 SkPoint fStartPts[LINES];
27 SkPoint fEndPts[LINES];
27 28
28 public: 29 public:
29 LineBench(SkScalar width, bool doAA) { 30 enum LineType {
31 SH, // Straight + horizontally
32 SV, // Straight + vertically
33 RAND,
34 };
35 LineBench(SkScalar width, bool doAA, LineType type) {
30 fStrokeWidth = width; 36 fStrokeWidth = width;
31 fDoAA = doAA; 37 fDoAA = doAA;
32 fName.printf("lines_%g_%s", width, doAA ? "AA" : "BW"); 38 fName.printf("lines_%g_%s_%s", width, doAA ? "AA" : "BW",
39 type == SH ? "SH" : (type == SV ? "SV" : "RAND"));
33 40
34 SkRandom rand; 41 SkRandom rand;
35 for (int i = 0; i < PTS; ++i) { 42 for (int i = 0; i < LINES; ++i) {
36 fPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480); 43 fStartPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 48 0);
44 if (type == SH) {
45 fEndPts[i].set(rand.nextUScalar1() * 640, fStartPts[i].y());
46 } else if (type == SV) {
47 fEndPts[i].set(fStartPts[i].x(), rand.nextUScalar1() * 480);
48 } else {
49 fEndPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
50 }
37 } 51 }
38 } 52 }
39 53
40 protected: 54 protected:
41 const char* onGetName() override { 55 const char* onGetName() override {
42 return fName.c_str(); 56 return fName.c_str();
43 } 57 }
44 58
45 void onDraw(int loops, SkCanvas* canvas) override { 59 void onDraw(int loops, SkCanvas* canvas) override {
46 SkPaint paint; 60 SkPaint paint;
47 this->setupPaint(&paint); 61 this->setupPaint(&paint);
48 62
49 paint.setStyle(SkPaint::kStroke_Style); 63 paint.setStyle(SkPaint::kStroke_Style);
50 paint.setAntiAlias(fDoAA); 64 paint.setAntiAlias(fDoAA);
51 paint.setStrokeWidth(fStrokeWidth); 65 paint.setStrokeWidth(fStrokeWidth);
52 66
53 for (int i = 0; i < loops; i++) { 67 for (int i = 0; i < loops; i++) {
54 canvas->drawPoints(SkCanvas::kLines_PointMode, PTS, fPts, paint); 68 canvas->drawLine(fStartPts[i].x(), fStartPts[i].y(), fEndPts[i].x(), fEndPts[i].y(), paint);
55 } 69 }
56 } 70 }
57 71
58 private: 72 private:
59 typedef Benchmark INHERITED; 73 typedef Benchmark INHERITED;
60 }; 74 };
61 75
62 DEF_BENCH(return new LineBench(0, false);) 76 DEF_BENCH(return new LineBench(0, false, LineBench::SH);)
63 DEF_BENCH(return new LineBench(SK_Scalar1, false);) 77 DEF_BENCH(return new LineBench(SK_Scalar1, false, LineBench::SH);)
64 DEF_BENCH(return new LineBench(0, true);) 78 DEF_BENCH(return new LineBench(0, true, LineBench::SH);)
65 DEF_BENCH(return new LineBench(SK_Scalar1/2, true);) 79 DEF_BENCH(return new LineBench(SK_Scalar1/2, true, LineBench::SH);)
66 DEF_BENCH(return new LineBench(SK_Scalar1, true);) 80 DEF_BENCH(return new LineBench(SK_Scalar1, true, LineBench::SH);)
81 DEF_BENCH(return new LineBench(SK_Scalar1*10,true, LineBench::SH);)
82 DEF_BENCH(return new LineBench(0, false, LineBench::SV);)
83 DEF_BENCH(return new LineBench(SK_Scalar1, false, LineBench::SV);)
84 DEF_BENCH(return new LineBench(0, true, LineBench::SV);)
85 DEF_BENCH(return new LineBench(SK_Scalar1/2, true, LineBench::SV);)
86 DEF_BENCH(return new LineBench(SK_Scalar1, true, LineBench::SV);)
87 DEF_BENCH(return new LineBench(SK_Scalar1*10,true, LineBench::SV);)
88 DEF_BENCH(return new LineBench(0, false, LineBench::RAND);)
89 DEF_BENCH(return new LineBench(SK_Scalar1, false, LineBench::RAND);)
90 DEF_BENCH(return new LineBench(0, true, LineBench::RAND);)
91 DEF_BENCH(return new LineBench(SK_Scalar1/2, true, LineBench::RAND);)
92 DEF_BENCH(return new LineBench(SK_Scalar1, true, LineBench::RAND);)
93 DEF_BENCH(return new LineBench(SK_Scalar1*10,true, LineBench::RAND);)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698