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

Side by Side Diff: bench/GradientBench.cpp

Issue 1803763002: Finish conversion to sk_sp<SkShader> (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 | « bench/GameBench.cpp ('k') | bench/ImageFilterCollapse.cpp » ('j') | 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 "Benchmark.h" 8 #include "Benchmark.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 29 matching lines...) Expand all
40 // We have several special-cases depending on the number (and spacing) of colors , so 40 // We have several special-cases depending on the number (and spacing) of colors , so
41 // try to exercise those here. 41 // try to exercise those here.
42 static const GradData gGradData[] = { 42 static const GradData gGradData[] = {
43 { 2, gColors, nullptr, "" }, 43 { 2, gColors, nullptr, "" },
44 { 50, gColors, nullptr, "_hicolor" }, // many color gradient 44 { 50, gColors, nullptr, "_hicolor" }, // many color gradient
45 { 3, gColors, nullptr, "_3color" }, 45 { 3, gColors, nullptr, "_3color" },
46 { 2, gShallowColors, nullptr, "_shallow" }, 46 { 2, gShallowColors, nullptr, "_shallow" },
47 }; 47 };
48 48
49 /// Ignores scale 49 /// Ignores scale
50 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, 50 static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data,
51 SkShader::TileMode tm, float scale, bool force4f) { 51 SkShader::TileMode tm, float scale, bool force 4f) {
52 const uint32_t flags = force4f ? SkLinearGradient::kForce4fContext_PrivateFl ag : 0; 52 const uint32_t flags = force4f ? SkLinearGradient::kForce4fContext_PrivateFl ag : 0;
53 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, 53 return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos,
54 data.fCount, tm, flags, nullptr); 54 data.fCount, tm, flags, nullptr);
55 } 55 }
56 56
57 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, 57 static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data,
58 SkShader::TileMode tm, float scale, bool force4f) { 58 SkShader::TileMode tm, float scale, bool force 4f) {
59 SkPoint center; 59 SkPoint center;
60 center.set(SkScalarAve(pts[0].fX, pts[1].fX), 60 center.set(SkScalarAve(pts[0].fX, pts[1].fX),
61 SkScalarAve(pts[0].fY, pts[1].fY)); 61 SkScalarAve(pts[0].fY, pts[1].fY));
62 return SkGradientShader::CreateRadial(center, center.fX * scale, 62 return SkGradientShader::MakeRadial(center, center.fX * scale, data.fColors,
63 data.fColors, 63 data.fPos, data.fCount, tm);
64 data.fPos, data.fCount, tm);
65 } 64 }
66 65
67 /// Ignores scale 66 /// Ignores scale
68 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, 67 static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data,
69 SkShader::TileMode tm, float scale, bool force4f) { 68 SkShader::TileMode tm, float scale, bool force4 f) {
70 SkPoint center; 69 SkPoint center;
71 center.set(SkScalarAve(pts[0].fX, pts[1].fX), 70 center.set(SkScalarAve(pts[0].fX, pts[1].fX),
72 SkScalarAve(pts[0].fY, pts[1].fY)); 71 SkScalarAve(pts[0].fY, pts[1].fY));
73 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, 72 return SkGradientShader::MakeSweep(center.fX, center.fY, data.fColors, data. fPos, data.fCount);
74 data.fPos, data.fCount);
75 } 73 }
76 74
77 /// Ignores scale 75 /// Ignores scale
78 static SkShader* MakeConical(const SkPoint pts[2], const GradData& data, 76 static sk_sp<SkShader> MakeConical(const SkPoint pts[2], const GradData& data,
79 SkShader::TileMode tm, float scale, bool force4f) { 77 SkShader::TileMode tm, float scale, bool forc e4f) {
80 SkPoint center0, center1; 78 SkPoint center0, center1;
81 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 79 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
82 SkScalarAve(pts[0].fY, pts[1].fY)); 80 SkScalarAve(pts[0].fY, pts[1].fY));
83 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 81 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
84 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 82 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
85 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0]. fX) / 7, 83 return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX ) / 7,
86 center0, (pts[1].fX - pts[0]. fX) / 2, 84 center0, (pts[1].fX - pts[0].fX ) / 2,
87 data.fColors, data.fPos, data .fCount, tm); 85 data.fColors, data.fPos, data.f Count, tm);
88 } 86 }
89 87
90 /// Ignores scale 88 /// Ignores scale
91 static SkShader* MakeConicalZeroRad(const SkPoint pts[2], const GradData& data, 89 static sk_sp<SkShader> MakeConicalZeroRad(const SkPoint pts[2], const GradData& data,
92 SkShader::TileMode tm, float scale, bool for ce4f) { 90 SkShader::TileMode tm, float scale, bo ol force4f) {
93 SkPoint center0, center1; 91 SkPoint center0, center1;
94 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 92 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
95 SkScalarAve(pts[0].fY, pts[1].fY)); 93 SkScalarAve(pts[0].fY, pts[1].fY));
96 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 94 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
97 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 95 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
98 return SkGradientShader::CreateTwoPointConical(center1, 0.0, 96 return SkGradientShader::MakeTwoPointConical(center1, 0.0,
99 center0, (pts[1].fX - pts[0]. fX) / 2, 97 center0, (pts[1].fX - pts[0].fX ) / 2,
100 data.fColors, data.fPos, data .fCount, tm); 98 data.fColors, data.fPos, data.f Count, tm);
101 } 99 }
102 100
103 /// Ignores scale 101 /// Ignores scale
104 static SkShader* MakeConicalOutside(const SkPoint pts[2], const GradData& data, 102 static sk_sp<SkShader> MakeConicalOutside(const SkPoint pts[2], const GradData& data,
105 SkShader::TileMode tm, float scale, bool for ce4f) { 103 SkShader::TileMode tm, float scale, bo ol force4f) {
106 SkPoint center0, center1; 104 SkPoint center0, center1;
107 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; 105 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
108 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; 106 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
109 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); 107 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
110 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); 108 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
111 return SkGradientShader::CreateTwoPointConical(center0, radius0, 109 return SkGradientShader::MakeTwoPointConical(center0, radius0,
112 center1, radius1, 110 center1, radius1,
113 data.fColors, data.fPos, 111 data.fColors, data.fPos,
114 data.fCount, tm); 112 data.fCount, tm);
115 } 113 }
116 114
117 /// Ignores scale 115 /// Ignores scale
118 static SkShader* MakeConicalOutsideZeroRad(const SkPoint pts[2], const GradData& data, 116 static sk_sp<SkShader> MakeConicalOutsideZeroRad(const SkPoint pts[2], const Gra dData& data,
119 SkShader::TileMode tm, float scale, b ool force4f) { 117 SkShader::TileMode tm, float sc ale, bool force4f) {
120 SkPoint center0, center1; 118 SkPoint center0, center1;
121 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; 119 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
122 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; 120 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
123 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); 121 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
124 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); 122 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
125 return SkGradientShader::CreateTwoPointConical(center0, 0.0, 123 return SkGradientShader::MakeTwoPointConical(center0, 0.0,
126 center1, radius1, 124 center1, radius1,
127 data.fColors, data.fPos, 125 data.fColors, data.fPos,
128 data.fCount, tm); 126 data.fCount, tm);
129 } 127 }
130 128
131 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, 129 typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data,
132 SkShader::TileMode tm, float scale, bool force4f) ; 130 SkShader::TileMode tm, float scale, bool fo rce4f);
133 131
134 static const struct { 132 static const struct {
135 GradMaker fMaker; 133 GradMaker fMaker;
136 const char* fName; 134 const char* fName;
137 } gGrads[] = { 135 } gGrads[] = {
138 { MakeLinear, "linear" }, 136 { MakeLinear, "linear" },
139 { MakeRadial, "radial1" }, 137 { MakeRadial, "radial1" },
140 { MakeSweep, "sweep" }, 138 { MakeSweep, "sweep" },
141 { MakeConical, "conical" }, 139 { MakeConical, "conical" },
142 { MakeConicalZeroRad, "conicalZero" }, 140 { MakeConicalZeroRad, "conicalZero" },
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 if (scale != 1.f) { 204 if (scale != 1.f) {
207 fName.appendf("_scale_%g", scale); 205 fName.appendf("_scale_%g", scale);
208 } 206 }
209 207
210 fName.append(data.fName); 208 fName.append(data.fName);
211 209
212 if (force4f) { 210 if (force4f) {
213 fName.append("_4f"); 211 fName.append("_4f");
214 } 212 }
215 213
216 SkAutoTUnref<SkShader> shader(MakeShader(gradType, data, tm, scale, forc e4f));
217 this->setupPaint(&fPaint); 214 this->setupPaint(&fPaint);
218 fPaint.setShader(shader); 215 fPaint.setShader(MakeShader(gradType, data, tm, scale, force4f));
219 } 216 }
220 217
221 GradientBench(GradType gradType, GradData data, bool dither, bool force4f = false) 218 GradientBench(GradType gradType, GradData data, bool dither, bool force4f = false)
222 : fGeomType(kRect_GeomType) { 219 : fGeomType(kRect_GeomType) {
223 220
224 const char *tmname = tilemodename(SkShader::kClamp_TileMode); 221 const char *tmname = tilemodename(SkShader::kClamp_TileMode);
225 fName.printf("gradient_%s_%s", gGrads[gradType].fName, tmname); 222 fName.printf("gradient_%s_%s", gGrads[gradType].fName, tmname);
226 fName.append(data.fName); 223 fName.append(data.fName);
227 224
228 if (dither) { 225 if (dither) {
229 fName.appendf("_dither"); 226 fName.appendf("_dither");
230 } 227 }
231 228
232 SkAutoTUnref<SkShader> shader(
233 MakeShader(gradType, data, SkShader::kClamp_TileMode, 1.0f, force4f) );
234 this->setupPaint(&fPaint); 229 this->setupPaint(&fPaint);
235 fPaint.setShader(shader); 230 fPaint.setShader(MakeShader(gradType, data, SkShader::kClamp_TileMode, 1 .0f, force4f));
236 fPaint.setDither(dither); 231 fPaint.setDither(dither);
237 } 232 }
238 233
239 protected: 234 protected:
240 const char* onGetName() override { 235 const char* onGetName() override {
241 return fName.c_str(); 236 return fName.c_str();
242 } 237 }
243 238
244 SkIPoint onGetSize() override { 239 SkIPoint onGetSize() override {
245 return SkIPoint::Make(kSize, kSize); 240 return SkIPoint::Make(kSize, kSize);
(...skipping 10 matching lines...) Expand all
256 case kOval_GeomType: 251 case kOval_GeomType:
257 canvas->drawOval(r, fPaint); 252 canvas->drawOval(r, fPaint);
258 break; 253 break;
259 } 254 }
260 } 255 }
261 } 256 }
262 257
263 private: 258 private:
264 typedef Benchmark INHERITED; 259 typedef Benchmark INHERITED;
265 260
266 SkShader* MakeShader(GradType gradType, GradData data, 261 sk_sp<SkShader> MakeShader(GradType gradType, GradData data,
267 SkShader::TileMode tm, float scale, bool force4f) { 262 SkShader::TileMode tm, float scale, bool force4f) {
268 const SkPoint pts[2] = { 263 const SkPoint pts[2] = {
269 { 0, 0 }, 264 { 0, 0 },
270 { SkIntToScalar(kSize), SkIntToScalar(kSize) } 265 { SkIntToScalar(kSize), SkIntToScalar(kSize) }
271 }; 266 };
272 267
273 return gGrads[gradType].fMaker(pts, data, tm, scale, force4f); 268 return gGrads[gradType].fMaker(pts, data, tm, scale, force4f);
274 } 269 }
275 270
276 static const int kSize = 400; 271 static const int kSize = 400;
277 272
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 { SkIntToScalar(100), SkIntToScalar(100) }, 371 { SkIntToScalar(100), SkIntToScalar(100) },
377 }; 372 };
378 373
379 for (int i = 0; i < loops; i++) { 374 for (int i = 0; i < loops; i++) {
380 const int gray = i % 256; 375 const int gray = i % 256;
381 const int alpha = fHasAlpha ? gray : 0xFF; 376 const int alpha = fHasAlpha ? gray : 0xFF;
382 SkColor colors[] = { 377 SkColor colors[] = {
383 SK_ColorBLACK, 378 SK_ColorBLACK,
384 SkColorSetARGB(alpha, gray, gray, gray), 379 SkColorSetARGB(alpha, gray, gray, gray),
385 SK_ColorWHITE }; 380 SK_ColorWHITE };
386 SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, 381 paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr,
387 SK_ARRAY_COUNT(colors), 382 SK_ARRAY_COUNT(colors),
388 SkShader::kClamp_TileMo de); 383 SkShader::kClamp_TileMo de));
389 paint.setShader(s)->unref();
390 canvas->drawRect(r, paint); 384 canvas->drawRect(r, paint);
391 } 385 }
392 } 386 }
393 387
394 private: 388 private:
395 typedef Benchmark INHERITED; 389 typedef Benchmark INHERITED;
396 }; 390 };
397 391
398 DEF_BENCH( return new Gradient2Bench(false); ) 392 DEF_BENCH( return new Gradient2Bench(false); )
399 DEF_BENCH( return new Gradient2Bench(true); ) 393 DEF_BENCH( return new Gradient2Bench(true); )
OLDNEW
« no previous file with comments | « bench/GameBench.cpp ('k') | bench/ImageFilterCollapse.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698