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

Side by Side Diff: bench/HardStopGradientBench.cpp

Issue 2131643002: Add HardStopGradientBench.cpp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 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
(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
10 #include "SkCanvas.h"
11 #include "SkShader.h"
12 #include "SkGradientShader.h"
13 #include "SkString.h"
14 #include "SkColor.h"
15 #include "SkPaint.h"
16
17 struct GradData {
bsalomon 2016/07/07 18:36:32 Is this used?
18 int fCount;
19 const SkColor* fColors;
20 const SkScalar* fPos;
21 const char* fName;
22 };
23
24 static constexpr int kMaxCount = 50;
25
26 static const char* get_tilemode_name(SkShader::TileMode tilemode) {
27 switch (tilemode) {
28 case SkShader::kClamp_TileMode:
29 return "clamp";
30 case SkShader::kRepeat_TileMode:
31 return "repeat";
32 case SkShader::kMirror_TileMode:
33 return "mirror";
34 default:
35 SkDEBUGFAIL("Unknown tilemode");
36 return "error";
37 }
38 }
39
40 class HardStopGradientBench : public Benchmark {
41 public:
42 HardStopGradientBench(SkShader::TileMode tilemode, int count) {
43 count = std::max(0, std::min(count, kMaxCount));
bsalomon 2016/07/07 18:36:32 Not sure I understand the purpose of kMaxCount.
44
45 fName.printf("hardstop_%s_%02d_colors", get_tilemode_name(tilemode), cou nt);
46
47 fTileMode = tilemode;
48 fColorCount = count;
49
50 // "Evenly spaced" colors
bsalomon 2016/07/07 18:36:32 Could from here onward and createShaderPaint be do
51 for (int i = 0; i < count; i++) {
52 fColors[i] = i * (0xffffffff / count);
53 }
54
55 // Create a hard stop
56 fPositions[0] = 0.0f;
57 fPositions[1] = 0.0f;
58 for (int i = 2; i < count; i++) {
59 // Evenly spaced afterwards
60 fPositions[i] = i / (count - 1.0f);
61 }
62 }
63
64 const char* onGetName() override {
65 return fName.c_str();
66 }
67
68 SkIPoint onGetSize() override {
69 return SkIPoint::Make(kSize, kSize);
70 }
71
72 /*
73 * Draw simple linear gradient from left to right
74 */
75 void onDraw(int loops, SkCanvas* canvas) override {
76 SkPoint points[2] = {
77 SkPoint::Make(0, kSize/2),
78 SkPoint::Make(kSize-1, kSize/2),
79 };
80
81 SkPaint paint = this->createShaderPaint(points);
82
83 for (int i = 0; i < loops; i++) {
84 canvas->drawPaint(paint);
85 }
86 }
87
88 private:
89 static const int kSize = 500;
90
91 SkShader::TileMode fTileMode;
92 SkString fName;
93 int fColorCount;
94 SkScalar fPositions[kMaxCount];
95 SkColor fColors[kMaxCount];
96
97 SkPaint createShaderPaint(SkPoint points[2]) {
98 SkPaint p;
99 p.setShader(SkGradientShader::MakeLinear(points,
100 fColors,
101 fPositions,
102 fColorCount,
103 fTileMode,
104 0,
105 nullptr));
106 return p;
107 }
108
109 typedef Benchmark INHERITED;
110 };
111
112 // Clamp
113 DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, kMaxCount/ 10);)
114 DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, kMaxCount/ 5);)
115 DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, kMaxCount/ 2);)
116 DEF_BENCH(return new HardStopGradientBench(SkShader::kClamp_TileMode, kMaxCount) ;)
117
118 // Repeat
119 DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, kMaxCount /10);)
120 DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, kMaxCount /5);)
121 DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, kMaxCount /2);)
122 DEF_BENCH(return new HardStopGradientBench(SkShader::kRepeat_TileMode, kMaxCount );)
123
124 // Mirror
125 DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, kMaxCount /10);)
126 DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, kMaxCount /5);)
127 DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, kMaxCount /2);)
128 DEF_BENCH(return new HardStopGradientBench(SkShader::kMirror_TileMode, kMaxCount );)
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