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

Side by Side Diff: bench/GradientBench.cpp

Issue 288313009: Remove unused (by clients) SkUnitMapper (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | expectations/gm/ignored-tests.txt » ('j') | gyp/skia_for_chromium_defines.gypi » ('J')
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"
17 16
18 struct GradData { 17 struct GradData {
19 int fCount; 18 int fCount;
20 const SkColor* fColors; 19 const SkColor* fColors;
21 const SkScalar* fPos; 20 const SkScalar* fPos;
22 const char* fName; 21 const char* fName;
23 }; 22 };
24 23
25 static const SkColor gColors[] = { 24 static const SkColor gColors[] = {
26 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, 25 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK,
(...skipping 11 matching lines...) Expand all
38 // We have several special-cases depending on the number (and spacing) of colors , so 37 // We have several special-cases depending on the number (and spacing) of colors , so
39 // try to exercise those here. 38 // try to exercise those here.
40 static const GradData gGradData[] = { 39 static const GradData gGradData[] = {
41 { 2, gColors, NULL, "" }, 40 { 2, gColors, NULL, "" },
42 { 50, gColors, NULL, "_hicolor" }, // many color gradient 41 { 50, gColors, NULL, "_hicolor" }, // many color gradient
43 { 3, gColors, NULL, "_3color" }, 42 { 3, gColors, NULL, "_3color" },
44 }; 43 };
45 44
46 /// Ignores scale 45 /// Ignores scale
47 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, 46 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
48 SkShader::TileMode tm, SkUnitMapper* mapper, 47 SkShader::TileMode tm, float scale) {
49 float scale) { 48 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCo unt, tm);
50 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
51 data.fCount, tm, mapper);
52 } 49 }
53 50
54 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, 51 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
55 SkShader::TileMode tm, SkUnitMapper* mapper, 52 SkShader::TileMode tm, float scale) {
56 float scale) {
57 SkPoint center; 53 SkPoint center;
58 center.set(SkScalarAve(pts[0].fX, pts[1].fX), 54 center.set(SkScalarAve(pts[0].fX, pts[1].fX),
59 SkScalarAve(pts[0].fY, pts[1].fY)); 55 SkScalarAve(pts[0].fY, pts[1].fY));
60 return SkGradientShader::CreateRadial(center, center.fX * scale, 56 return SkGradientShader::CreateRadial(center, center.fX * scale,
61 data.fColors, 57 data.fColors,
62 data.fPos, data.fCount, tm, mapper); 58 data.fPos, data.fCount, tm);
63 } 59 }
64 60
65 /// Ignores scale 61 /// Ignores scale
66 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, 62 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
67 SkShader::TileMode tm, SkUnitMapper* mapper, 63 SkShader::TileMode tm, float scale) {
68 float scale) {
69 SkPoint center; 64 SkPoint center;
70 center.set(SkScalarAve(pts[0].fX, pts[1].fX), 65 center.set(SkScalarAve(pts[0].fX, pts[1].fX),
71 SkScalarAve(pts[0].fY, pts[1].fY)); 66 SkScalarAve(pts[0].fY, pts[1].fY));
72 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, 67 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
73 data.fPos, data.fCount, mapper); 68 data.fPos, data.fCount);
74 } 69 }
75 70
76 /// Ignores scale 71 /// Ignores scale
77 static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, 72 static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
78 SkShader::TileMode tm, SkUnitMapper* mapper, 73 SkShader::TileMode tm, float scale) {
79 float scale) {
80 SkPoint center0, center1; 74 SkPoint center0, center1;
81 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 75 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
82 SkScalarAve(pts[0].fY, pts[1].fY)); 76 SkScalarAve(pts[0].fY, pts[1].fY));
83 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 77 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
84 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 78 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
85 return SkGradientShader::CreateTwoPointRadial( 79 return SkGradientShader::CreateTwoPointRadial(
86 center1, (pts[1].fX - pts[0].f X) / 7, 80 center1, (pts[1].fX - pts[0].f X) / 7,
87 center0, (pts[1].fX - pts[0].f X) / 2, 81 center0, (pts[1].fX - pts[0].f X) / 2,
88 data.fColors, data.fPos, data. fCount, tm, mapper); 82 data.fColors, data.fPos, data. fCount, tm);
89 } 83 }
90 84
91 /// Ignores scale 85 /// Ignores scale
92 static SkShader* MakeConical(const SkPoint pts[2], const GradData& data, 86 static SkShader* MakeConical(const SkPoint pts[2], const GradData& data,
93 SkShader::TileMode tm, SkUnitMapper* mapper, 87 SkShader::TileMode tm, float scale) {
94 float scale) {
95 SkPoint center0, center1; 88 SkPoint center0, center1;
96 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 89 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
97 SkScalarAve(pts[0].fY, pts[1].fY)); 90 SkScalarAve(pts[0].fY, pts[1].fY));
98 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 91 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
99 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 92 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
100 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0]. fX) / 7, 93 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0]. fX) / 7,
101 center0, (pts[1].fX - pts[0]. fX) / 2, 94 center0, (pts[1].fX - pts[0]. fX) / 2,
102 data.fColors, data.fPos, data .fCount, tm, mapper); 95 data.fColors, data.fPos, data .fCount, tm);
103 } 96 }
104 97
105 /// Ignores scale 98 /// Ignores scale
106 static SkShader* MakeConicalZeroRad(const SkPoint pts[2], const GradData& data, 99 static SkShader* MakeConicalZeroRad(const SkPoint pts[2], const GradData& data,
107 SkShader::TileMode tm, SkUnitMapper* mapper, 100 SkShader::TileMode tm, float scale) {
108 float scale) {
109 SkPoint center0, center1; 101 SkPoint center0, center1;
110 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 102 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
111 SkScalarAve(pts[0].fY, pts[1].fY)); 103 SkScalarAve(pts[0].fY, pts[1].fY));
112 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 104 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
113 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 105 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
114 return SkGradientShader::CreateTwoPointConical(center1, 0.0, 106 return SkGradientShader::CreateTwoPointConical(center1, 0.0,
115 center0, (pts[1].fX - pts[0]. fX) / 2, 107 center0, (pts[1].fX - pts[0]. fX) / 2,
116 data.fColors, data.fPos, data .fCount, tm, mapper); 108 data.fColors, data.fPos, data .fCount, tm);
117 } 109 }
118 110
119 /// Ignores scale 111 /// Ignores scale
120 static SkShader* MakeConicalOutside(const SkPoint pts[2], const GradData& data, 112 static SkShader* MakeConicalOutside(const SkPoint pts[2], const GradData& data,
121 SkShader::TileMode tm, SkUnitMapper* mapper, 113 SkShader::TileMode tm, float scale) {
122 float scale) {
123 SkPoint center0, center1; 114 SkPoint center0, center1;
124 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); 115 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
125 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); 116 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
126 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); 117 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
127 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); 118 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
128 return SkGradientShader::CreateTwoPointConical(center0, radius0, 119 return SkGradientShader::CreateTwoPointConical(center0, radius0,
129 center1, radius1, 120 center1, radius1,
130 data.fColors, data.fPos, 121 data.fColors, data.fPos,
131 data.fCount, tm, mapper); 122 data.fCount, tm);
132 } 123 }
133 124
134 /// Ignores scale 125 /// Ignores scale
135 static SkShader* MakeConicalOutsideZeroRad(const SkPoint pts[2], const GradData& data, 126 static SkShader* MakeConicalOutsideZeroRad(const SkPoint pts[2], const GradData& data,
136 SkShader::TileMode tm, SkUnitMapper* mapper, 127 SkShader::TileMode tm, float scale) {
137 float scale) {
138 SkPoint center0, center1; 128 SkPoint center0, center1;
139 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); 129 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
140 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); 130 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
141 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); 131 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
142 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); 132 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
143 return SkGradientShader::CreateTwoPointConical(center0, 0.0, 133 return SkGradientShader::CreateTwoPointConical(center0, 0.0,
144 center1, radius1, 134 center1, radius1,
145 data.fColors, data.fPos, 135 data.fColors, data.fPos,
146 data.fCount, tm, mapper); 136 data.fCount, tm);
147 } 137 }
148 138
149 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, 139 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
150 SkShader::TileMode tm, SkUnitMapper* mapper, 140 SkShader::TileMode tm, float scale);
151 float scale);
152 141
153 static const struct { 142 static const struct {
154 GradMaker fMaker; 143 GradMaker fMaker;
155 const char* fName; 144 const char* fName;
156 } gGrads[] = { 145 } gGrads[] = {
157 { MakeLinear, "linear" }, 146 { MakeLinear, "linear" },
158 { MakeRadial, "radial1" }, 147 { MakeRadial, "radial1" },
159 { MakeSweep, "sweep" }, 148 { MakeSweep, "sweep" },
160 { Make2Radial, "radial2" }, 149 { Make2Radial, "radial2" },
161 { MakeConical, "conical" }, 150 { MakeConical, "conical" },
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 fName.appendf("_scale_%g", scale); 222 fName.appendf("_scale_%g", scale);
234 } 223 }
235 224
236 fName.append(data.fName); 225 fName.append(data.fName);
237 226
238 const SkPoint pts[2] = { 227 const SkPoint pts[2] = {
239 { 0, 0 }, 228 { 0, 0 },
240 { SkIntToScalar(W), SkIntToScalar(H) } 229 { SkIntToScalar(W), SkIntToScalar(H) }
241 }; 230 };
242 231
243 fShader = gGrads[gradType].fMaker(pts, data, tm, NULL, scale); 232 fShader = gGrads[gradType].fMaker(pts, data, tm, scale);
244 fGeomType = geomType; 233 fGeomType = geomType;
245 } 234 }
246 235
247 virtual ~GradientBench() { 236 virtual ~GradientBench() {
248 fShader->unref(); 237 fShader->unref();
249 } 238 }
250 239
251 protected: 240 protected:
252 virtual const char* onGetName() { 241 virtual const char* onGetName() {
253 return fName.c_str(); 242 return fName.c_str();
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 canvas->drawRect(r, paint); 345 canvas->drawRect(r, paint);
357 } 346 }
358 } 347 }
359 348
360 private: 349 private:
361 typedef SkBenchmark INHERITED; 350 typedef SkBenchmark INHERITED;
362 }; 351 };
363 352
364 DEF_BENCH( return new Gradient2Bench(false); ) 353 DEF_BENCH( return new Gradient2Bench(false); )
365 DEF_BENCH( return new Gradient2Bench(true); ) 354 DEF_BENCH( return new Gradient2Bench(true); )
OLDNEW
« no previous file with comments | « no previous file | expectations/gm/ignored-tests.txt » ('j') | gyp/skia_for_chromium_defines.gypi » ('J')

Powered by Google App Engine
This is Rietveld 408576698