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

Side by Side Diff: bench/SkLinearBitmapPipelineBench.cpp

Issue 1704583003: Simplified linear pipeline. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix unaligned size problem. Created 4 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 | gm/SkLinearBitmapPipelineGM.cpp » ('j') | 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 <memory>
9 #include "SkColor.h"
10 #include "SkLinearBitmapPipeline.h"
11 #include "Benchmark.h"
12 #include "SkShader.h"
13 #include "SkImage.h"
14
15 struct CommonBitmapFPBenchmark : public Benchmark {
16 CommonBitmapFPBenchmark(
17 SkISize srcSize,
18 SkColorProfileType colorProfile,
19 SkMatrix m,
20 bool useBilerp,
21 SkShader::TileMode xTile,
22 SkShader::TileMode yTile)
23 : fColorProfile(colorProfile)
24 , fM{m}
25 , fUseBilerp{useBilerp}
26 , fXTile{xTile}
27 , fYTile{yTile} {
28 fSrcSize = srcSize;
29 }
30
31 static SkString tileName(const char* pre, SkShader::TileMode mode) {
32 SkString name{pre};
33 switch (mode) {
34 case SkShader::kClamp_TileMode:
35 name.append("Clamp");
36 return name;
37 case SkShader::kRepeat_TileMode:
38 name.append("Repeat");
39 return name;
40 case SkShader::kMirror_TileMode:
41 name.append("Mirror");
42 return name;
43 default:
44 name.append("Unknown");
45 return name;
46 }
47 }
48
49 const char* onGetName() override {
50 SkString name {"SkBitmapFP"};
51 if (fM.getType() & SkMatrix::kPerspective_Mask) {
52 name.append("Perspective");
53 } else if (fM.getType() & SkMatrix::kAffine_Mask) {
54 name.append("Affine");
55 } else if (fM.getType() & SkMatrix::kScale_Mask) {
56 name.append("Scale");
57 } else if (fM.getType() & SkMatrix::kTranslate_Mask) {
58 name.append("Translate");
59 } else {
60 name.append("Identity");
61 }
62
63 name.append(tileName("X", fXTile));
64 name.append(tileName("Y", fYTile));
65
66 if (fUseBilerp) {
67 name.append("Filter");
68 } else {
69 name.append("Nearest");
70 }
71
72 name.appendf("%s", BaseName().c_str());
73
74 return name.c_str();
bungeman-skia 2016/02/17 19:36:34 Gone! This is being reported by asan, because the
bungeman-skia 2016/02/17 20:10:18 This is now fixed with https://codereview.chromium
75 }
76
77 void onPreDraw(SkCanvas*) override {
78 int width = fSrcSize.fWidth;
79 int height = fSrcSize.fHeight;
80 fBitmap.reset(new uint32_t[width * height]);
81 for (int y = 0; y < height; y++) {
82 for (int x = 0; x < width; x++) {
83 fBitmap[y * width + x] = (y << 8) + x + (128<<24);
84 }
85 }
86
87 bool trash = fM.invert(&fInvert);
88 sk_ignore_unused_variable(trash);
89
90 fInfo = SkImageInfo::MakeN32Premul(width, height, fColorProfile);
91 }
92
93 bool isSuitableFor(Backend backend) override {
94 return backend == kNonRendering_Backend;
95 }
96
97 virtual SkString BaseName() = 0;
98
99 SkISize fSrcSize;
100 SkColorProfileType fColorProfile;
101 SkMatrix fM;
102 SkMatrix fInvert;
103 bool fUseBilerp;
104 SkShader::TileMode fXTile;
105 SkShader::TileMode fYTile;
106 SkImageInfo fInfo;
107 std::unique_ptr<uint32_t[]> fBitmap;
108 };
109
110 struct SkBitmapFPGeneral final : public CommonBitmapFPBenchmark {
111 SkBitmapFPGeneral(
112 SkISize srcSize,
113 SkColorProfileType colorProfile,
114 SkMatrix m,
115 bool useBilerp,
116 SkShader::TileMode xTile,
117 SkShader::TileMode yTile)
118 : CommonBitmapFPBenchmark(srcSize, colorProfile, m, useBilerp, xTile , yTile) { }
119 SkString BaseName() override {
120 SkString name;
121 if (fInfo.isSRGB()) {
122 name.set("sRGB");
123 } else {
124 name.set("Linr");
125 }
126 return name;
127 }
128
129 void onDraw(int loops, SkCanvas*) override {
130 int width = fSrcSize.fWidth;
131 int height = fSrcSize.fHeight;
132
133 SkPM4f* FPbuffer = new SkPM4f[width * height];
134
135 SkLinearBitmapPipeline pipeline{fInvert, fXTile, fYTile, fInfo, fBitmap. get(), };
136
137 int count = 100;
138
139 for (int n = 0; n < 1000*loops; n++) {
140 pipeline.shadeSpan4f(3, 6, FPbuffer, count);
141 }
142
143 delete [] FPbuffer;
144
145 }
146 };
147
148 struct SkBitmapFPOrigShader : public CommonBitmapFPBenchmark {
149 SkBitmapFPOrigShader(
150 SkISize srcSize,
151 SkColorProfileType colorProfile,
152 SkMatrix m,
153 bool useBilerp,
154 SkShader::TileMode xTile,
155 SkShader::TileMode yTile)
156 : CommonBitmapFPBenchmark(srcSize, colorProfile, m, useBilerp, xTile , yTile) { }
157 SkString BaseName() override {
158 SkString name{"Orig"};
159 return name;
160 }
161
162 void onPreDraw(SkCanvas* c) override {
163 CommonBitmapFPBenchmark::onPreDraw(c);
164
165 SkImage* image = SkImage::NewRasterCopy(
166 fInfo, fBitmap.get(), sizeof(SkPMColor) * fSrcSize.fWidth);
167 fImage.reset(image);
168 SkShader* shader = fImage->newShader(fXTile, fYTile);
169 if (fUseBilerp) {
170 fPaint.setFilterQuality(SkFilterQuality::kLow_SkFilterQuality);
171 } else {
172 fPaint.setFilterQuality(SkFilterQuality::kNone_SkFilterQuality);
173 }
174 fPaint.setShader(shader)->unref();
175
176 }
177
178 void onPostDraw(SkCanvas*) override {
179
180 }
181
182 void onDraw(int loops, SkCanvas*) override {
183 int width = fSrcSize.fWidth;
184 int height = fSrcSize.fHeight;
185
186 SkPMColor *buffer4b = new SkPMColor[width * height];
187
188 uint32_t storage[200];
189 SkASSERT(fPaint.getShader()->contextSize() <= sizeof(storage));
190 SkShader::Context* ctx = fPaint.getShader()->createContext(
191 {fPaint, fM, nullptr},
192 storage);
193
194 int count = 100;
195
196 for (int n = 0; n < 1000*loops; n++) {
197 ctx->shadeSpan(3, 6, buffer4b, count);
198 }
199
200 ctx->~Context();
201 delete buffer4b;
bungeman-skia 2016/02/17 21:38:41 This is also causing asan issues... delete [] buf
202 }
203 SkPaint fPaint;
204 SkAutoTUnref<SkImage> fImage;
205 };
206
207 static SkISize srcSize = SkISize::Make(120, 100);
208 static SkMatrix mI = SkMatrix::I();
209 DEF_BENCH(return new SkBitmapFPGeneral(
210 srcSize, kSRGB_SkColorProfileType, mI, false,
211 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
212
213 DEF_BENCH(return new SkBitmapFPGeneral(
214 srcSize, kLinear_SkColorProfileType, mI, false,
215 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
216
217 DEF_BENCH(return new SkBitmapFPOrigShader(
218 srcSize, kLinear_SkColorProfileType, mI, false,
219 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
220
221 DEF_BENCH(return new SkBitmapFPGeneral(
222 srcSize, kSRGB_SkColorProfileType, mI, true,
223 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
224
225 DEF_BENCH(return new SkBitmapFPGeneral(
226 srcSize, kLinear_SkColorProfileType, mI, true,
227 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
228
229 DEF_BENCH(return new SkBitmapFPOrigShader(
230 srcSize, kLinear_SkColorProfileType, mI, true,
231 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
232
233 static SkMatrix mS = SkMatrix::MakeScale(2.7f, 2.7f);
234 DEF_BENCH(return new SkBitmapFPGeneral(
235 srcSize, kSRGB_SkColorProfileType, mS, false,
236 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
237
238 DEF_BENCH(return new SkBitmapFPGeneral(
239 srcSize, kLinear_SkColorProfileType, mS, false,
240 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
241
242 DEF_BENCH(return new SkBitmapFPOrigShader(
243 srcSize, kLinear_SkColorProfileType, mS, false,
244 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
245
246 DEF_BENCH(return new SkBitmapFPGeneral(
247 srcSize, kSRGB_SkColorProfileType, mS, true,
248 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
249
250 DEF_BENCH(return new SkBitmapFPGeneral(
251 srcSize, kLinear_SkColorProfileType, mS, true,
252 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
253
254 DEF_BENCH(return new SkBitmapFPOrigShader(
255 srcSize, kLinear_SkColorProfileType, mS, true,
256 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
257
258 static SkMatrix rotate(SkScalar r) {
259 SkMatrix m;
260 m.setRotate(30);
261 return m;
262 }
263
264 static SkMatrix mR = rotate(30);
265 DEF_BENCH(return new SkBitmapFPGeneral(
266 srcSize, kSRGB_SkColorProfileType, mR, false,
267 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
268
269 DEF_BENCH(return new SkBitmapFPGeneral(
270 srcSize, kLinear_SkColorProfileType, mR, false,
271 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
272
273 DEF_BENCH(return new SkBitmapFPOrigShader(
274 srcSize, kLinear_SkColorProfileType, mR, false,
275 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
276
277 DEF_BENCH(return new SkBitmapFPGeneral(
278 srcSize, kSRGB_SkColorProfileType, mR, true,
279 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
280
281 DEF_BENCH(return new SkBitmapFPGeneral(
282 srcSize, kLinear_SkColorProfileType, mR, true,
283 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
284
285 DEF_BENCH(return new SkBitmapFPOrigShader(
286 srcSize, kLinear_SkColorProfileType, mR, true,
287 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);)
288
OLDNEW
« no previous file with comments | « no previous file | gm/SkLinearBitmapPipelineGM.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698