Index: tests/GradientTest.cpp |
diff --git a/tests/GradientTest.cpp b/tests/GradientTest.cpp |
index 65210705526e47e6574dcdf061313f77c4ed2ae2..cc94cbaf7591d3e7ecbca31cfc3422754854d55b 100644 |
--- a/tests/GradientTest.cpp |
+++ b/tests/GradientTest.cpp |
@@ -20,9 +20,9 @@ |
static void test_big_grad(skiatest::Reporter* reporter) { |
const SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; |
const SkPoint pts[] = {{ 15, 14.7112684f }, { 0.709064007f, 12.6108112f }}; |
- SkPaint paint; |
- paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, |
- SkShader::kClamp_TileMode)); |
+ SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode); |
+ SkPaint paint; |
+ paint.setShader(s)->unref(); |
SkBitmap bm; |
bm.allocN32Pixels(2000, 1); |
@@ -46,7 +46,7 @@ |
const SkScalar* fRadius; // 2 |
SkShader::TileMode fTileMode; |
- void gradCheck(skiatest::Reporter* reporter, const sk_sp<SkShader>& shader, |
+ void gradCheck(skiatest::Reporter* reporter, SkShader* shader, |
SkShader::GradientInfo* info, |
SkShader::GradientType gt) const { |
SkAutoTMalloc<SkColor> colorStorage(fColorCount); |
@@ -68,7 +68,7 @@ |
static void none_gradproc(skiatest::Reporter* reporter, const GradRec&) { |
- sk_sp<SkShader> s(SkShader::MakeEmptyShader()); |
+ SkAutoTUnref<SkShader> s(SkShader::CreateEmptyShader()); |
REPORTER_ASSERT(reporter, SkShader::kNone_GradientType == s->asAGradient(nullptr)); |
} |
@@ -84,42 +84,52 @@ |
} |
static void linear_gradproc(skiatest::Reporter* reporter, const GradRec& rec) { |
- sk_sp<SkShader> s(SkGradientShader::MakeLinear(rec.fPoint, rec.fColors, rec.fPos, |
- rec.fColorCount, rec.fTileMode)); |
- |
- SkShader::GradientInfo info; |
- rec.gradCheck(reporter, s, &info, SkShader::kLinear_GradientType); |
- REPORTER_ASSERT(reporter, !memcmp(info.fPoint, rec.fPoint, 2 * sizeof(SkPoint))); |
-} |
- |
-static void radial_gradproc(skiatest::Reporter* reporter, const GradRec& rec) { |
- sk_sp<SkShader> s(SkGradientShader::MakeRadial(rec.fPoint[0], rec.fRadius[0], rec.fColors, |
- rec.fPos, rec.fColorCount, rec.fTileMode)); |
- |
- SkShader::GradientInfo info; |
- rec.gradCheck(reporter, s, &info, SkShader::kRadial_GradientType); |
- REPORTER_ASSERT(reporter, info.fPoint[0] == rec.fPoint[0]); |
- REPORTER_ASSERT(reporter, info.fRadius[0] == rec.fRadius[0]); |
-} |
- |
-static void sweep_gradproc(skiatest::Reporter* reporter, const GradRec& rec) { |
- sk_sp<SkShader> s(SkGradientShader::MakeSweep(rec.fPoint[0].fX, rec.fPoint[0].fY, rec.fColors, |
- rec.fPos, rec.fColorCount)); |
- |
- SkShader::GradientInfo info; |
- rec.gradCheck(reporter, s, &info, SkShader::kSweep_GradientType); |
- REPORTER_ASSERT(reporter, info.fPoint[0] == rec.fPoint[0]); |
-} |
- |
-static void conical_gradproc(skiatest::Reporter* reporter, const GradRec& rec) { |
- sk_sp<SkShader> s(SkGradientShader::MakeTwoPointConical(rec.fPoint[0], |
- rec.fRadius[0], |
- rec.fPoint[1], |
- rec.fRadius[1], |
+ SkAutoTUnref<SkShader> s(SkGradientShader::CreateLinear(rec.fPoint, |
rec.fColors, |
rec.fPos, |
rec.fColorCount, |
rec.fTileMode)); |
+ |
+ SkShader::GradientInfo info; |
+ rec.gradCheck(reporter, s, &info, SkShader::kLinear_GradientType); |
+ REPORTER_ASSERT(reporter, !memcmp(info.fPoint, rec.fPoint, 2 * sizeof(SkPoint))); |
+} |
+ |
+static void radial_gradproc(skiatest::Reporter* reporter, const GradRec& rec) { |
+ SkAutoTUnref<SkShader> s(SkGradientShader::CreateRadial(rec.fPoint[0], |
+ rec.fRadius[0], |
+ rec.fColors, |
+ rec.fPos, |
+ rec.fColorCount, |
+ rec.fTileMode)); |
+ |
+ SkShader::GradientInfo info; |
+ rec.gradCheck(reporter, s, &info, SkShader::kRadial_GradientType); |
+ REPORTER_ASSERT(reporter, info.fPoint[0] == rec.fPoint[0]); |
+ REPORTER_ASSERT(reporter, info.fRadius[0] == rec.fRadius[0]); |
+} |
+ |
+static void sweep_gradproc(skiatest::Reporter* reporter, const GradRec& rec) { |
+ SkAutoTUnref<SkShader> s(SkGradientShader::CreateSweep(rec.fPoint[0].fX, |
+ rec.fPoint[0].fY, |
+ rec.fColors, |
+ rec.fPos, |
+ rec.fColorCount)); |
+ |
+ SkShader::GradientInfo info; |
+ rec.gradCheck(reporter, s, &info, SkShader::kSweep_GradientType); |
+ REPORTER_ASSERT(reporter, info.fPoint[0] == rec.fPoint[0]); |
+} |
+ |
+static void conical_gradproc(skiatest::Reporter* reporter, const GradRec& rec) { |
+ SkAutoTUnref<SkShader> s(SkGradientShader::CreateTwoPointConical(rec.fPoint[0], |
+ rec.fRadius[0], |
+ rec.fPoint[1], |
+ rec.fRadius[1], |
+ rec.fColors, |
+ rec.fPos, |
+ rec.fColorCount, |
+ rec.fTileMode)); |
SkShader::GradientInfo info; |
rec.gradCheck(reporter, s, &info, SkShader::kConical_GradientType); |
@@ -135,10 +145,15 @@ |
}; |
SkColor colors[] = { SK_ColorBLUE, SK_ColorBLUE }; |
const SkScalar pos[] = { 0, SK_Scalar1 }; |
- SkPaint paint; |
- paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 2, SkShader::kClamp_TileMode)); |
+ SkAutoTUnref<SkShader> s(SkGradientShader::CreateLinear(pts, |
+ colors, |
+ pos, |
+ 2, |
+ SkShader::kClamp_TileMode)); |
SkBitmap outBitmap; |
outBitmap.allocN32Pixels(10, 1); |
+ SkPaint paint; |
+ paint.setShader(s.get()); |
SkCanvas canvas(outBitmap); |
canvas.drawPaint(paint); |
SkAutoLockPixels alp(outBitmap); |
@@ -189,8 +204,11 @@ |
const SkPoint pts[] = {{ 100, 50 }, { 100.0001f, 50000 }}; |
const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE }; |
const SkScalar pos[] = { 0, 1 }; |
- SkPaint paint; |
- paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 2, SkShader::kClamp_TileMode)); |
+ SkAutoTUnref<SkShader> gradient( |
+ SkGradientShader::CreateLinear(pts, colors, pos, 2, SkShader::kClamp_TileMode)); |
+ |
+ SkPaint paint; |
+ paint.setShader(gradient); |
surface->getCanvas()->drawPaint(paint); |
} |
@@ -206,9 +224,12 @@ |
const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE }; |
const SkScalar pos[] = {0, 0.200000003f, 0.800000012f, 1 }; |
- SkPaint paint; |
- paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 4, SkShader::kClamp_TileMode)); |
- |
+ |
+ SkAutoTUnref<SkShader> gradient( |
+ SkGradientShader::CreateLinear(pts, colors, pos, 4, SkShader::kClamp_TileMode)); |
+ |
+ SkPaint paint; |
+ paint.setShader(gradient); |
SkRect r = {0, 83, 1254, 620}; |
surface->getCanvas()->drawRect(r, paint); |
} |
@@ -220,11 +241,12 @@ |
surface->getCanvas()->clear(SK_ColorRED); |
const SkColor colors[] = { SK_ColorGREEN, SK_ColorBLUE }; |
- SkPaint p; |
- p.setShader(SkGradientShader::MakeTwoPointConical( |
+ SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical( |
SkPoint::Make(2.5f, 2.5f), 0, |
SkPoint::Make(3.0f, 3.0f), 10, |
colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode)); |
+ SkPaint p; |
+ p.setShader(shader); |
surface->getCanvas()->drawPaint(p); |
// r == 0 for the center pixel. |