Index: bench/GradientBench.cpp |
diff --git a/bench/GradientBench.cpp b/bench/GradientBench.cpp |
index 21ebdce7ab12ebc9c757dab6dc4ffac6b3cc8c07..73014f7bae2ba55ad960097c2bb70167eb644d10 100644 |
--- a/bench/GradientBench.cpp |
+++ b/bench/GradientBench.cpp |
@@ -47,87 +47,89 @@ |
}; |
/// Ignores scale |
-static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, |
- SkShader::TileMode tm, float scale, bool force4f) { |
+static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, |
+ SkShader::TileMode tm, float scale, bool force4f) { |
const uint32_t flags = force4f ? SkLinearGradient::kForce4fContext_PrivateFlag : 0; |
- return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, |
- data.fCount, tm, flags, nullptr); |
-} |
- |
-static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, |
- SkShader::TileMode tm, float scale, bool force4f) { |
+ return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, |
+ data.fCount, tm, flags, nullptr); |
+} |
+ |
+static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, |
+ SkShader::TileMode tm, float scale, bool force4f) { |
SkPoint center; |
center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
SkScalarAve(pts[0].fY, pts[1].fY)); |
- return SkGradientShader::MakeRadial(center, center.fX * scale, data.fColors, |
- data.fPos, data.fCount, tm); |
-} |
- |
-/// Ignores scale |
-static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data, |
- SkShader::TileMode tm, float scale, bool force4f) { |
+ return SkGradientShader::CreateRadial(center, center.fX * scale, |
+ data.fColors, |
+ data.fPos, data.fCount, tm); |
+} |
+ |
+/// Ignores scale |
+static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, |
+ SkShader::TileMode tm, float scale, bool force4f) { |
SkPoint center; |
center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
SkScalarAve(pts[0].fY, pts[1].fY)); |
- return SkGradientShader::MakeSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount); |
-} |
- |
-/// Ignores scale |
-static sk_sp<SkShader> MakeConical(const SkPoint pts[2], const GradData& data, |
- SkShader::TileMode tm, float scale, bool force4f) { |
+ return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, |
+ data.fPos, data.fCount); |
+} |
+ |
+/// Ignores scale |
+static SkShader* MakeConical(const SkPoint pts[2], const GradData& data, |
+ SkShader::TileMode tm, float scale, bool force4f) { |
SkPoint center0, center1; |
center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
SkScalarAve(pts[0].fY, pts[1].fY)); |
center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
- return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7, |
- center0, (pts[1].fX - pts[0].fX) / 2, |
- data.fColors, data.fPos, data.fCount, tm); |
-} |
- |
-/// Ignores scale |
-static sk_sp<SkShader> MakeConicalZeroRad(const SkPoint pts[2], const GradData& data, |
- SkShader::TileMode tm, float scale, bool force4f) { |
+ return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7, |
+ center0, (pts[1].fX - pts[0].fX) / 2, |
+ data.fColors, data.fPos, data.fCount, tm); |
+} |
+ |
+/// Ignores scale |
+static SkShader* MakeConicalZeroRad(const SkPoint pts[2], const GradData& data, |
+ SkShader::TileMode tm, float scale, bool force4f) { |
SkPoint center0, center1; |
center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
SkScalarAve(pts[0].fY, pts[1].fY)); |
center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
- return SkGradientShader::MakeTwoPointConical(center1, 0.0, |
- center0, (pts[1].fX - pts[0].fX) / 2, |
- data.fColors, data.fPos, data.fCount, tm); |
-} |
- |
-/// Ignores scale |
-static sk_sp<SkShader> MakeConicalOutside(const SkPoint pts[2], const GradData& data, |
- SkShader::TileMode tm, float scale, bool force4f) { |
+ return SkGradientShader::CreateTwoPointConical(center1, 0.0, |
+ center0, (pts[1].fX - pts[0].fX) / 2, |
+ data.fColors, data.fPos, data.fCount, tm); |
+} |
+ |
+/// Ignores scale |
+static SkShader* MakeConicalOutside(const SkPoint pts[2], const GradData& data, |
+ SkShader::TileMode tm, float scale, bool force4f) { |
SkPoint center0, center1; |
SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; |
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
- return SkGradientShader::MakeTwoPointConical(center0, radius0, |
- center1, radius1, |
- data.fColors, data.fPos, |
- data.fCount, tm); |
-} |
- |
-/// Ignores scale |
-static sk_sp<SkShader> MakeConicalOutsideZeroRad(const SkPoint pts[2], const GradData& data, |
- SkShader::TileMode tm, float scale, bool force4f) { |
+ return SkGradientShader::CreateTwoPointConical(center0, radius0, |
+ center1, radius1, |
+ data.fColors, data.fPos, |
+ data.fCount, tm); |
+} |
+ |
+/// Ignores scale |
+static SkShader* MakeConicalOutsideZeroRad(const SkPoint pts[2], const GradData& data, |
+ SkShader::TileMode tm, float scale, bool force4f) { |
SkPoint center0, center1; |
SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; |
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
- return SkGradientShader::MakeTwoPointConical(center0, 0.0, |
- center1, radius1, |
- data.fColors, data.fPos, |
- data.fCount, tm); |
-} |
- |
-typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data, |
- SkShader::TileMode tm, float scale, bool force4f); |
+ return SkGradientShader::CreateTwoPointConical(center0, 0.0, |
+ center1, radius1, |
+ data.fColors, data.fPos, |
+ data.fCount, tm); |
+} |
+ |
+typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, |
+ SkShader::TileMode tm, float scale, bool force4f); |
static const struct { |
GradMaker fMaker; |
@@ -211,8 +213,9 @@ |
fName.append("_4f"); |
} |
+ SkAutoTUnref<SkShader> shader(MakeShader(gradType, data, tm, scale, force4f)); |
this->setupPaint(&fPaint); |
- fPaint.setShader(MakeShader(gradType, data, tm, scale, force4f)); |
+ fPaint.setShader(shader); |
} |
GradientBench(GradType gradType, GradData data, bool dither, bool force4f = false) |
@@ -226,8 +229,10 @@ |
fName.appendf("_dither"); |
} |
+ SkAutoTUnref<SkShader> shader( |
+ MakeShader(gradType, data, SkShader::kClamp_TileMode, 1.0f, force4f)); |
this->setupPaint(&fPaint); |
- fPaint.setShader(MakeShader(gradType, data, SkShader::kClamp_TileMode, 1.0f, force4f)); |
+ fPaint.setShader(shader); |
fPaint.setDither(dither); |
} |
@@ -258,8 +263,8 @@ |
private: |
typedef Benchmark INHERITED; |
- sk_sp<SkShader> MakeShader(GradType gradType, GradData data, |
- SkShader::TileMode tm, float scale, bool force4f) { |
+ SkShader* MakeShader(GradType gradType, GradData data, |
+ SkShader::TileMode tm, float scale, bool force4f) { |
const SkPoint pts[2] = { |
{ 0, 0 }, |
{ SkIntToScalar(kSize), SkIntToScalar(kSize) } |
@@ -378,9 +383,10 @@ |
SK_ColorBLACK, |
SkColorSetARGB(alpha, gray, gray, gray), |
SK_ColorWHITE }; |
- paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, |
+ SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, |
SK_ARRAY_COUNT(colors), |
- SkShader::kClamp_TileMode)); |
+ SkShader::kClamp_TileMode); |
+ paint.setShader(s)->unref(); |
canvas->drawRect(r, paint); |
} |
} |