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

Side by Side Diff: bench/GradientBench.cpp

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