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

Side by Side Diff: bench/GradientBench.cpp

Issue 18655012: Added a high-color (50 colors) gradient for each gradient type. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Removed enum type, added name field to GradData struct instead. Created 7 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 | Annotate | Revision Log
« 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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkBenchmark.h" 8 #include "SkBenchmark.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 "SkGradientShader.h" 12 #include "SkGradientShader.h"
13 #include "SkPaint.h" 13 #include "SkPaint.h"
14 #include "SkShader.h" 14 #include "SkShader.h"
15 #include "SkString.h" 15 #include "SkString.h"
16 #include "SkUnitMapper.h" 16 #include "SkUnitMapper.h"
17 17
18 struct GradData { 18 struct GradData {
19 int fCount; 19 int fCount;
20 const SkColor* fColors; 20 const SkColor* fColors;
21 const SkScalar* fPos; 21 const SkScalar* fPos;
22 const char* fName;
22 }; 23 };
23 24
24 static const SkColor gColors[] = { 25 static const SkColor gColors[] = {
25 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, 26 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
27 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
28 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
29 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
30 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
31 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
32 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
33 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
34 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
35 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, // 1 0 lines, 50 colors
26 }; 36 };
27 37
28 static const GradData gGradData[] = { 38 static const GradData gGradData[] = {
29 { 2, gColors, NULL }, 39 { 2, gColors, NULL, "" },
40 { 50, gColors, NULL, "_hicolor" }, // many color gradient
30 }; 41 };
31 42
32 /// Ignores scale 43 /// Ignores scale
33 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, 44 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
34 SkShader::TileMode tm, SkUnitMapper* mapper, 45 SkShader::TileMode tm, SkUnitMapper* mapper,
35 float scale) { 46 float scale) {
36 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, 47 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
37 data.fCount, tm, mapper); 48 data.fCount, tm, mapper);
38 } 49 }
39 50
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 SkString fName; 160 SkString fName;
150 SkShader* fShader; 161 SkShader* fShader;
151 int fCount; 162 int fCount;
152 enum { 163 enum {
153 W = 400, 164 W = 400,
154 H = 400, 165 H = 400,
155 N = 1 166 N = 1
156 }; 167 };
157 public: 168 public:
158 GradientBench(void* param, GradType gradType, 169 GradientBench(void* param, GradType gradType,
170 GradData data = gGradData[0],
159 SkShader::TileMode tm = SkShader::kClamp_TileMode, 171 SkShader::TileMode tm = SkShader::kClamp_TileMode,
160 GeomType geomType = kRect_GeomType, 172 GeomType geomType = kRect_GeomType,
161 float scale = 1.0f) 173 float scale = 1.0f
174 )
162 : INHERITED(param) { 175 : INHERITED(param) {
163 fName.printf("gradient_%s_%s", gGrads[gradType].fName, 176 fName.printf("gradient_%s_%s", gGrads[gradType].fName,
164 tilemodename(tm)); 177 tilemodename(tm));
165 if (geomType != kRect_GeomType) { 178 if (geomType != kRect_GeomType) {
166 fName.append("_"); 179 fName.append("_");
167 fName.append(geomtypename(geomType)); 180 fName.append(geomtypename(geomType));
168 } 181 }
169 182
183 fName.append(data.fName);
184
170 const SkPoint pts[2] = { 185 const SkPoint pts[2] = {
171 { 0, 0 }, 186 { 0, 0 },
172 { SkIntToScalar(W), SkIntToScalar(H) } 187 { SkIntToScalar(W), SkIntToScalar(H) }
173 }; 188 };
174 189
175 fCount = SkBENCHLOOP(N * gGrads[gradType].fRepeat); 190 fCount = SkBENCHLOOP(N * gGrads[gradType].fRepeat);
176 fShader = gGrads[gradType].fMaker(pts, gGradData[0], tm, NULL, scale); 191 fShader = gGrads[gradType].fMaker(pts, data, tm, NULL, scale);
177 fGeomType = geomType; 192 fGeomType = geomType;
178 } 193 }
179 194
180 virtual ~GradientBench() { 195 virtual ~GradientBench() {
181 fShader->unref(); 196 fShader->unref();
182 } 197 }
183 198
184 protected: 199 protected:
185 virtual const char* onGetName() { 200 virtual const char* onGetName() {
186 return fName.c_str(); 201 return fName.c_str();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 paint.setShader(s)->unref(); 264 paint.setShader(s)->unref();
250 canvas->drawRect(r, paint); 265 canvas->drawRect(r, paint);
251 } 266 }
252 } 267 }
253 268
254 private: 269 private:
255 typedef SkBenchmark INHERITED; 270 typedef SkBenchmark INHERITED;
256 }; 271 };
257 272
258 DEF_BENCH( return new GradientBench(p, kLinear_GradType); ) 273 DEF_BENCH( return new GradientBench(p, kLinear_GradType); )
259 DEF_BENCH( return new GradientBench(p, kLinear_GradType, SkShader::kMirror_TileM ode); ) 274 DEF_BENCH( return new GradientBench(p, kLinear_GradType, gGradData[1]); )
275 DEF_BENCH( return new GradientBench(p, kLinear_GradType, gGradData[0], SkShader: :kMirror_TileMode); )
260 276
261 // Draw a radial gradient of radius 1/2 on a rectangle; half the lines should 277 // Draw a radial gradient of radius 1/2 on a rectangle; half the lines should
262 // be completely pinned, the other half should pe partially pinned 278 // be completely pinned, the other half should pe partially pinned
263 DEF_BENCH( return new GradientBench(p, kRadial_GradType, SkShader::kClamp_TileMo de, kRect_GeomType, 0.5f); ) 279 DEF_BENCH( return new GradientBench(p, kRadial_GradType, gGradData[0], SkShader: :kClamp_TileMode, kRect_GeomType, 0.5f); )
264 280
265 // Draw a radial gradient on a circle of equal size; all the lines should 281 // Draw a radial gradient on a circle of equal size; all the lines should
266 // hit the unpinned fast path (so long as GradientBench.W == H) 282 // hit the unpinned fast path (so long as GradientBench.W == H)
267 DEF_BENCH( return new GradientBench(p, kRadial_GradType, SkShader::kClamp_TileMo de, kOval_GeomType); ) 283 DEF_BENCH( return new GradientBench(p, kRadial_GradType, gGradData[0], SkShader: :kClamp_TileMode, kOval_GeomType); )
268 284
269 DEF_BENCH( return new GradientBench(p, kRadial_GradType, SkShader::kMirror_TileM ode); ) 285 DEF_BENCH( return new GradientBench(p, kRadial_GradType, gGradData[0], SkShader: :kMirror_TileMode); )
270 DEF_BENCH( return new GradientBench(p, kSweep_GradType); ) 286 DEF_BENCH( return new GradientBench(p, kSweep_GradType); )
287 DEF_BENCH( return new GradientBench(p, kSweep_GradType, gGradData[1]); )
271 DEF_BENCH( return new GradientBench(p, kRadial2_GradType); ) 288 DEF_BENCH( return new GradientBench(p, kRadial2_GradType); )
272 DEF_BENCH( return new GradientBench(p, kRadial2_GradType, SkShader::kMirror_Tile Mode); ) 289 DEF_BENCH( return new GradientBench(p, kRadial2_GradType, gGradData[1]); )
290 DEF_BENCH( return new GradientBench(p, kRadial2_GradType, gGradData[0], SkShader ::kMirror_TileMode); )
273 DEF_BENCH( return new GradientBench(p, kConical_GradType); ) 291 DEF_BENCH( return new GradientBench(p, kConical_GradType); )
292 DEF_BENCH( return new GradientBench(p, kConical_GradType, gGradData[1]); )
274 293
275 DEF_BENCH( return new Gradient2Bench(p, false); ) 294 DEF_BENCH( return new Gradient2Bench(p, false); )
276 DEF_BENCH( return new Gradient2Bench(p, true); ) 295 DEF_BENCH( return new Gradient2Bench(p, true); )
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