// { 2, gCol2, nullptr },
};
-static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
- return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm);
+static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+ return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCount, tm);
}
-static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
- SkPoint center;
- center.set(SkScalarAve(pts[0].fX, pts[1].fX),
- SkScalarAve(pts[0].fY, pts[1].fY));
- return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
- data.fPos, data.fCount, tm);
+static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+ const SkPoint pt{ SkScalarAve(pts[0].fX, pts[1].fX), SkScalarAve(pts[0].fY, pts[1].fY) };
+ return SkGradientShader::MakeRadial(pt, pt.fX, data.fColors, data.fPos, data.fCount, tm);
}
-static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
- SkPoint center;
- center.set(SkScalarAve(pts[0].fX, pts[1].fX),
- SkScalarAve(pts[0].fY, pts[1].fY));
- return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
+static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
+ const SkPoint pt{ SkScalarAve(pts[0].fX, pts[1].fX), SkScalarAve(pts[0].fY, pts[1].fY) };
+ return SkGradientShader::MakeSweep(pt.fX, pt.fY, data.fColors, data.fPos, data.fCount);
}
-typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
+typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData&, SkShader::TileMode);
static const GradMaker gGradMakers[] = {
MakeLinear, MakeRadial, MakeSweep,
for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
canvas->save();
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
- SkShader* shader = gGradMakers[j](pts, gGradData[i], tm);
- paint.setShader(shader)->unref();
+ paint.setShader(gGradMakers[j](pts, gGradData[i], tm));
canvas->drawRect(r, paint);
canvas->translate(0, SkIntToScalar(120));
}
static const int IMAGES_X = 4; // number of images per row
-static SkShader* make_linear_gradient(const SkPoint pts[2], const SkMatrix& localMatrix) {
- return SkGradientShader::CreateLinear(pts, gColors, nullptr, SK_ARRAY_COUNT(gColors),
- SkShader::kClamp_TileMode, 0, &localMatrix);
+static sk_sp<SkShader> make_linear_gradient(const SkPoint pts[2], const SkMatrix& localMatrix) {
+ return SkGradientShader::MakeLinear(pts, gColors, nullptr, SK_ARRAY_COUNT(gColors),
+ SkShader::kClamp_TileMode, 0, &localMatrix);
}
-static SkShader* make_radial_gradient(const SkPoint pts[2], const SkMatrix& localMatrix) {
+static sk_sp<SkShader> make_radial_gradient(const SkPoint pts[2], const SkMatrix& localMatrix) {
SkPoint center;
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
float radius = (center - pts[0]).length();
- return SkGradientShader::CreateRadial(center, radius, gColors, nullptr, SK_ARRAY_COUNT(gColors),
- SkShader::kClamp_TileMode, 0, &localMatrix);
+ return SkGradientShader::MakeRadial(center, radius, gColors, nullptr, SK_ARRAY_COUNT(gColors),
+ SkShader::kClamp_TileMode, 0, &localMatrix);
}
static void draw_gradients(SkCanvas* canvas,
- SkShader* (*makeShader)(const SkPoint[2], const SkMatrix&),
+ sk_sp<SkShader> (*makeShader)(const SkPoint[2], const SkMatrix&),
const SkPoint ptsArray[][2], int numImages) {
// Use some nice prime numbers for the rectangle and matrix with
// different scaling along the x and y axes (which is the bug this
canvas->save();
}
- // Setup shader and draw.
- SkAutoTUnref<SkShader> shader(makeShader(*ptsArray, shaderMat));
-
SkPaint paint;
- paint.setShader(shader);
+ paint.setShader(makeShader(*ptsArray, shaderMat));
canvas->drawRect(rectGrad, paint);
// Advance to next position.
{ 4, gColorClamp, gPosClamp }
};
-static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
- return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
- data.fCount, tm, 0, &localMatrix);
+static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix) {
+ return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCount, tm, 0,
+ &localMatrix);
}
-static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center;
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
- return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
- data.fPos, data.fCount, tm, 0, &localMatrix);
+ return SkGradientShader::MakeRadial(center, center.fX, data.fColors, data.fPos, data.fCount,
+ tm, 0, &localMatrix);
}
-static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode, const SkMatrix& localMatrix) {
SkPoint center;
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
- return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
- data.fPos, data.fCount, 0, &localMatrix);
+ return SkGradientShader::MakeSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount,
+ 0, &localMatrix);
}
-static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2Radial(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix) {
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::CreateTwoPointConical(
- center1, (pts[1].fX - pts[0].fX) / 7,
- center0, (pts[1].fX - pts[0].fX) / 2,
- data.fColors, data.fPos, data.fCount, tm,
- 0, &localMatrix);
+ 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,
+ 0, &localMatrix);
}
-static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data,
+static sk_sp<SkShader> Make2Conical(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
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::CreateTwoPointConical(center1, radius1,
- center0, radius0,
- data.fColors, data.fPos,
- data.fCount, tm, 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0,
+ data.fColors, data.fPos,
+ data.fCount, tm, 0, &localMatrix);
}
-typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix);
+typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix);
static const GradMaker gGradMakers[] = {
MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical
};
scale.postTranslate(25.f, 25.f);
}
- SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, scale);
-
- paint.setShader(shader);
+ paint.setShader(gGradMakers[j](pts, gGradData[i], tm, scale));
canvas->drawRect(r, paint);
- shader->unref();
canvas->translate(0, SkIntToScalar(120));
}
canvas->restore();
perspective.setPerspY(SkIntToScalar(i+1) / 500);
perspective.setSkewX(SkIntToScalar(i+1) / 10);
- SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, perspective);
-
- paint.setShader(shader);
+ paint.setShader(gGradMakers[j](pts, gGradData[i], tm, perspective));
canvas->drawRect(r, paint);
- shader->unref();
canvas->translate(0, SkIntToScalar(120));
}
canvas->restore();
SkPoint c1;
c1.iset(0, 25);
SkScalar r1 = SkIntToScalar(150);
- SkShader* s = SkGradientShader::CreateTwoPointConical(c0, r0, c1, r1, colors,
- pos, SK_ARRAY_COUNT(pos),
- SkShader::kClamp_TileMode);
SkPaint paint;
+ paint.setShader(SkGradientShader::MakeTwoPointConical(c0, r0, c1, r1, colors,
+ pos, SK_ARRAY_COUNT(pos),
+ SkShader::kClamp_TileMode));
paint.setDither(fDither);
- paint.setShader(s)->unref();
canvas->drawPaint(paint);
}
SkScalar r0 = 20;
SkPoint c1 = { 200, 25 };
SkScalar r1 = 10;
- SkShader* s = SkGradientShader::CreateTwoPointConical(c0, r0, c1, r1, colors,
- pos, SK_ARRAY_COUNT(pos),
- SkShader::kClamp_TileMode);
+
SkPaint paint;
paint.setColor(SK_ColorYELLOW);
canvas->drawRect(SkRect::MakeWH(100, 150), paint);
- paint.setShader(s)->unref();
+ paint.setShader(SkGradientShader::MakeTwoPointConical(c0, r0, c1, r1, colors, pos,
+ SK_ARRAY_COUNT(pos),
+ SkShader::kClamp_TileMode));
canvas->drawRect(SkRect::MakeWH(100, 150), paint);
}
SkPoint center;
center.iset(0, 300);
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
- SkShader* shader = SkGradientShader::CreateRadial(
+ paint.setShader(SkGradientShader::MakeRadial(
SkPoint(center),
SkIntToScalar(200), gColors, nullptr, 5,
- SkShader::kClamp_TileMode);
- paint.setShader(shader);
+ SkShader::kClamp_TileMode));
canvas->drawRect(r, paint);
- shader->unref();
}
private:
const SkScalar pos[] = { 0.0f,
0.35f,
1.0f };
- SkShader* shader =
- SkGradientShader::CreateRadial(center, radius, colors,
- pos, SK_ARRAY_COUNT(pos),
- SkShader::kClamp_TileMode);
- paint.setShader(shader)->unref();
+ paint.setShader(SkGradientShader::MakeRadial(center, radius, colors, pos,
+ SK_ARRAY_COUNT(pos),
+ SkShader::kClamp_TileMode));
SkRect r = {
0, 0, SkIntToScalar(dim.width()), SkIntToScalar(dim.height())
};
const uint32_t flags[] = { 0, SkGradientShader::kInterpolateColorsInPremul_Flag };
for (size_t i = 0; i < SK_ARRAY_COUNT(flags); i++) {
- SkAutoTUnref<SkShader> sweep(
- SkGradientShader::CreateSweep(cx, cy, sweep_colors,
- nullptr, SK_ARRAY_COUNT(sweep_colors),
- flags[i], nullptr));
- SkAutoTUnref<SkShader> radial1(
- SkGradientShader::CreateRadial(center, radius, colors1,
- nullptr, SK_ARRAY_COUNT(colors1),
- SkShader::kClamp_TileMode,
- flags[i], nullptr));
- SkAutoTUnref<SkShader> radial2(
- SkGradientShader::CreateRadial(center, radius, colors2,
- nullptr, SK_ARRAY_COUNT(colors2),
- SkShader::kClamp_TileMode,
- flags[i], nullptr));
- paint1.setShader(sweep);
+ paint1.setShader(SkGradientShader::MakeSweep(cx, cy, sweep_colors,
+ nullptr, SK_ARRAY_COUNT(sweep_colors),
+ flags[i], nullptr));
+ paint2.setShader(SkGradientShader::MakeRadial(center, radius, colors1,
+ nullptr, SK_ARRAY_COUNT(colors1),
+ SkShader::kClamp_TileMode,
+ flags[i], nullptr));
+ paint3.setShader(SkGradientShader::MakeRadial(center, radius, colors2,
+ nullptr, SK_ARRAY_COUNT(colors2),
+ SkShader::kClamp_TileMode,
+ flags[i], nullptr));
paint1.setDither(fDither);
- paint2.setShader(radial1);
paint2.setDither(fDither);
- paint3.setShader(radial2);
paint3.setDither(fDither);
canvas->drawCircle(cx, cy, radius, paint1);
const SkPoint center = { 0, 0 };
const SkScalar kRadius = 3000;
const SkColor gColors[] = { 0xFFFFFFFF, 0xFF000000 };
- fShader.reset(SkGradientShader::CreateRadial(center, kRadius, gColors, nullptr, 2,
- SkShader::kClamp_TileMode));
+ fShader = SkGradientShader::MakeRadial(center, kRadius, gColors, nullptr, 2,
+ SkShader::kClamp_TileMode);
}
void onDraw(SkCanvas* canvas) override {
}
private:
- SkAutoTUnref<SkShader> fShader;
+ sk_sp<SkShader> fShader;
bool fDither;
typedef GM INHERITED;
const SkColor colors[] = { SK_ColorRED, SK_ColorRED, SK_ColorWHITE, SK_ColorWHITE,
SK_ColorRED };
const SkScalar pos[] = { 0, .4f, .4f, .8f, .8f, 1 };
- fShader.reset(SkGradientShader::CreateRadial(center, kRadius, colors, pos,
- SK_ARRAY_COUNT(gColors), SkShader::kClamp_TileMode));
+ fShader = SkGradientShader::MakeRadial(center, kRadius, colors, pos,
+ SK_ARRAY_COUNT(gColors), SkShader::kClamp_TileMode);
}
void onDraw(SkCanvas* canvas) override {
}
private:
- SkAutoTUnref<SkShader> fShader;
+ sk_sp<SkShader> fShader;
bool fDither;
typedef GM INHERITED;
for (int inner = 0; inner < (int) SK_ARRAY_COUNT(unitPos); ++inner) {
pos[inner] = unitPos[inner] / (kMinWidth + index * kWidthBump);
}
- fShader[index].reset(SkGradientShader::CreateLinear(pts, colors, pos,
- SK_ARRAY_COUNT(gColors), SkShader::kClamp_TileMode));
+ fShader[index] = SkGradientShader::MakeLinear(pts, colors, pos,
+ SK_ARRAY_COUNT(gColors), SkShader::kClamp_TileMode);
}
}
}
private:
- SkAutoTUnref<SkShader> fShader[100];
+ sk_sp<SkShader> fShader[100];
bool fDither;
typedef GM INHERITED;
SkPaint paint;
for (unsigned i = 0; i < SK_ARRAY_COUNT(configs); ++i) {
SkAutoCanvasRestore acr(canvas, true);
- SkAutoTUnref<SkShader> gradient(
- SkGradientShader::CreateLinear(configs[i].pts, colors, configs[i].pos, kStopCount,
- SkShader::kClamp_TileMode, fFlags, nullptr));
+ paint.setShader(SkGradientShader::MakeLinear(configs[i].pts, colors, configs[i].pos,
+ kStopCount, SkShader::kClamp_TileMode,
+ fFlags, nullptr));
canvas->translate(kRectSize * ((i % 4) * 1.5f + 0.25f),
kRectSize * ((i / 4) * 1.5f + 0.25f));
- paint.setShader(gradient);
canvas->drawRect(SkRect::MakeWH(kRectSize, kRectSize), paint);
}
}
#define SIZE 121
-static SkShader* make_linear(const GradRun& run, SkShader::TileMode mode) {
+static sk_sp<SkShader> make_linear(const GradRun& run, SkShader::TileMode mode) {
const SkPoint pts[] { { 30, 30 }, { SIZE - 30, SIZE - 30 } };
- return SkGradientShader::CreateLinear(pts, run.fColors, run.fPos, run.fCount, mode);
+ return SkGradientShader::MakeLinear(pts, run.fColors, run.fPos, run.fCount, mode);
}
-static SkShader* make_radial(const GradRun& run, SkShader::TileMode mode) {
+static sk_sp<SkShader> make_radial(const GradRun& run, SkShader::TileMode mode) {
const SkScalar half = SIZE * 0.5f;
- return SkGradientShader::CreateRadial({half,half}, half - 10,
- run.fColors, run.fPos, run.fCount, mode);
+ return SkGradientShader::MakeRadial({half,half}, half - 10, run.fColors, run.fPos,
+ run.fCount, mode);
}
-static SkShader* make_conical(const GradRun& run, SkShader::TileMode mode) {
+static sk_sp<SkShader> make_conical(const GradRun& run, SkShader::TileMode mode) {
const SkScalar half = SIZE * 0.5f;
const SkPoint center { half, half };
- return SkGradientShader::CreateTwoPointConical(center, 20, center, half - 10,
- run.fColors, run.fPos, run.fCount, mode);
+ return SkGradientShader::MakeTwoPointConical(center, 20, center, half - 10,
+ run.fColors, run.fPos, run.fCount, mode);
}
-static SkShader* make_sweep(const GradRun& run, SkShader::TileMode) {
+static sk_sp<SkShader> make_sweep(const GradRun& run, SkShader::TileMode) {
const SkScalar half = SIZE * 0.5f;
- return SkGradientShader::CreateSweep(half, half, run.fColors, run.fPos, run.fCount);
+ return SkGradientShader::MakeSweep(half, half, run.fColors, run.fPos, run.fCount);
}
/*
4,
},
};
- SkShader* (*factories[])(const GradRun&, SkShader::TileMode) {
+ sk_sp<SkShader> (*factories[])(const GradRun&, SkShader::TileMode) {
make_linear, make_radial, make_conical, make_sweep
};
canvas->translate(0, dy);
SkAutoCanvasRestore acr(canvas, true);
for (const auto& run : runs) {
- paint.setShader(factory(run, mode))->unref();
+ paint.setShader(factory(run, mode));
canvas->drawRect(rect, paint);
canvas->translate(dx, 0);
}
}
}
- SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(
- pts, colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, flags, nullptr));
-
SkPaint p;
- p.setShader(shader);
+ p.setShader(SkGradientShader::MakeLinear(
+ pts, colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, flags, nullptr));
canvas->drawRect(SkRect::MakeXYWH(0, 0, 500, 500), p);
}
{ 4, gColorClamp, gPosClamp }
};
-static SkShader* Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix) {
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::CreateTwoPointConical(center0, radius0,
- center1, radius1,
- data.fColors, data.fPos,
- data.fCount, tm, 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
+ data.fPos, data.fCount, tm, 0, &localMatrix);
}
-static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& data,
+static sk_sp<SkShader> Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
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::CreateTwoPointConical(center1, radius1,
- center0, radius0,
- data.fColors, data.fPos,
- data.fCount, tm, 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0, data.fColors,
+ data.fPos, data.fCount, tm, 0, &localMatrix);
}
-static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalInside(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix) {
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::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
- center0, (pts[1].fX - pts[0].fX) / 2,
- data.fColors, data.fPos, data.fCount, tm,
- 0, &localMatrix);
+ 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,
+ 0, &localMatrix);
}
-static SkShader* Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix) {
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::CreateTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 2,
- center1, (pts[1].fX - pts[0].fX) / 7,
- data.fColors, data.fPos, data.fCount, tm,
- 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 2,
+ center1, (pts[1].fX - pts[0].fX) / 7,
+ data.fColors, data.fPos, data.fCount, tm,
+ 0, &localMatrix);
}
-static SkShader* Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data,
+static sk_sp<SkShader> Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
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::CreateTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 7,
- center0, (pts[1].fX - pts[0].fX) / 2,
- data.fColors, data.fPos, data.fCount, tm,
- 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 7,
+ center0, (pts[1].fX - pts[0].fX) / 2,
+ data.fColors, data.fPos, data.fCount, tm,
+ 0, &localMatrix);
}
-static SkShader* Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix) {
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::CreateTwoPointConical(center1, 0.f,
- center0, (pts[1].fX - pts[0].fX) / 2,
- data.fColors, data.fPos, data.fCount, tm,
- 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center1, 0.f,
+ center0, (pts[1].fX - pts[0].fX) / 2,
+ data.fColors, data.fPos, data.fCount, tm,
+ 0, &localMatrix);
}
-static SkShader* Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix) {
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::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 2,
- center0, 0.f,
- data.fColors, data.fPos, data.fCount, tm,
- 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 2,
+ center0, 0.f,
+ data.fColors, data.fPos, data.fCount, tm,
+ 0, &localMatrix);
}
-static SkShader* Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data,
+static sk_sp<SkShader> Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
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::CreateTwoPointConical(center0, 0.f,
- center0, (pts[1].fX - pts[0].fX) / 2,
- data.fColors, data.fPos, data.fCount, tm,
- 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center0, 0.f, center0, (pts[1].fX - pts[0].fX) / 2,
+ data.fColors, data.fPos, data.fCount, tm,
+ 0, &localMatrix);
}
-static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm,
+ const SkMatrix& localMatrix) {
SkPoint center0, center1;
SkScalar radius0 = 0.f;
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::CreateTwoPointConical(center0, radius0,
- center1, radius1,
- data.fColors, data.fPos,
- data.fCount, tm, 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1,
+ data.fColors, data.fPos,
+ data.fCount, tm, 0, &localMatrix);
}
-static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm,
+ const SkMatrix& localMatrix) {
SkPoint center0, center1;
SkScalar radius0 = 0.f;
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::CreateTwoPointConical(center1, radius1,
- center0, radius0,
- data.fColors, data.fPos,
- data.fCount, tm, 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0, data.fColors,
+ data.fPos, data.fCount, tm, 0, &localMatrix);
}
-static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
center0.set(center1.fX + radius1, center1.fY);
- return SkGradientShader::CreateTwoPointConical(center0, radius0,
- center1, radius1,
- data.fColors, data.fPos,
- data.fCount, tm, 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
+ data.fPos, data.fCount, tm, 0, &localMatrix);
}
-static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
center0.set(center1.fX, center1.fY + radius1);
- return SkGradientShader::CreateTwoPointConical(center0, radius0,
- center1, radius1,
- data.fColors, data.fPos,
- data.fCount, tm, 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
+ data.fPos, data.fCount, tm, 0, &localMatrix);
}
-static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm,
+ const SkMatrix& localMatrix) {
SkPoint center0, center1;
SkScalar radius0 = 0.f;
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
center0.set(center1.fX + radius1, center1.fY);
- return SkGradientShader::CreateTwoPointConical(center0, radius0,
- center1, radius1,
- data.fColors, data.fPos,
- data.fCount, tm, 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
+ data.fPos, data.fCount, tm, 0, &localMatrix);
}
-static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
SkScalar radius0 = 0.f;
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
center0.set(center1.fX, center1.fY + radius1);
- return SkGradientShader::CreateTwoPointConical(center0, radius0,
- center1, radius1,
- data.fColors, data.fPos,
- data.fCount, tm, 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
+ data.fPos, data.fCount, tm, 0, &localMatrix);
}
-static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
center0.set(center1.fX - radius1 + radius0, center1.fY);
- return SkGradientShader::CreateTwoPointConical(center0, radius0,
- center1, radius1,
- data.fColors, data.fPos,
- data.fCount, tm, 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
+ data.fPos, data.fCount, tm, 0, &localMatrix);
}
-static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
center0.set(center1.fX, center1.fY + radius1 - radius0);
- return SkGradientShader::CreateTwoPointConical(center0, radius0,
- center1, radius1,
- data.fColors, data.fPos,
- data.fCount, tm, 0, &localMatrix);
+ return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
+ data.fPos, data.fCount, tm, 0, &localMatrix);
}
-static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData& data,
+static sk_sp<SkShader> Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
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::CreateTwoPointConical(center0, 0.0000000000000000001f,
+ return SkGradientShader::MakeTwoPointConical(center0, 0.0000000000000000001f,
center0, (pts[1].fX - pts[0].fX) / 2,
data.fColors, data.fPos, data.fCount, tm,
0, &localMatrix);
}
-typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
- SkShader::TileMode tm, const SkMatrix& localMatrix);
+typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data,
+ SkShader::TileMode tm, const SkMatrix& localMatrix);
static const GradMaker gGradMakersOutside[] = {
Make2ConicalOutside, Make2ConicalOutsideFlip,
scale.postTranslate(25.f, 25.f);
}
- SkShader* shader = gradMaker[j](pts, gGradData[i], tm, scale);
- paint.setShader(shader);
+ paint.setShader(gradMaker[j](pts, gGradData[i], tm, scale));
canvas->drawRect(r, paint);
- shader->unref();
canvas->translate(0, SkIntToScalar(120));
}
canvas->restore();
{ 4, gColors, nullptr },
};
-static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
- return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm);
+static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+ return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCount, tm);
}
-static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
SkPoint center;
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
- return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
- data.fPos, data.fCount, tm);
+ return SkGradientShader::MakeRadial(center, center.fX, data.fColors, data.fPos, data.fCount, tm);
}
-static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
+static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
SkPoint center;
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
- return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
+ return SkGradientShader::MakeSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
}
-static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+static sk_sp<SkShader> Make2Radial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
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::CreateTwoPointConical(
+ 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);
}
-static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+static sk_sp<SkShader> Make2Conical(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
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::CreateTwoPointConical(center1, radius1,
+ return SkGradientShader::MakeTwoPointConical(center1, radius1,
center0, radius0,
data.fColors, data.fPos,
data.fCount, tm);
}
-typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
+typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
static const GradMaker gGradMakers[] = {
MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical,
for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); ++i) {
canvas->save();
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); ++j) {
- SkShader* shader = gGradMakers[j](kPts, gGradData[i], kTM);
- paint.setShader(shader)->unref();
+ paint.setShader(gGradMakers[j](kPts, gGradData[i], kTM));
paint.setAlpha(kAlphas[a]);
canvas->drawRect(kRect, paint);
canvas->translate(0, SkIntToScalar(kRect.height() + 20));
for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
ColorPos rec;
procs[i](&rec);
- SkShader* s = SkGradientShader::CreateLinear(pts, rec.fColors, rec.fPos, rec.fCount,
- SkShader::kClamp_TileMode);
- paint.setShader(s)->unref();
+ paint.setShader(SkGradientShader::MakeLinear(pts, rec.fColors, rec.fPos, rec.fCount,
+ SkShader::kClamp_TileMode));
canvas->drawRect(drawR, paint);
canvas->save();
#include "SkTypeface.h"
// test shader w/ transparency
-static SkShader* make_grad(SkScalar width) {
+static sk_sp<SkShader> make_grad(SkScalar width) {
SkColor colors[] = { SK_ColorRED, 0x0000FF00, SK_ColorBLUE };
SkPoint pts[] = { { 0, 0 }, { width, 0 } };
- return SkGradientShader::CreateLinear(pts, colors, nullptr,
- SK_ARRAY_COUNT(colors),
- SkShader::kMirror_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+ SkShader::kMirror_TileMode);
}
// test opaque shader
-static SkShader* make_grad2(SkScalar width) {
+static sk_sp<SkShader> make_grad2(SkScalar width) {
SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
SkPoint pts[] = { { 0, 0 }, { width, 0 } };
- return SkGradientShader::CreateLinear(pts, colors, nullptr,
- SK_ARRAY_COUNT(colors),
- SkShader::kMirror_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+ SkShader::kMirror_TileMode);
}
-static SkShader* make_chrome_solid() {
+static sk_sp<SkShader> make_chrome_solid() {
SkColor colors[] = { SK_ColorGREEN, SK_ColorGREEN };
SkPoint pts[] = { { 0, 0 }, { 1, 0 } };
- return SkGradientShader::CreateLinear(pts, colors, nullptr, 2,
- SkShader::kClamp_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
}
namespace skiagm {
canvas->drawRect(r, paint);
// Minimal repro doesn't require AA, LCD, or a nondefault typeface
- paint.setShader(make_chrome_solid())->unref();
+ paint.setShader(make_chrome_solid());
paint.setTextSize(SkIntToScalar(500));
canvas->drawText("I", 1, 0, 100, paint);
canvas->drawText("Normal Stroke Text", 18, 0, 100, paint);
// Minimal repro doesn't require AA, LCD, or a nondefault typeface
- paint.setShader(make_chrome_solid())->unref();
+ paint.setShader(make_chrome_solid());
paint.setStyle(SkPaint::kFill_Style);
canvas->drawText("Gradient Fill Text", 18, 0, 150, paint);
canvas->translate(SkIntToScalar(20), paint.getTextSize());
for (int i = 0; i < 2; ++i) {
- paint.setShader(make_grad(SkIntToScalar(80)))->unref();
+ paint.setShader(make_grad(SkIntToScalar(80)));
draw_text3(canvas, paint);
canvas->translate(0, paint.getTextSize() * 2);
- paint.setShader(make_grad2(SkIntToScalar(80)))->unref();
+ paint.setShader(make_grad2(SkIntToScalar(80)));
draw_text3(canvas, paint);
canvas->translate(0, paint.getTextSize() * 2);
return H;
}
-static SkShader* make_bg_shader() {
+static sk_sp<SkShader> make_bg_shader() {
SkBitmap bm;
bm.allocN32Pixels(2, 2);
*bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = 0xFFFFFFFF;
SkMatrix m;
m.setScale(SkIntToScalar(6), SkIntToScalar(6));
- return SkShader::CreateBitmapShader(bm,
- SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode,
- &m);
+ return SkShader::MakeBitmapShader(bm,
+ SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &m);
}
namespace skiagm {
virtual SkISize onISize() override { return SkISize::Make(640, 480); }
void onOnceBeforeDraw() override {
- fBGPaint.setShader(make_bg_shader())->unref();
+ fBGPaint.setShader(make_bg_shader());
}
void onDraw(SkCanvas* canvas) override {
SkColor colors[2];
colors[0] = SK_ColorWHITE;
colors[1] = SK_ColorBLACK;
- SkAutoTUnref<SkShader> shader(
- SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2,
- SkShader::kClamp_TileMode)
- );
SkPaint paint;
- paint.setShader(shader);
+ paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr,
+ 2, SkShader::kClamp_TileMode));
canvas->drawCircle(x, y, radius, paint);
fGradientCircle.reset(surface->newImageSnapshot());
}
SkColor colors[2];
colors[0] = SK_ColorWHITE;
colors[1] = SK_ColorBLACK;
- SkAutoTUnref<SkShader> shader(
- SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2,
- SkShader::kClamp_TileMode)
- );
SkPaint paint;
- paint.setShader(shader);
+ paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr,
+ 2, SkShader::kClamp_TileMode));
canvas->drawCircle(x, y, radius, paint);
return surface->newImageSnapshot();
SkColor colors[2];
colors[0] = SK_ColorWHITE;
colors[1] = SK_ColorBLACK;
- SkAutoTUnref<SkShader> shader(
- SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2,
- SkShader::kClamp_TileMode)
- );
SkPaint paint;
- paint.setShader(shader);
+ paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr,
+ 2, SkShader::kClamp_TileMode));
canvas->drawCircle(x, y, radius, paint);
return surface->newImageSnapshot();
SkColor colors[2];
colors[0] = SK_ColorWHITE;
colors[1] = SK_ColorBLACK;
- SkAutoTUnref<SkShader> shader(
- SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2,
- SkShader::kClamp_TileMode)
- );
SkPaint paint;
- paint.setShader(shader);
+ paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2,
+ SkShader::kClamp_TileMode));
canvas->drawCircle(x, y, radius, paint);
return surface->newImageSnapshot();
SkPaint paint;
static const SkColor kColors[] =
{ SK_ColorBLUE, SK_ColorYELLOW, SK_ColorGREEN, SK_ColorWHITE };
- paint.setShader(SkGradientShader::CreateRadial(SkPoint::Make(0,0), kBmpSize / 2.f, kColors,
- nullptr, SK_ARRAY_COUNT(kColors),
- SkShader::kMirror_TileMode))->unref();
+ paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(0,0), kBmpSize / 2.f, kColors,
+ nullptr, SK_ARRAY_COUNT(kColors),
+ SkShader::kMirror_TileMode));
SkBitmap rgbBmp;
rgbBmp.allocN32Pixels(kBmpSize, kBmpSize, true);
SkCanvas canvas(rgbBmp);
static const SkColor kColors[] =
{ SK_ColorBLUE, SK_ColorYELLOW, SK_ColorGREEN, SK_ColorWHITE };
SkScalar r = (width + height) / 4.f;
- paint.setShader(SkGradientShader::CreateRadial(SkPoint::Make(0,0), r, kColors,
- nullptr, SK_ARRAY_COUNT(kColors),
- SkShader::kMirror_TileMode))->unref();
+ paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(0,0), r, kColors,
+ nullptr, SK_ARRAY_COUNT(kColors),
+ SkShader::kMirror_TileMode));
surface->getCanvas()->drawPaint(paint);
return surface->newImageSnapshot();
static const int kWidth = kColWidth * kNumCols;
static const int kHeight = 750;
-static SkShader* make_shader(const SkRect& bounds) {
+static sk_sp<SkShader> make_shader(const SkRect& bounds) {
const SkPoint pts[] = {
{ bounds.left(), bounds.top() },
{ bounds.right(), bounds.bottom() },
const SkColor colors[] = {
SK_ColorRED, SK_ColorGREEN,
};
- return SkGradientShader::CreateLinear(pts,
- colors, nullptr, SK_ARRAY_COUNT(colors),
- SkShader::kRepeat_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+ SkShader::kRepeat_TileMode);
}
class LcdBlendGM : public skiagm::GM {
if (useGrad) {
SkRect r;
r.setXYWH(0, y - fTextHeight, SkIntToScalar(kColWidth), fTextHeight);
- paint.setShader(make_shader(r))->unref();
+ paint.setShader(make_shader(r));
}
SkString string(gModes[m].fLabel);
canvas->drawText(gModes[m].fLabel, string.size(), 0, y, paint);
paint);
}
-static void draw_scene(SkCanvas* canvas, SkColorFilter* filter,
- SkXfermode::Mode mode, SkShader* s1,
- SkShader* s2) {
+static void draw_scene(SkCanvas* canvas, SkColorFilter* filter, SkXfermode::Mode mode,
+ const sk_sp<SkShader>& s1, const sk_sp<SkShader>& s2) {
SkPaint paint;
paint.setAntiAlias(true);
SkRect r, c, bounds = SkRect::MakeWH(kSize, kSize);
SkScalar pos[] = { 0.2f, 1.0f };
fFilter.reset(SkLumaColorFilter::Create());
- fGr1.reset(SkGradientShader::CreateLinear(g1Points,
- g1Colors,
- pos,
- SK_ARRAY_COUNT(g1Colors),
- SkShader::kClamp_TileMode));
- fGr2.reset(SkGradientShader::CreateLinear(g2Points,
- g2Colors,
- pos,
- SK_ARRAY_COUNT(g2Colors),
- SkShader::kClamp_TileMode));
+ fGr1 = SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_COUNT(g1Colors),
+ SkShader::kClamp_TileMode);
+ fGr2 = SkGradientShader::MakeLinear(g2Points, g2Colors, pos, SK_ARRAY_COUNT(g2Colors),
+ SkShader::kClamp_TileMode);
}
protected:
SkXfermode::kDstIn_Mode,
};
struct {
- SkShader* fShader1;
- SkShader* fShader2;
+ const sk_sp<SkShader>& fShader1;
+ const sk_sp<SkShader>& fShader2;
} shaders[] = {
{ nullptr, nullptr },
{ nullptr, fGr2 },
private:
SkAutoTUnref<SkColorFilter> fFilter;
- SkAutoTUnref<SkShader> fGr1, fGr2;
+ sk_sp<SkShader> fGr1, fGr2;
typedef skiagm::GM INHERITED;
};
SkPoint::Make(0, SkIntToScalar(80)) };
SkColor colors[2] = { 0xFFFFFFFF, 0x40404040 };
SkScalar pos[2] = { 0, SkIntToScalar(80) };
- paint.setShader(SkGradientShader::CreateLinear(
- pts, colors, pos, 2, SkShader::kClamp_TileMode))->unref();
+ paint.setShader(SkGradientShader::MakeLinear(
+ pts, colors, pos, 2, SkShader::kClamp_TileMode));
const char* str = "e";
canvas.drawText(str, strlen(str), SkIntToScalar(-10), SkIntToScalar(80), paint);
}
*/
#include "gm.h"
-#include "SkBitmapProcShader.h"
#include "SkColorFilter.h"
#include "SkGradientShader.h"
namespace skiagm {
// Using gradients because GPU doesn't currently have an implementation of SkColorShader (duh!)
-static SkShader* make_color_shader(SkColor color) {
+static sk_sp<SkShader> make_color_shader(SkColor color) {
static const SkPoint kPts[] = {{0, 0}, {1, 1}};
SkColor colors[] = {color, color};
- return SkGradientShader::CreateLinear(kPts, colors, nullptr, 2, SkShader::kClamp_TileMode);
+ return SkGradientShader::MakeLinear(kPts, colors, nullptr, 2, SkShader::kClamp_TileMode);
}
-static SkShader* make_solid_shader() {
+static sk_sp<SkShader> make_solid_shader() {
return make_color_shader(SkColorSetARGB(0xFF, 0x42, 0x82, 0x21));
}
-static SkShader* make_transparent_shader() {
+static sk_sp<SkShader> make_transparent_shader() {
return make_color_shader(SkColorSetARGB(0x80, 0x10, 0x70, 0x20));
}
-static SkShader* make_trans_black_shader() {
+static sk_sp<SkShader> make_trans_black_shader() {
return make_color_shader(0x0);
}
// draws a background behind each test rect to see transparency
-static SkShader* make_bg_shader(int checkSize) {
+static sk_sp<SkShader> make_bg_shader(int checkSize) {
SkBitmap bmp;
bmp.allocN32Pixels(2 * checkSize, 2 * checkSize);
SkCanvas canvas(bmp);
SkIntToScalar(checkSize), SkIntToScalar(checkSize));
canvas.drawRect(rect1, paint);
canvas.drawRect(rect0, paint);
- return new SkBitmapProcShader(bmp, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);
+ return SkShader::MakeBitmapShader(bmp, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);
}
class ModeColorFilterGM : public GM {
}
protected:
- virtual SkString onShortName() {
+ SkString onShortName() override {
return SkString("modecolorfilters");
}
- virtual SkISize onISize() {
+ SkISize onISize() override {
return SkISize::Make(WIDTH, HEIGHT);
}
- virtual void onDraw(SkCanvas* canvas) {
+ void onDraw(SkCanvas* canvas) override {
// size of rect for each test case
static const int kRectWidth = 20;
static const int kRectHeight = 20;
static const int kCheckSize = 10;
if (!fBmpShader) {
- fBmpShader.reset(make_bg_shader(kCheckSize));
+ fBmpShader = make_bg_shader(kCheckSize);
}
SkPaint bgPaint;
bgPaint.setShader(fBmpShader);
bgPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
- SkShader* shaders[] = {
+ sk_sp<SkShader> shaders[] = {
nullptr, // use a paint color instead of a shader
make_solid_shader(),
make_transparent_shader(),
}
}
}
-
- for (size_t i = 0; i < SK_ARRAY_COUNT(shaders); ++i) {
- SkSafeUnref(shaders[i]);
- }
}
private:
- SkAutoTUnref<SkShader> fBmpShader;
+ sk_sp<SkShader> fBmpShader;
typedef GM INHERITED;
};
SkPoint center = SkPoint::Make(SkIntToScalar(0), SkIntToScalar(0));
SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
- SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center,
- SkIntToScalar(20),
- colors,
- pos,
- SK_ARRAY_COUNT(colors),
- SkShader::kClamp_TileMode));
+ auto shader = SkGradientShader::MakeRadial(center, 20, colors, pos, SK_ARRAY_COUNT(colors),
+ SkShader::kClamp_TileMode);
for (int i = 0; i < fPaints.count(); ++i) {
canvas->save();
#include "SkGradientShader.h"
#include "SkPatchUtils.h"
-static SkShader* make_shader() {
+static sk_sp<SkShader> make_shader() {
const SkColor colors[] = {
SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE, SK_ColorMAGENTA, SK_ColorBLUE,
SK_ColorYELLOW,
};
const SkPoint pts[] = { { 100.f / 4.f, 0.f }, { 3.f * 100.f / 4.f, 100.f } };
- return SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
- SkShader::kMirror_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+ SkShader::kMirror_TileMode);
}
static void draw_control_points(SkCanvas* canvas, const SkPoint cubics[12]) {
SkXfermode::kModulate_Mode,
};
- SkAutoTUnref<SkShader> shader(make_shader());
+ sk_sp<SkShader> shader(make_shader());
canvas->save();
for (int y = 0; y < 3; y++) {
SK_ColorBLUE, SK_ColorYELLOW,
kCellSize/10);
- fBitmapShader.reset(SkShader::CreateBitmapShader(fBitmap,
- SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode));
+ fBitmapShader = SkShader::MakeBitmapShader(fBitmap, SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode);
SkPoint pts1[] = {
{ 0, 0 },
{ SkIntToScalar(kCellSize), SkIntToScalar(kCellSize) }
};
static const SkScalar pos[] = { 0, 0.25f, 0.5f, 0.75f, SK_Scalar1 };
- fLinearGrad1.reset(SkGradientShader::CreateLinear(pts1, colors, pos,
- SK_ARRAY_COUNT(colors),
- SkShader::kClamp_TileMode));
- fLinearGrad2.reset(SkGradientShader::CreateLinear(pts2, colors, pos,
- SK_ARRAY_COUNT(colors),
- SkShader::kClamp_TileMode));
+ fLinearGrad1 = SkGradientShader::MakeLinear(pts1, colors, pos, SK_ARRAY_COUNT(colors),
+ SkShader::kClamp_TileMode);
+ fLinearGrad2 = SkGradientShader::MakeLinear(pts2, colors, pos, SK_ARRAY_COUNT(colors),
+ SkShader::kClamp_TileMode);
fPerspMatrix.reset();
fPerspMatrix.setPerspY(SK_Scalar1 / 50);
bool fDoAA;
SkPath fPath;
- SkAutoTUnref<SkShader> fBitmapShader;
- SkAutoTUnref<SkShader> fLinearGrad1;
- SkAutoTUnref<SkShader> fLinearGrad2;
+ sk_sp<SkShader> fBitmapShader;
+ sk_sp<SkShader> fLinearGrad1;
+ sk_sp<SkShader> fLinearGrad2;
SkMatrix fPerspMatrix;
SkAutoTUnref<SkImage> fImage;
SkBitmap fBitmap;
const SkScalar pos1[] = { 0, 0.75f };
const SkColor colors1[] = { SK_ColorTRANSPARENT, SK_ColorBLACK };
SkASSERT(SK_ARRAY_COUNT(pos1) == SK_ARRAY_COUNT(colors1));
- SkAutoTUnref<SkShader> gradient1(SkGradientShader::CreateLinear(pts1, colors1, pos1,
- SK_ARRAY_COUNT(pos1),
- SkShader::kClamp_TileMode));
- paint.setShader(gradient1.get());
+ paint.setShader(SkGradientShader::MakeLinear(pts1, colors1, pos1, SK_ARRAY_COUNT(pos1),
+ SkShader::kClamp_TileMode));
canvas->drawRect(underlineRect, paint);
const SkPoint pts2[] = { SkPoint::Make(iBox.x() - iBox.width() * kGradientPad, 0),
SK_ColorBLACK
};
SkASSERT(SK_ARRAY_COUNT(pos2) == SK_ARRAY_COUNT(colors2));
- SkAutoTUnref<SkShader> gradient2(SkGradientShader::CreateLinear(pts2, colors2, pos2,
- SK_ARRAY_COUNT(pos2),
- SkShader::kClamp_TileMode));
- paint.setShader(gradient2.get());
+ paint.setShader(SkGradientShader::MakeLinear(pts2, colors2, pos2, SK_ARRAY_COUNT(pos2),
+ SkShader::kClamp_TileMode));
canvas->drawText(kSkiaStr, textLen, 0, 0, paint);
}
canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint);
canvas->drawRect(SkRect::MakeXYWH(fSceneSize * 1.1f, 0, fSceneSize, fSceneSize), paint);
- SkAutoTUnref<SkShader> pictureShader(
- SkShader::CreatePictureShader(fPicture, kTileConfigs[tileMode].tmx,
- kTileConfigs[tileMode].tmy, &localMatrix, nullptr));
- paint.setShader(pictureShader.get());
+ paint.setShader(SkShader::MakePictureShader(fPicture, kTileConfigs[tileMode].tmx,
+ kTileConfigs[tileMode].tmy, &localMatrix,
+ nullptr));
canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint);
canvas->translate(fSceneSize * 1.1f, 0);
- SkAutoTUnref<SkShader> bitmapShader(SkShader::CreateBitmapShader(
- fBitmap,
- kTileConfigs[tileMode].tmx,
- kTileConfigs[tileMode].tmy,
- &localMatrix));
- paint.setShader(bitmapShader.get());
+ paint.setShader(SkShader::MakeBitmapShader(fBitmap,
+ kTileConfigs[tileMode].tmx,
+ kTileConfigs[tileMode].tmy,
+ &localMatrix));
canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint);
canvas->restore();
SkScalar fTileSize;
SkScalar fSceneSize;
- SkAutoTUnref<SkPicture> fPicture;
+ sk_sp<SkPicture> fPicture;
SkBitmap fBitmap;
typedef GM INHERITED;
p.setStrokeWidth(10);
c->drawLine(20, 20, 80, 80, p);
- SkAutoTUnref<SkPicture> picture(recorder.endRecording());
- SkAutoTUnref<SkShader> shader(
- SkShader::CreatePictureShader(picture.get(), SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode, nullptr, nullptr));
+ sk_sp<SkPicture> picture(recorder.endRecording());
+ sk_sp<SkShader> shader(SkShader::MakePictureShader(picture, SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode,
+ nullptr, nullptr));
p.setColor(sk_tool_utils::color_to_565(0xFF8BC34A)); // green
canvas->drawPaint(p);
SkPictureRecorder recorder;
SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPictureSize);
draw_scene(pictureCanvas, kPictureSize);
- SkAutoTUnref<SkPicture> picture(recorder.endRecording());
+ sk_sp<SkPicture> picture(recorder.endRecording());
SkPoint offset = SkPoint::Make(100, 100);
pictureCanvas = recorder.beginRecording(SkRect::MakeXYWH(offset.x(), offset.y(),
kPictureSize, kPictureSize));
pictureCanvas->translate(offset.x(), offset.y());
draw_scene(pictureCanvas, kPictureSize);
- SkAutoTUnref<SkPicture> offsetPicture(recorder.endRecording());
+ sk_sp<SkPicture> offsetPicture(recorder.endRecording());
for (unsigned i = 0; i < SK_ARRAY_COUNT(tiles); ++i) {
SkRect tile = SkRect::MakeXYWH(tiles[i].x * kPictureSize,
localMatrix.postScale(kFillSize / (2 * kPictureSize),
kFillSize / (2 * kPictureSize));
- SkPicture* picturePtr = picture.get();
+ sk_sp<SkPicture>& pictureRef = picture;
SkRect* tilePtr = &tile;
if (tile == SkRect::MakeWH(kPictureSize, kPictureSize)) {
// When the tile == picture bounds, exercise the picture + offset path.
- picturePtr = offsetPicture.get();
+ pictureRef = offsetPicture;
tilePtr = nullptr;
}
- fShaders[i].reset(SkShader::CreatePictureShader(picturePtr,
- SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode,
- &localMatrix,
- tilePtr));
+ fShaders[i] = SkShader::MakePictureShader(pictureRef, SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode, &localMatrix,
+ tilePtr);
}
}
}
private:
- SkAutoTUnref<SkShader> fShaders[SK_ARRAY_COUNT(tiles)];
+ sk_sp<SkShader> fShaders[SK_ARRAY_COUNT(tiles)];
typedef GM INHERITED;
};
SkCanvas canvas(bmp);
SkPoint pts[] = { {0, 0}, {0, SkIntToScalar(height)} };
SkColor colors0[] = { 0xFF1060B0 , 0xFF102030 };
- paint.setShader(SkGradientShader::CreateLinear(pts, colors0, nullptr, 2,
- SkShader::kClamp_TileMode))->unref();
+ paint.setShader(SkGradientShader::MakeLinear(pts, colors0, nullptr, 2,
+ SkShader::kClamp_TileMode));
canvas.drawPaint(paint);
SkColor colors1[] = { 0xFFA07010 , 0xFFA02080 };
paint.setAntiAlias(true);
- paint.setShader(SkGradientShader::CreateLinear(pts, colors1, nullptr, 2,
- SkShader::kClamp_TileMode))->unref();
+ paint.setShader(SkGradientShader::MakeLinear(pts, colors1, nullptr, 2,
+ SkShader::kClamp_TileMode));
canvas.drawCircle(SkIntToScalar(width) / 2, SkIntToScalar(height) / 2,
SkIntToScalar(width + height) / 5, paint);
}
SkPoint center = SkPoint::Make(SkIntToScalar(-5), SkIntToScalar(30));
SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
- SkShader* s = SkGradientShader::CreateRadial(center,
- SkIntToScalar(20),
- colors,
- pos,
- SK_ARRAY_COUNT(colors),
- SkShader::kClamp_TileMode);
- p.setShader(s)->unref();
+ p.setShader(SkGradientShader::MakeRadial(center, 20, colors, pos,
+ SK_ARRAY_COUNT(colors),
+ SkShader::kClamp_TileMode));
fPaints.push_back(p);
}
SkPoint center = SkPoint::Make(SkIntToScalar(0), SkIntToScalar(0));
SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
- SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center,
- SkIntToScalar(20),
- colors,
- pos,
- SK_ARRAY_COUNT(colors),
- SkShader::kClamp_TileMode));
+ auto shader = SkGradientShader::MakeRadial(center, 20, colors, pos, SK_ARRAY_COUNT(colors),
+ SkShader::kClamp_TileMode);
for (int i = 0; i < fPaints.count(); ++i) {
canvas->save();
public:
SamplerStressGM()
: fTextureCreated(false)
- , fShader(nullptr)
, fMaskFilter(nullptr) {
}
- virtual ~SamplerStressGM() {
- }
-
protected:
SkString onShortName() override {
}
void createShader() {
- if (fShader.get()) {
+ if (fShader) {
return;
}
createTexture();
- fShader.reset(SkShader::CreateBitmapShader(fTexture,
- SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode));
+ fShader = SkShader::MakeBitmapShader(fTexture, SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode);
}
void createMaskFilter() {
}
private:
- SkBitmap fTexture;
- bool fTextureCreated;
- SkAutoTUnref<SkShader> fShader;
+ SkBitmap fTexture;
+ bool fTextureCreated;
+ sk_sp<SkShader> fShader;
SkAutoTUnref<SkMaskFilter> fMaskFilter;
typedef GM INHERITED;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
#include "gm.h"
#include "SkGradientShader.h"
namespace skiagm {
-static SkShader* MakeLinear(SkScalar width, SkScalar height, bool alternate,
+static sk_sp<SkShader> MakeLinear(SkScalar width, SkScalar height, bool alternate,
const SkMatrix& localMatrix) {
- SkPoint pts[2] = { {0, 0}, {width, height}};
- SkColor colors[2] = {SK_ColorRED, SK_ColorGREEN};
- if (alternate) {
- pts[1].fY = 0;
- colors[0] = SK_ColorBLUE;
- colors[1] = SK_ColorYELLOW;
- }
- return SkGradientShader::CreateLinear(pts, colors, nullptr, 2,
- SkShader::kClamp_TileMode, 0, &localMatrix);
+ SkPoint pts[2] = { {0, 0}, {width, height}};
+ SkColor colors[2] = {SK_ColorRED, SK_ColorGREEN};
+ if (alternate) {
+ pts[1].fY = 0;
+ colors[0] = SK_ColorBLUE;
+ colors[1] = SK_ColorYELLOW;
+ }
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode,
+ 0, &localMatrix);
}
///////////////////////////////////////////////////////////////////////////////
class ShaderBoundsGM : public GM {
public:
- typedef SkShader* (*ShaderGenFunc)(SkScalar width, SkScalar height,
- bool alternate, const SkMatrix& localMatrix);
+ typedef sk_sp<SkShader> (*ShaderGenFunc)(SkScalar width, SkScalar height,
+ bool alternate, const SkMatrix& localMatrix);
ShaderBoundsGM(ShaderGenFunc maker, const SkString& name)
: fShaderMaker(maker),
fName(name) {
// Background shader.
SkPaint paint;
- paint.setShader(MakeShader(559, 387, false))->unref();
+ paint.setShader(MakeShader(559, 387, false));
SkRect r = SkRect::MakeXYWH(SkIntToScalar(-12), SkIntToScalar(-41),
SkIntToScalar(571), SkIntToScalar(428));
canvas->drawRect(r, paint);
// Constrained shader.
- paint.setShader(MakeShader(101, 151, true))->unref();
+ paint.setShader(MakeShader(101, 151, true));
r = SkRect::MakeXYWH(SkIntToScalar(43), SkIntToScalar(71),
SkIntToScalar(101), SkIntToScalar(151));
canvas->clipRect(r);
canvas->drawRect(r, paint);
}
- SkShader* MakeShader(int width, int height, bool background) {
+ sk_sp<SkShader> MakeShader(int width, int height, bool background) {
SkScalar scale = 0.5f;
if (background) {
scale = 0.6f;
SkScalar shaderWidth = width / scale;
SkScalar shaderHeight = height / scale;
SkMatrix shaderScale = SkMatrix::MakeScale(scale);
- SkShader* shader = fShaderMaker(shaderWidth, shaderHeight, background, shaderScale);
- return shader;
+ return fShaderMaker(shaderWidth, shaderHeight, background, shaderScale);
}
private:
ShaderGenFunc fShaderMaker;
SkString fName;
- SkShader* MakeShader(bool background);
+ sk_sp<SkShader> MakeShader(bool background);
};
///////////////////////////////////////////////////////////////////////////////
SkPaint paint;
paint.setDither(true);
- paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
- SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref();
+ paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, SK_ARRAY_COUNT(colors),
+ SkShader::kClamp_TileMode));
canvas.drawPaint(paint);
}
{ 5, gColors, nullptr },
};
-static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
- return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm);
+static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+ return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCount, tm);
}
-static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
SkPoint center;
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
- return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
- data.fPos, data.fCount, tm);
+ return SkGradientShader::MakeRadial(center, center.fX, data.fColors, data.fPos, data.fCount,
+ tm);
}
-static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
+static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
SkPoint center;
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
- return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
+ return SkGradientShader::MakeSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
}
-static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+static sk_sp<SkShader> Make2Conical(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
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::CreateTwoPointConical(
+ 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);
}
-typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
+typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
static const GradMaker gGradMakers[] = {
MakeLinear, MakeRadial, MakeSweep, Make2Conical
SK_ARRAY_COUNT(gGradMakers);
static const int bmpCount = SK_ARRAY_COUNT(tileModes) *
SK_ARRAY_COUNT(tileModes);
- SkShader* shaders[gradCount + bmpCount];
+ sk_sp<SkShader> shaders[gradCount + bmpCount];
int shdIdx = 0;
for (size_t d = 0; d < SK_ARRAY_COUNT(gGradData); ++d) {
makebm(&bm, w/16, h/4);
for (size_t tx = 0; tx < SK_ARRAY_COUNT(tileModes); ++tx) {
for (size_t ty = 0; ty < SK_ARRAY_COUNT(tileModes); ++ty) {
- shaders[shdIdx++] = SkShader::CreateBitmapShader(bm, tileModes[tx], tileModes[ty]);
+ shaders[shdIdx++] = SkShader::MakeBitmapShader(bm, tileModes[tx], tileModes[ty]);
}
}
int i = 2*s;
canvas->translate(SkIntToScalar((i / testsPerCol) * colWidth),
SkIntToScalar((i % testsPerCol) * rowHeight));
- paint.setShader(shaders[s])->unref();
+ paint.setShader(shaders[s]);
canvas->drawText(text, textLen, 0, textBase, paint);
canvas->restore();
canvas->save();
SkPaint paint;
- paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos,
- SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode))->unref();
+ paint.setShader(SkGradientShader::MakeLinear(kPts0, kColors0, kPos,
+ SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode));
canvas.drawPaint(paint);
- paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos,
- SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref();
+ paint.setShader(SkGradientShader::MakeLinear(kPts1, kColors1, kPos,
+ SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode));
canvas.drawPaint(paint);
}
canvas->translate(0, kPadY / 2 + kPointSize);
columnH += kPadY / 2 + kPointSize;
for (int lm = 0; lm < localMatrices.count(); ++lm) {
- paint.setShader(
- SkShader::CreateBitmapShader(bmp,
- SkShader::kMirror_TileMode,
- SkShader::kRepeat_TileMode,
- &localMatrices[lm].fMatrix))->unref();
+ paint.setShader(SkShader::MakeBitmapShader(bmp, SkShader::kMirror_TileMode,
+ SkShader::kRepeat_TileMode,
+ &localMatrices[lm].fMatrix));
canvas->save();
canvas->concat(matrices[m].fMatrix);
SkPaint paint;
- paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos,
- SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode))->unref();
+ paint.setShader(SkGradientShader::MakeLinear(kPts0, kColors0, kPos,
+ SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode));
canvas.drawPaint(paint);
- paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos,
- SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref();
+ paint.setShader(SkGradientShader::MakeLinear(kPts1, kColors1, kPos,
+ SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode));
canvas.drawPaint(paint);
}
localM.postRotate(20);
localM.postScale(1.15f, .85f);
- SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(fBmp,
- kTileModes[tm0],
- kTileModes[tm1],
- &localM));
-
SkPaint fillPaint;
fillPaint.setAntiAlias(true);
sk_tool_utils::set_portable_typeface(&fillPaint);
fillPaint.setTextSize(SkIntToScalar(kPointSize));
fillPaint.setFilterQuality(kLow_SkFilterQuality);
- fillPaint.setShader(shader);
+ fillPaint.setShader(SkShader::MakeBitmapShader(fBmp, kTileModes[tm0],
+ kTileModes[tm1], &localM));
canvas->drawText(kText, kTextLen, 0, 0, fillPaint);
canvas->drawText(kText, kTextLen, 0, 0, outlinePaint);
canvas->drawBitmap(fBitmap, 10, 10, &paint);
canvas->translate(0, 40);
- SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(
+ paint.setShader(SkShader::MakeBitmapShader(
fBitmap, SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode));
// see bug.skia.org/562 (shows bug as reported)
- paint.setShader(shader);
paint.setStyle(SkPaint::kFill_Style);
canvas->drawRect(SkRect::MakeXYWH(10, 10, 20, 20), paint);
paint.setShader(nullptr);
#include "gm.h"
#include "SkGradientShader.h"
-typedef SkShader* (*MakeShaderProc)(const SkColor[], int count, const SkSize&);
+typedef sk_sp<SkShader> (*MakeShaderProc)(const SkColor[], int count, const SkSize&);
-static SkShader* shader_linear(const SkColor colors[], int count, const SkSize& size) {
+static sk_sp<SkShader> shader_linear(const SkColor colors[], int count, const SkSize& size) {
SkPoint pts[] = { { 0, 0 }, { size.width(), size.height() } };
- return SkGradientShader::CreateLinear(pts, colors, nullptr, count,
- SkShader::kClamp_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, count, SkShader::kClamp_TileMode);
}
-static SkShader* shader_radial(const SkColor colors[], int count, const SkSize& size) {
+static sk_sp<SkShader> shader_radial(const SkColor colors[], int count, const SkSize& size) {
SkPoint center = { size.width()/2, size.height()/2 };
- return SkGradientShader::CreateRadial(center, size.width()/2, colors, nullptr, count,
- SkShader::kClamp_TileMode);
+ return SkGradientShader::MakeRadial(center, size.width()/2, colors, nullptr, count,
+ SkShader::kClamp_TileMode);
}
-static SkShader* shader_conical(const SkColor colors[], int count, const SkSize& size) {
+static sk_sp<SkShader> shader_conical(const SkColor colors[], int count, const SkSize& size) {
SkPoint center = { size.width()/2, size.height()/2 };
- return SkGradientShader::CreateTwoPointConical(center, size.width()/64,
- center, size.width()/2,
- colors, nullptr, count,
- SkShader::kClamp_TileMode);
+ return SkGradientShader::MakeTwoPointConical(center, size.width()/64, center, size.width()/2,
+ colors, nullptr, count, SkShader::kClamp_TileMode);
}
-static SkShader* shader_sweep(const SkColor colors[], int count, const SkSize& size) {
- return SkGradientShader::CreateSweep(size.width()/2, size.height()/2,
- colors, nullptr, count);
+static sk_sp<SkShader> shader_sweep(const SkColor colors[], int count, const SkSize& size) {
+ return SkGradientShader::MakeSweep(size.width()/2, size.height()/2, colors, nullptr, count);
}
class ShallowGradientGM : public skiagm::GM {
SkSize size = SkSize::Make(r.width(), r.height());
SkPaint paint;
- paint.setShader(fProc(colors, colorCount, size))->unref();
+ paint.setShader(fProc(colors, colorCount, size));
paint.setDither(fDither);
canvas->drawRect(r, paint);
}
SkMatrix matrix;
matrix.setScale(0.75f, 0.75f);
matrix.preRotate(30.0f);
- SkAutoTUnref<SkShader> shader(
- SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode, &matrix));
- paint->setShader(shader);
+ paint->setShader(
+ SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode,
+ &matrix));
}
static void exercise_draw_pos_text(SkCanvas* canvas,
static void gradient_paintproc(SkPaint* paint) {
const SkColor colors[] = { SK_ColorGREEN, SK_ColorBLUE };
const SkPoint pts[] = { { 0, 0 }, { W, H } };
- SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr,
- SK_ARRAY_COUNT(colors),
- SkShader::kClamp_TileMode);
- paint->setShader(s)->unref();
+ paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+ SkShader::kClamp_TileMode));
}
typedef void (*Proc)(SkCanvas*, const SkPaint&);
#define W 200
#define H 100
-static SkShader* make_shader() {
+static sk_sp<SkShader> make_shader() {
int a = 0x99;
int b = 0xBB;
SkPoint pts[] = { { 0, 0 }, { W, H } };
SkColor colors[] = { SkColorSetRGB(a, a, a), SkColorSetRGB(b, b, b) };
- return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
}
static SkSurface* make_surface(GrContext* ctx, const SkImageInfo& info, SkPixelGeometry geo,
paint.setLCDRenderText(true);
paint.setDither(true);
- paint.setShader(make_shader())->unref();
+ paint.setShader(make_shader());
canvas->drawRect(SkRect::MakeWH(W, H), paint);
paint.setShader(nullptr);
#include "SkGradientShader.h"
#include "SkTableColorFilter.h"
-static SkShader* make_shader0(int w, int h) {
+static sk_sp<SkShader> make_shader0(int w, int h) {
SkPoint pts[] = { {0, 0}, {SkIntToScalar(w), SkIntToScalar(h)} };
SkColor colors[] = {
SK_ColorBLACK, SK_ColorGREEN, SK_ColorCYAN,
SK_ColorRED, 0, SK_ColorBLUE, SK_ColorWHITE
};
- return SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
- SkShader::kClamp_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+ SkShader::kClamp_TileMode);
}
static void make_bm0(SkBitmap* bm) {
int W = 120;
SkCanvas canvas(*bm);
SkPaint paint;
- paint.setShader(make_shader0(W, H))->unref();
+ paint.setShader(make_shader0(W, H));
canvas.drawPaint(paint);
}
-static SkShader* make_shader1(int w, int h) {
+static sk_sp<SkShader> make_shader1(int w, int h) {
SkScalar cx = SkIntToScalar(w)/2;
SkScalar cy = SkIntToScalar(h)/2;
SkColor colors[] = {
SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
};
- return SkGradientShader::CreateRadial(SkPoint::Make(cx, cy), cx, colors, nullptr,
- SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode);
+ return SkGradientShader::MakeRadial(SkPoint::Make(cx, cy), cx, colors, nullptr,
+ SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode);
}
static void make_bm1(SkBitmap* bm) {
int W = 120;
SkCanvas canvas(*bm);
SkPaint paint;
- paint.setShader(make_shader1(W, H))->unref();
+ paint.setShader(make_shader1(W, H));
paint.setAntiAlias(true);
canvas.drawCircle(cx, cy, cx, paint);
}
}
SkPaint paint;
- paint.setShader(make_shader1(50, 50))->unref();
+ paint.setShader(make_shader1(50, 50));
SkRect r = SkRect::MakeWH(50, 50);
const SkScalar spacer = 10;
paint->setPathEffect(make_tile_effect())->unref();
}
-static SkShader* make_shader(const SkRect& bounds) {
+static sk_sp<SkShader> make_shader(const SkRect& bounds) {
const SkPoint pts[] = {
{ bounds.left(), bounds.top() },
{ bounds.right(), bounds.bottom() },
SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorBLACK,
SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW,
};
- return SkGradientShader::CreateLinear(pts,
- colors, nullptr, SK_ARRAY_COUNT(colors),
- SkShader::kClamp_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+ SkShader::kClamp_TileMode);
}
static void color_filter(SkPaint* paint) {
SkRect r;
r.setWH(SkIntToScalar(kWidth), 50);
- paint->setShader(make_shader(r))->unref();
+ paint->setShader(make_shader(r));
paint->setColorFilter(SkColorMatrixFilter::CreateLightingFilter(0xF0F0F0, 0))->unref();
}
}
SkISize sz = this->onISize();
- fShader.reset(SkGradientShader::CreateRadial(SkPoint::Make(SkIntToScalar(sz.width() / 2),
- SkIntToScalar(sz.height() / 2)),
- sz.width() * .66f, colors, pos,
- SK_ARRAY_COUNT(colors),
- SkShader::kRepeat_TileMode));
+ fShader = SkGradientShader::MakeRadial(SkPoint::Make(SkIntToScalar(sz.width() / 2),
+ SkIntToScalar(sz.height() / 2)),
+ sz.width() * .66f, colors, pos,
+ SK_ARRAY_COUNT(colors),
+ SkShader::kRepeat_TileMode);
}
SkString onShortName() override {
private:
SkTDArray<uint16_t> fGlyphs;
SkAutoTUnref<const SkTextBlob> fBlob;
- SkAutoTUnref<SkShader> fShader;
+ sk_sp<SkShader> fShader;
typedef skiagm::GM INHERITED;
};
SkPaint paint;
SkColor colors1[] = { SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorGRAY };
- paint.setShader(SkGradientShader::CreateSweep(65.f, 75.f, colors1,
- nullptr, SK_ARRAY_COUNT(colors1)))->unref();
- canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f,
- fBmp.width() + 10.f, fBmp.height() + 10.f), paint);
+ paint.setShader(SkGradientShader::MakeSweep(65.f, 75.f, colors1, nullptr,
+ SK_ARRAY_COUNT(colors1)));
+ canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f, fBmp.width() + 10.f, fBmp.height() + 10.f),
+ paint);
SkColor colors2[] = { SK_ColorMAGENTA, SK_ColorLTGRAY, SK_ColorYELLOW };
- paint.setShader(SkGradientShader::CreateSweep(45.f, 55.f, colors2, nullptr,
- SK_ARRAY_COUNT(colors2)))->unref();
+ paint.setShader(SkGradientShader::MakeSweep(45.f, 55.f, colors2, nullptr,
+ SK_ARRAY_COUNT(colors2)));
paint.setXfermodeMode(SkXfermode::kDarken_Mode);
- canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f,
- fBmp.width() + 10.f, fBmp.height() + 10.f), paint);
+ canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f, fBmp.width() + 10.f, fBmp.height() + 10.f),
+ paint);
SkColor colors3[] = { SK_ColorBLUE, SK_ColorLTGRAY, SK_ColorGREEN };
- paint.setShader(SkGradientShader::CreateSweep(25.f, 35.f, colors3, nullptr,
- SK_ARRAY_COUNT(colors3)))->unref();
+ paint.setShader(SkGradientShader::MakeSweep(25.f, 35.f, colors3, nullptr,
+ SK_ARRAY_COUNT(colors3)));
paint.setXfermodeMode(SkXfermode::kLighten_Mode);
- canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f,
- fBmp.width() + 10.f, fBmp.height() + 10.f), paint);
+ canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f, fBmp.width() + 10.f, fBmp.height() + 10.f),
+ paint);
}
void onDraw(SkCanvas* canvas) override {
-
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
#include "gm.h"
#include "Resources.h"
#include "SkShader.h"
#include "SkStream.h"
-
/***
*
* This GM reproduces Skia bug 2904, in which a tiled bitmap shader was failing to draw correctly
mat.setScale(121.f/360.f, 93.f/288.f);
mat.postTranslate(-72, -72);
- SkShader *shader = SkShader::CreateBitmapShader(fBitmap, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &mat);
- paint.setShader(shader);
-
- SkSafeUnref(shader);
+ paint.setShader(SkShader::MakeBitmapShader(fBitmap, SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode, &mat));
canvas->drawRectCoords(8,8,1008, 608, paint);
}
SkPaint paint;
paint.setDither(true);
- paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
- SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref();
+ paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, SK_ARRAY_COUNT(colors),
+ SkShader::kClamp_TileMode));
canvas.drawPaint(paint);
}
static void setup(SkPaint* paint, const SkBitmap& bm, bool filter,
SkShader::TileMode tmx, SkShader::TileMode tmy) {
- SkShader* shader = SkShader::CreateBitmapShader(bm, tmx, tmy);
- paint->setShader(shader)->unref();
+ paint->setShader(SkShader::MakeBitmapShader(bm, tmx, tmy));
paint->setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality);
}
static const int gWidth = 32;
static const int gHeight = 32;
-static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) {
+static sk_sp<SkShader> make_bm(SkShader::TileMode tx, SkShader::TileMode ty) {
SkBitmap bm;
makebm(&bm, kN32_SkColorType, gWidth, gHeight);
- return SkShader::CreateBitmapShader(bm, tx, ty);
+ return SkShader::MakeBitmapShader(bm, tx, ty);
}
-static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
+static sk_sp<SkShader> make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)} };
SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 };
SkScalar rad = SkIntToScalar(gWidth)/2;
int index = (int)ty;
switch (index % 3) {
case 0:
- return SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
case 1:
- return SkGradientShader::CreateRadial(center, rad, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
+ return SkGradientShader::MakeRadial(center, rad, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
case 2:
- return SkGradientShader::CreateSweep(center.fX, center.fY, colors, nullptr, SK_ARRAY_COUNT(colors));
+ return SkGradientShader::MakeSweep(center.fX, center.fY, colors, nullptr, SK_ARRAY_COUNT(colors));
}
-
return nullptr;
}
-typedef SkShader* (*ShaderProc)(SkShader::TileMode, SkShader::TileMode);
+typedef sk_sp<SkShader> (*ShaderProc)(SkShader::TileMode, SkShader::TileMode);
class Tiling2GM : public skiagm::GM {
ShaderProc fProc;
x += SkIntToScalar(50);
for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
SkPaint paint;
- paint.setShader(fProc(gModes[kx], gModes[ky]))->unref();
+ paint.setShader(fProc(gModes[kx], gModes[ky]));
canvas->save();
canvas->translate(x, y);
SkPaint paint;
paint.setDither(true);
- paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
- SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref();
+ paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos,
+ SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
canvas.drawPaint(paint);
}
static void setup(SkPaint* paint, const SkBitmap& bm, SkFilterQuality filter_level,
SkShader::TileMode tmx, SkShader::TileMode tmy) {
- SkShader* shader = SkShader::CreateBitmapShader(bm, tmx, tmy);
- paint->setShader(shader)->unref();
+ paint->setShader(SkShader::MakeBitmapShader(bm, tmx, tmy));
paint->setFilterQuality(filter_level);
}
static const int gWidth = 32;
static const int gHeight = 32;
-static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) {
+static sk_sp<SkShader> make_bm(SkShader::TileMode tx, SkShader::TileMode ty) {
SkBitmap bm;
makebm(&bm, kN32_SkColorType, gWidth, gHeight);
- return SkShader::CreateBitmapShader(bm, tx, ty);
+ return SkShader::MakeBitmapShader(bm, tx, ty);
}
-static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
+static sk_sp<SkShader> make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)} };
SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 };
SkScalar rad = SkIntToScalar(gWidth)/2;
int index = (int)ty;
switch (index % 3) {
case 0:
- return SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
case 1:
- return SkGradientShader::CreateRadial(center, rad, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
+ return SkGradientShader::MakeRadial(center, rad, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
case 2:
- return SkGradientShader::CreateSweep(center.fX, center.fY, colors, nullptr, SK_ARRAY_COUNT(colors));
+ return SkGradientShader::MakeSweep(center.fX, center.fY, colors, nullptr, SK_ARRAY_COUNT(colors));
}
return nullptr;
}
-typedef SkShader* (*ShaderProc)(SkShader::TileMode, SkShader::TileMode);
+typedef sk_sp<SkShader> (*ShaderProc)(SkShader::TileMode, SkShader::TileMode);
class ScaledTiling2GM : public skiagm::GM {
ShaderProc fProc;
x += SkIntToScalar(50);
for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
SkPaint paint;
- paint.setShader(fProc(gModes[kx], gModes[ky]))->unref();
+ paint.setShader(fProc(gModes[kx], gModes[ky]));
canvas->save();
canvas->translate(x, y);
virtual void onDraw(SkCanvas* canvas) {
SkBitmap bm = make_bitmap();
- SkShader* s =
- SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
- SkShader::kMirror_TileMode);
SkPaint paint;
paint.setAlpha(0x80);
- paint.setShader(s)->unref();
+ paint.setShader(SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode,
+ SkShader::kMirror_TileMode));
canvas->drawPaint(paint);
}
#include "SkSurface.h"
#include "gm.h"
-static void make_transparency(SkCanvas* canvas,
- SkScalar width,
- SkScalar height) {
+static void make_transparency(SkCanvas* canvas, SkScalar width, SkScalar height) {
SkPoint pts[2];
pts[0] = SkPoint::Make(0, 0);
pts[1] = SkPoint::Make(width, 0);
SkColor shaderColors[2];
shaderColors[0] = SK_AlphaTRANSPARENT;
shaderColors[1] = kColors[i];
- SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(
- pts, shaderColors, nullptr, 2, SkShader::kClamp_TileMode));
- SkRect r = SkRect::MakeXYWH(0, i * kRowHeight, width, kRowHeight);
SkPaint p;
- p.setShader(shader);
- canvas->drawRect(r, p);
+ p.setShader(SkGradientShader::MakeLinear(pts, shaderColors, nullptr, 2,
+ SkShader::kClamp_TileMode));
+ canvas->drawRect(SkRect::MakeXYWH(0, i * kRowHeight, width, kRowHeight), p);
}
}
// http://crrev.com/834303005
-static SkShader* create_checkerboard_shader(SkColor c1, SkColor c2, int size) {
+static sk_sp<SkShader> create_checkerboard_shader(SkColor c1, SkColor c2, int size) {
SkBitmap bm;
bm.allocN32Pixels(2 * size, 2 * size);
bm.eraseColor(c1);
bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2);
bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2);
- return SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode);
+ return SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);
}
// http://crrev.com/834303005
static void checkerboard(SkCanvas* canvas, SkColor c1, SkColor c2, int size) {
SkPaint paint;
- paint.setShader(create_checkerboard_shader(c1, c2, size))->unref();
+ paint.setShader(create_checkerboard_shader(c1, c2, size));
canvas->drawPaint(paint);
}
#include "SkGradientShader.h"
#include "SkRandom.h"
-static SkShader* make_shader1(SkScalar w, SkScalar h) {
+static sk_sp<SkShader> make_shader1(SkScalar w, SkScalar h) {
const SkColor colors[] = {
SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE,
SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW,
};
const SkPoint pts[] = { { w/4, 0 }, { 3*w/4, h } };
- return SkGradientShader::CreateLinear(pts, colors, nullptr,
- SK_ARRAY_COUNT(colors),
- SkShader::kMirror_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+ SkShader::kMirror_TileMode);
}
-static SkShader* make_shader2() {
- return SkShader::CreateColorShader(SK_ColorBLUE);
+static sk_sp<SkShader> make_shader2() {
+ return SkShader::MakeColorShader(SK_ColorBLUE);
}
static SkColorFilter* make_color_filter() {
SkPoint fPts[9];
SkPoint fTexs[9];
SkColor fColors[9];
- SkAutoTUnref<SkShader> fShader1;
- SkAutoTUnref<SkShader> fShader2;
+ sk_sp<SkShader> fShader1;
+ sk_sp<SkShader> fShader2;
SkAutoTUnref<SkColorFilter> fColorFilter;
public:
fTexs[3].set(0, h/2); fTexs[4].set(w/2, h/2); fTexs[5].set(w, h/2);
fTexs[6].set(0, h); fTexs[7].set(w/2, h); fTexs[8].set(w, h);
- fShader1.reset(make_shader1(w, h));
- fShader2.reset(make_shader2());
+ fShader1 = make_shader1(w, h);
+ fShader2 = make_shader2();
fColorFilter.reset(make_color_filter());
SkRandom rand;
};
const struct {
- const SkColor* fColors;
- const SkPoint* fTexs;
- SkShader* fShader;
- SkColorFilter* fColorFilter;
- uint8_t fAlpha;
+ const SkColor* fColors;
+ const SkPoint* fTexs;
+ const sk_sp<SkShader>& fShader;
+ SkColorFilter* fColorFilter;
+ uint8_t fAlpha;
} rec[] = {
{ fColors, nullptr, fShader1, nullptr , 0xFF },
{ nullptr, fTexs , fShader1, nullptr , 0xFF },
static void draw(SkCanvas* canvas, int width, int height, SkColor colors[2]) {
const SkPoint center = { SkIntToScalar(width)/2, SkIntToScalar(height)/2 };
const SkScalar radius = 40;
- SkShader* shader = SkGradientShader::CreateRadial(center, radius, colors, nullptr, 2,
- SkShader::kMirror_TileMode);
SkPaint paint;
- paint.setShader(shader)->unref();
+ paint.setShader(SkGradientShader::MakeRadial(center, radius, colors, nullptr, 2,
+ SkShader::kMirror_TileMode));
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
canvas->drawPaint(paint);
}
const SkScalar h = SkIntToScalar(H);
SkMatrix m;
m.setScale(SkIntToScalar(6), SkIntToScalar(6));
- SkShader* s = SkShader::CreateBitmapShader(fBG,
- SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode,
- &m);
+ auto s = SkShader::MakeBitmapShader(fBG, SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode, &m);
SkPaint labelP;
labelP.setAntiAlias(true);
y0 = 0;
}
}
- s->unref();
}
private:
SkMatrix lm;
lm.setScale(SkIntToScalar(16), SkIntToScalar(16));
- fBG.reset(SkShader::CreateBitmapShader(bg,
- SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode,
- &lm));
+ fBG = SkShader::MakeBitmapShader(bg, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode,
+ &lm);
SkBitmap srcBmp;
srcBmp.allocN32Pixels(kSize, kSize);
pixels[kSize * y + x] = rowColor;
}
}
- fSrc.reset(SkShader::CreateBitmapShader(srcBmp,
- SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode));
+ fSrc = SkShader::MakeBitmapShader(srcBmp, SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode);
SkBitmap dstBmp;
dstBmp.allocN32Pixels(kSize, kSize);
pixels = reinterpret_cast<SkPMColor*>(dstBmp.getPixels());
pixels[kSize * y + x] = colColor;
}
}
- fDst.reset(SkShader::CreateBitmapShader(dstBmp,
- SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode));
+ fDst = SkShader::MakeBitmapShader(dstBmp, SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode);
}
enum {
kSize = 256 >> kShift,
};
- SkAutoTUnref<SkShader> fBG;
- SkAutoTUnref<SkShader> fSrc;
- SkAutoTUnref<SkShader> fDst;
+ sk_sp<SkShader> fBG;
+ sk_sp<SkShader> fSrc;
+ sk_sp<SkShader> fDst;
typedef GM INHERITED;
};
SkMatrix lm;
lm.setScale(SkIntToScalar(kCheckSize), SkIntToScalar(kCheckSize));
- fBGShader.reset(SkShader::CreateBitmapShader(bg,
- SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode,
- &lm));
+ fBGShader = SkShader::MakeBitmapShader(bg, SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode, &lm);
SkPaint bmpPaint;
- static const SkPoint kCenter = { SkIntToScalar(kSize) / 2, SkIntToScalar(kSize) / 2 };
- static const SkColor kColors[] = { SK_ColorTRANSPARENT, 0x80800000,
- 0xF020F060, SK_ColorWHITE };
- bmpPaint.setShader(SkGradientShader::CreateRadial(kCenter,
- 3 * SkIntToScalar(kSize) / 4,
- kColors,
- nullptr,
- SK_ARRAY_COUNT(kColors),
- SkShader::kRepeat_TileMode))->unref();
+ const SkPoint kCenter = { SkIntToScalar(kSize) / 2, SkIntToScalar(kSize) / 2 };
+ const SkColor kColors[] = {
+ SK_ColorTRANSPARENT, 0x80800000, 0xF020F060, SK_ColorWHITE
+ };
+ bmpPaint.setShader(SkGradientShader::MakeRadial(kCenter, 3 * SkIntToScalar(kSize) / 4,
+ kColors, nullptr, SK_ARRAY_COUNT(kColors),
+ SkShader::kRepeat_TileMode));
SkBitmap bmp;
bmp.allocN32Pixels(kSize, kSize);
7 * SkIntToScalar(kSize) / 8, 7 * SkIntToScalar(kSize) / 8};
bmpCanvas.drawRect(rect, bmpPaint);
- fBmpShader.reset(SkShader::CreateBitmapShader(bmp,
- SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode));
+ fBmpShader = SkShader::MakeBitmapShader(bmp, SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode);
}
enum {
kTestsPerRow = 15,
};
- SkAutoTUnref<SkShader> fBGShader;
- SkAutoTUnref<SkShader> fBmpShader;
+ sk_sp<SkShader> fBGShader;
+ sk_sp<SkShader> fBmpShader;
typedef GM INHERITED;
};
uint32_t* pixel = bm.getAddr32(1,0);
*pixel = SK_ColorBLUE;
- SkShader* bitmapShader = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode);
- SkAutoTUnref<SkShader> aur(bitmapShader);
+ auto bitmapShader = SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode);
// Flatten, storing it in the bitmap heap.
SkBitmapHeap heap(1, 1);
fPts[1].set(w, 0);
fPts[2].set(w, h);
fPts[3].set(0, h);
- SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode);
- paint->setShader(s)->unref();
-
+ paint->setShader(SkShader::MakeBitmapShader(bm, SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode));
}
void draw(SkCanvas* canvas, SkPaint* paint) {
pts[2].set(SkIntToScalar(d.fWidth), SkIntToScalar(d.fHeight));
pts[3].set(0, SkIntToScalar(d.fHeight));
SkPaint paint;
- SkShader* shader = SkShader::CreateBitmapShader(d.fBitmap,
- SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
- paint.setShader(shader)->unref();
+ paint.setShader(SkShader::MakeBitmapShader(d.fBitmap, SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode));
canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, pts, pts,
nullptr, nullptr, nullptr, 0, paint);
}
0.0078740157f,
SkIntToScalar(239),
0, 0, SK_Scalar1);
- SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode, &matrix);
-
SkPaint paint;
- paint.setShader(s)->unref();
+ paint.setShader(SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode, &matrix));
SkRect r = SkRect::MakeXYWH(681, 239, 695, 253);
c.drawRect(r, paint);
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 }};
- SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
SkPaint paint;
- paint.setShader(s)->unref();
+ paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2,
+ SkShader::kClamp_TileMode));
SkBitmap bm;
bm.allocN32Pixels(2000, 1);
const SkScalar* fRadius; // 2
SkShader::TileMode fTileMode;
- void gradCheck(skiatest::Reporter* reporter, SkShader* shader,
+ void gradCheck(skiatest::Reporter* reporter, const sk_sp<SkShader>& shader,
SkShader::GradientInfo* info,
SkShader::GradientType gt) const {
SkAutoTMalloc<SkColor> colorStorage(fColorCount);
static void none_gradproc(skiatest::Reporter* reporter, const GradRec&) {
- SkAutoTUnref<SkShader> s(SkShader::CreateEmptyShader());
+ sk_sp<SkShader> s(SkShader::MakeEmptyShader());
REPORTER_ASSERT(reporter, SkShader::kNone_GradientType == s->asAGradient(nullptr));
}
}
static void linear_gradproc(skiatest::Reporter* reporter, const GradRec& rec) {
- SkAutoTUnref<SkShader> s(SkGradientShader::CreateLinear(rec.fPoint,
- rec.fColors,
- rec.fPos,
- rec.fColorCount,
- rec.fTileMode));
+ 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);
}
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));
+ 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);
}
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));
+ 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);
}
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));
+ sk_sp<SkShader> s(SkGradientShader::MakeTwoPointConical(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);
};
SkColor colors[] = { SK_ColorBLUE, SK_ColorBLUE };
const SkScalar pos[] = { 0, SK_Scalar1 };
- SkAutoTUnref<SkShader> s(SkGradientShader::CreateLinear(pts,
- colors,
- pos,
- 2,
- SkShader::kClamp_TileMode));
+ SkPaint paint;
+ paint.setShader(SkGradientShader::MakeLinear(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);
const SkPoint pts[] = {{ 100, 50 }, { 100.0001f, 50000 }};
const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
const SkScalar pos[] = { 0, 1 };
- SkAutoTUnref<SkShader> gradient(
- SkGradientShader::CreateLinear(pts, colors, pos, 2, SkShader::kClamp_TileMode));
-
SkPaint paint;
- paint.setShader(gradient);
+ paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 2, SkShader::kClamp_TileMode));
surface->getCanvas()->drawPaint(paint);
}
const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE };
const SkScalar pos[] = {0, 0.200000003f, 0.800000012f, 1 };
-
- SkAutoTUnref<SkShader> gradient(
- SkGradientShader::CreateLinear(pts, colors, pos, 4, SkShader::kClamp_TileMode));
-
SkPaint paint;
- paint.setShader(gradient);
+ paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 4, SkShader::kClamp_TileMode));
+
SkRect r = {0, 83, 1254, 620};
surface->getCanvas()->drawRect(r, paint);
}
surface->getCanvas()->clear(SK_ColorRED);
const SkColor colors[] = { SK_ColorGREEN, SK_ColorBLUE };
- SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(
+ SkPaint p;
+ p.setShader(SkGradientShader::MakeTwoPointConical(
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.
SkColor colors[2];
colors[0] = SK_ColorWHITE;
colors[1] = SK_ColorBLACK;
- SkAutoTUnref<SkShader> shader(
- SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2,
- SkShader::kClamp_TileMode)
- );
SkPaint paint;
- paint.setShader(shader);
+ paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2,
+ SkShader::kClamp_TileMode));
canvas.drawCircle(x, y, radius, paint);
return bitmap;
}
SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1};
SkScalar radius = SkIntToScalar(5);
- SkAutoTUnref<SkShader> s(SkGradientShader::CreateRadial(
- center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
SkPaint gradientPaint;
- gradientPaint.setShader(s);
+ gradientPaint.setShader(SkGradientShader::MakeRadial(
+ center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
// Test using the image filter
{
SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1};
SkScalar radius = SkIntToScalar(5);
- SkAutoTUnref<SkShader> s(SkGradientShader::CreateRadial(
- center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
SkPaint gradientPaint;
- gradientPaint.setShader(s);
+ gradientPaint.setShader(SkGradientShader::MakeRadial(
+ center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
// Test using the image filter
{
SkCanvas canvas(bitmap);
canvas.clear(SK_ColorGREEN);
- SkShader* shader = SkShader::CreatePictureShader(
- nullptr, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr, nullptr);
- paint.setShader(shader)->unref();
+ paint.setShader(SkShader::MakePictureShader(
+ nullptr, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr, nullptr));
canvas.drawRect(SkRect::MakeWH(1,1), paint);
REPORTER_ASSERT(reporter, *bitmap.getAddr32(0,0) == SK_ColorGREEN);
SkPictureRecorder factory;
factory.beginRecording(0, 0, nullptr, 0);
- SkAutoTUnref<SkPicture> picture(factory.endRecording());
- shader = SkShader::CreatePictureShader(
- picture.get(), SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr, nullptr);
- paint.setShader(shader)->unref();
+ sk_sp<SkPicture> picture(factory.endRecording());
+ paint.setShader(SkShader::MakePictureShader(std::move(picture), SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode, nullptr, nullptr));
canvas.drawRect(SkRect::MakeWH(1,1), paint);
REPORTER_ASSERT(reporter, *bitmap.getAddr32(0,0) == SK_ColorGREEN);
bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2));
bitmap.eraseColor(SK_ColorBLUE);
*(bitmap.getAddr32(0, 0)) = SK_ColorGREEN;
- SkShader* shader = SkShader::CreateBitmapShader(bitmap, SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode);
- paint.setShader(shader)->unref();
- REPORTER_ASSERT(reporter, shader->isABitmap());
+ paint.setShader(SkShader::MakeBitmapShader(bitmap, SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode));
+ REPORTER_ASSERT(reporter, paint.getShader()->isABitmap());
canvas->drawRect(SkRect::MakeWH(10, 10), paint);
}
DEF_TEST(MiniRecorderLeftHanging, r) {
// Any shader or other ref-counted effect will do just fine here.
SkPaint paint;
- paint.setShader(SkShader::CreateColorShader(SK_ColorRED))->unref();
+ paint.setShader(SkShader::MakeColorShader(SK_ColorRED));
SkMiniRecorder rec;
REPORTER_ASSERT(r, rec.drawRect(SkRect::MakeWH(20,30), paint));
SkRect bounds = SkRect::MakeWH(320, 240);
SkPaint paint;
- paint.setShader(SkShader::CreateEmptyShader())->unref();
+ paint.setShader(SkShader::MakeEmptyShader());
REPORTER_ASSERT(r, paint.getShader()->unique());
{
bmp.setInfo(info);
// test 1: bitmap without pixel data
- SkShader* shader = SkShader::CreateBitmapShader(bmp,
+ auto shader = SkShader::MakeBitmapShader(bmp,
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
REPORTER_ASSERT(reporter, shader);
REPORTER_ASSERT(reporter, !shader->isOpaque());
- shader->unref();
// From this point on, we have pixels
bmp.allocPixels(info);
// test 2: not opaque by default
- shader = SkShader::CreateBitmapShader(bmp,
+ shader = SkShader::MakeBitmapShader(bmp,
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
REPORTER_ASSERT(reporter, shader);
REPORTER_ASSERT(reporter, !shader->isOpaque());
- shader->unref();
// test 3: explicitly opaque
bmp.setAlphaType(kOpaque_SkAlphaType);
- shader = SkShader::CreateBitmapShader(bmp,
+ shader = SkShader::MakeBitmapShader(bmp,
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
REPORTER_ASSERT(reporter, shader);
REPORTER_ASSERT(reporter, shader->isOpaque());
- shader->unref();
// test 4: explicitly not opaque
bmp.setAlphaType(kPremul_SkAlphaType);
- shader = SkShader::CreateBitmapShader(bmp,
+ shader = SkShader::MakeBitmapShader(bmp,
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
REPORTER_ASSERT(reporter, shader);
REPORTER_ASSERT(reporter, !shader->isOpaque());
- shader->unref();
-
}
-static void test_gradient(skiatest::Reporter* reporter)
-{
+static void test_gradient(skiatest::Reporter* reporter) {
SkPoint pts[2];
pts[0].iset(0, 0);
pts[1].iset(1, 0);
// test 1: all opaque
colors[0] = SkColorSetARGB(0xFF, 0, 0, 0);
colors[1] = SkColorSetARGB(0xFF, 0, 0, 0);
- SkShader* grad = SkGradientShader::CreateLinear(pts, colors, pos, count,
- mode);
+ auto grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
REPORTER_ASSERT(reporter, grad);
REPORTER_ASSERT(reporter, grad->isOpaque());
- grad->unref();
// test 2: all 0 alpha
colors[0] = SkColorSetARGB(0, 0, 0, 0);
colors[1] = SkColorSetARGB(0, 0, 0, 0);
- grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode);
+ grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
REPORTER_ASSERT(reporter, grad);
REPORTER_ASSERT(reporter, !grad->isOpaque());
- grad->unref();
// test 3: one opaque, one transparent
colors[0] = SkColorSetARGB(0xFF, 0, 0, 0);
colors[1] = SkColorSetARGB(0x40, 0, 0, 0);
- grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode);
+ grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
REPORTER_ASSERT(reporter, grad);
REPORTER_ASSERT(reporter, !grad->isOpaque());
- grad->unref();
// test 4: test 3, swapped
colors[0] = SkColorSetARGB(0x40, 0, 0, 0);
colors[1] = SkColorSetARGB(0xFF, 0, 0, 0);
- grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode);
+ grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
REPORTER_ASSERT(reporter, grad);
REPORTER_ASSERT(reporter, !grad->isOpaque());
- grad->unref();
}
-static void test_color(skiatest::Reporter* reporter)
-{
+static void test_color(skiatest::Reporter* reporter) {
SkColorShader colorShader1(SkColorSetARGB(0,0,0,0));
REPORTER_ASSERT(reporter, !colorShader1.isOpaque());
SkColorShader colorShader2(SkColorSetARGB(0xFF,0,0,0));