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

Side by Side Diff: bench/BigPathBench.cpp

Issue 909893002: add rounded-join option to bigpath bench (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 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 2015 Google Inc. 2 * Copyright 2015 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 "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkPath.h" 10 #include "SkPath.h"
11 #include "SkString.h" 11 #include "SkString.h"
12 12
13 static void make_path(SkPath& path) { 13 static void make_path(SkPath& path) {
14 #include "BigPathBench.inc" 14 #include "BigPathBench.inc"
15 } 15 }
16 16
17 enum Align { 17 enum Align {
18 kLeft_Align, 18 kLeft_Align,
19 kMiddle_Align, 19 kMiddle_Align,
20 kRight_Align 20 kRight_Align
21 }; 21 };
22 22
23 const char* gAlignName[] = { "left", "middle", "right" }; 23 const char* gAlignName[] = { "left", "middle", "right" };
24 24
25 // Inspired by crbug.com/455429 25 // Inspired by crbug.com/455429
26 class BigPathBench : public Benchmark { 26 class BigPathBench : public Benchmark {
27 SkPath fPath; 27 SkPath fPath;
28 SkString fName; 28 SkString fName;
29 Align fAlign; 29 Align fAlign;
30 bool fRound;
30 31
31 public: 32 public:
32 BigPathBench(Align align) : fAlign(align) { 33 BigPathBench(Align align, bool round) : fAlign(align), fRound(round) {
33 fName.printf("bigpath_%s", gAlignName[fAlign]); 34 fName.printf("bigpath_%s", gAlignName[fAlign]);
35 if (round) {
36 fName.append("_round");
37 }
34 } 38 }
35 39
36 protected: 40 protected:
37 const char* onGetName() SK_OVERRIDE { 41 const char* onGetName() SK_OVERRIDE {
38 return fName.c_str(); 42 return fName.c_str();
39 } 43 }
40 44
41 SkIPoint onGetSize() SK_OVERRIDE { 45 SkIPoint onGetSize() SK_OVERRIDE {
42 return SkIPoint::Make(640, 100); 46 return SkIPoint::Make(640, 100);
43 } 47 }
44 48
45 void onPreDraw() SK_OVERRIDE { 49 void onPreDraw() SK_OVERRIDE {
46 make_path(fPath); 50 make_path(fPath);
47 } 51 }
48 52
49 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 53 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
50 SkPaint paint; 54 SkPaint paint;
51 paint.setAntiAlias(true); 55 paint.setAntiAlias(true);
52 paint.setStyle(SkPaint::kStroke_Style); 56 paint.setStyle(SkPaint::kStroke_Style);
53 paint.setStrokeWidth(2); 57 paint.setStrokeWidth(2);
58 if (fRound) {
59 paint.setStrokeJoin(SkPaint::kRound_Join);
60 }
54 this->setupPaint(&paint); 61 this->setupPaint(&paint);
55 62
56 const SkRect r = fPath.getBounds(); 63 const SkRect r = fPath.getBounds();
57 switch (fAlign) { 64 switch (fAlign) {
58 case kLeft_Align: 65 case kLeft_Align:
59 canvas->translate(-r.left(), 0); 66 canvas->translate(-r.left(), 0);
60 break; 67 break;
61 case kMiddle_Align: 68 case kMiddle_Align:
62 break; 69 break;
63 case kRight_Align: 70 case kRight_Align:
64 canvas->translate(640 - r.right(), 0); 71 canvas->translate(640 - r.right(), 0);
65 break; 72 break;
66 } 73 }
67 74
68 for (int i = 0; i < loops; i++) { 75 for (int i = 0; i < loops; i++) {
69 canvas->drawPath(fPath, paint); 76 canvas->drawPath(fPath, paint);
70 } 77 }
71 } 78 }
72 79
73 private: 80 private:
74 typedef Benchmark INHERITED; 81 typedef Benchmark INHERITED;
75 }; 82 };
76 83
77 DEF_BENCH( return new BigPathBench(kLeft_Align); ) 84 DEF_BENCH( return new BigPathBench(kLeft_Align, false); )
78 DEF_BENCH( return new BigPathBench(kMiddle_Align); ) 85 DEF_BENCH( return new BigPathBench(kMiddle_Align, false); )
79 DEF_BENCH( return new BigPathBench(kRight_Align); ) 86 DEF_BENCH( return new BigPathBench(kRight_Align, false); )
80 87
88 DEF_BENCH( return new BigPathBench(kLeft_Align, true); )
89 DEF_BENCH( return new BigPathBench(kMiddle_Align, true); )
90 DEF_BENCH( return new BigPathBench(kRight_Align, true); )
91
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