aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-03-13 14:13:58 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-13 14:13:58 -0700
commit1a9b9640843a64af8d9d90337ec3b3fea663196a (patch)
tree37dae22b03c887f2f0087309bbac84c983c828c5 /gm
parent9283d20afc27571f7a871d1bd1100dd5df584941 (diff)
Reland of "more shader-->sp conversions (patchset #5 id:80001 of https://codereview.chromium.org/1789633002/ )"
Diffstat (limited to 'gm')
-rw-r--r--gm/gradientDirtyLaundry.cpp26
-rw-r--r--gm/gradient_matrix.cpp19
-rw-r--r--gm/gradients.cpp172
-rw-r--r--gm/gradients_2pt_conical.cpp181
-rw-r--r--gm/gradients_no_texture.cpp31
-rw-r--r--gm/gradtext.cpp27
-rw-r--r--gm/hairmodes.cpp10
-rw-r--r--gm/imagefiltersclipped.cpp7
-rw-r--r--gm/imagefilterscropexpand.cpp7
-rw-r--r--gm/imagefiltersscaled.cpp7
-rw-r--r--gm/imagefilterstransformed.cpp7
-rw-r--r--gm/imagefromyuvtextures.cpp6
-rw-r--r--gm/imagetoyuvplanes.cpp6
-rw-r--r--gm/lcdblendmodes.cpp9
-rw-r--r--gm/lumafilter.cpp25
-rw-r--r--gm/matrixconvolution.cpp4
-rw-r--r--gm/modecolorfilters.cpp31
-rwxr-xr-xgm/ovals.cpp8
-rw-r--r--gm/patch.cpp8
-rw-r--r--gm/perspshaders.cpp21
-rw-r--r--gm/pictureimagegenerator.cpp12
-rw-r--r--gm/pictureshader.cpp27
-rw-r--r--gm/pictureshadertile.cpp18
-rw-r--r--gm/rectangletexture.cpp8
-rw-r--r--gm/rects.cpp10
-rw-r--r--gm/roundrects.cpp8
-rw-r--r--gm/samplerstress.cpp17
-rw-r--r--gm/shaderbounds.cpp36
-rw-r--r--gm/shadertext.cpp30
-rw-r--r--gm/shadertext2.cpp16
-rw-r--r--gm/shadertext3.cpp16
-rw-r--r--gm/shadows.cpp3
-rw-r--r--gm/shallowgradient.cpp28
-rw-r--r--gm/skbug_257.cpp7
-rw-r--r--gm/srcmode.cpp6
-rw-r--r--gm/surface.cpp6
-rw-r--r--gm/tablecolorfilter.cpp18
-rw-r--r--gm/textbloblooper.cpp9
-rw-r--r--gm/textblobshader.cpp12
-rw-r--r--gm/texturedomaineffect.cpp24
-rw-r--r--gm/tiledscaledbitmap.cpp9
-rw-r--r--gm/tilemodes.cpp24
-rw-r--r--gm/tilemodes_scaled.cpp23
-rw-r--r--gm/tinybitmap.cpp6
-rw-r--r--gm/transparency.cpp19
-rw-r--r--gm/vertices.cpp29
-rw-r--r--gm/verylargebitmap.cpp5
-rw-r--r--gm/xfermodes.cpp7
-rw-r--r--gm/xfermodes2.cpp22
-rw-r--r--gm/xfermodes3.cpp31
50 files changed, 472 insertions, 626 deletions
diff --git a/gm/gradientDirtyLaundry.cpp b/gm/gradientDirtyLaundry.cpp
index 8ef5fc9229..3fca7f276c 100644
--- a/gm/gradientDirtyLaundry.cpp
+++ b/gm/gradientDirtyLaundry.cpp
@@ -35,27 +35,22 @@ static const GradData gGradData[] = {
// { 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,
@@ -86,8 +81,7 @@ protected:
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));
}
diff --git a/gm/gradient_matrix.cpp b/gm/gradient_matrix.cpp
index 8f665a1b94..816891847d 100644
--- a/gm/gradient_matrix.cpp
+++ b/gm/gradient_matrix.cpp
@@ -61,22 +61,22 @@ static const SkScalar TESTGRID_Y = SkIntToScalar(200);
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
@@ -97,11 +97,8 @@ static void draw_gradients(SkCanvas* canvas,
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.
diff --git a/gm/gradients.cpp b/gm/gradients.cpp
index eeb5bcb9ff..29d0f31e96 100644
--- a/gm/gradients.cpp
+++ b/gm/gradients.cpp
@@ -40,59 +40,57 @@ static const GradData gGradData[] = {
{ 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
};
@@ -136,11 +134,8 @@ protected:
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();
@@ -196,11 +191,8 @@ protected:
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();
@@ -287,12 +279,11 @@ protected:
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);
}
@@ -329,13 +320,13 @@ DEF_SIMPLE_GM(small_color_stop, canvas, 100, 150) {
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);
}
@@ -368,13 +359,11 @@ protected:
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:
@@ -413,11 +402,9 @@ protected:
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())
};
@@ -464,25 +451,19 @@ protected:
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);
@@ -519,8 +500,8 @@ protected:
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 {
@@ -531,7 +512,7 @@ protected:
}
private:
- SkAutoTUnref<SkShader> fShader;
+ sk_sp<SkShader> fShader;
bool fDither;
typedef GM INHERITED;
@@ -556,8 +537,8 @@ protected:
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 {
@@ -569,7 +550,7 @@ protected:
}
private:
- SkAutoTUnref<SkShader> fShader;
+ sk_sp<SkShader> fShader;
bool fDither;
typedef GM INHERITED;
@@ -604,8 +585,8 @@ protected:
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);
}
}
@@ -621,7 +602,7 @@ protected:
}
private:
- SkAutoTUnref<SkShader> fShader[100];
+ sk_sp<SkShader> fShader[100];
bool fDither;
typedef GM INHERITED;
@@ -673,13 +654,12 @@ protected:
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);
}
}
@@ -704,27 +684,27 @@ struct GradRun {
#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);
}
/*
@@ -762,7 +742,7 @@ DEF_SIMPLE_GM(gradients_dup_color_stops, canvas, 704, 564) {
4,
},
};
- SkShader* (*factories[])(const GradRun&, SkShader::TileMode) {
+ sk_sp<SkShader> (*factories[])(const GradRun&, SkShader::TileMode) {
make_linear, make_radial, make_conical, make_sweep
};
@@ -777,7 +757,7 @@ DEF_SIMPLE_GM(gradients_dup_color_stops, canvas, 704, 564) {
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);
}
@@ -799,11 +779,9 @@ static void draw_many_stops(SkCanvas* canvas, uint32_t flags) {
}
}
- 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);
}
diff --git a/gm/gradients_2pt_conical.cpp b/gm/gradients_2pt_conical.cpp
index 39ebb4a1f9..28ed8bb965 100644
--- a/gm/gradients_2pt_conical.cpp
+++ b/gm/gradients_2pt_conical.cpp
@@ -37,235 +37,218 @@ static const GradData gGradData[] = {
{ 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,
@@ -347,10 +330,8 @@ protected:
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();
diff --git a/gm/gradients_no_texture.cpp b/gm/gradients_no_texture.cpp
index 00c865c178..b688aab4cb 100644
--- a/gm/gradients_no_texture.cpp
+++ b/gm/gradients_no_texture.cpp
@@ -26,51 +26,50 @@ static const GradData gGradData[] = {
{ 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,
@@ -107,8 +106,7 @@ protected:
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));
@@ -256,9 +254,8 @@ protected:
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();
diff --git a/gm/gradtext.cpp b/gm/gradtext.cpp
index acb88d6e52..d66454760b 100644
--- a/gm/gradtext.cpp
+++ b/gm/gradtext.cpp
@@ -11,28 +11,25 @@
#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 {
@@ -56,7 +53,7 @@ protected:
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);
@@ -84,7 +81,7 @@ protected:
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);
@@ -140,12 +137,12 @@ protected:
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);
diff --git a/gm/hairmodes.cpp b/gm/hairmodes.cpp
index 4f85c19883..15e75fe847 100644
--- a/gm/hairmodes.cpp
+++ b/gm/hairmodes.cpp
@@ -58,7 +58,7 @@ static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode, SkAlpha a0, SkAlpha
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;
@@ -66,10 +66,8 @@ static SkShader* make_bg_shader() {
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 {
@@ -85,7 +83,7 @@ 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 {
diff --git a/gm/imagefiltersclipped.cpp b/gm/imagefiltersclipped.cpp
index f5c9cefbb2..033b80638f 100644
--- a/gm/imagefiltersclipped.cpp
+++ b/gm/imagefiltersclipped.cpp
@@ -53,12 +53,9 @@ protected:
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());
}
diff --git a/gm/imagefilterscropexpand.cpp b/gm/imagefilterscropexpand.cpp
index 9ceab2036a..185bbde0a6 100644
--- a/gm/imagefilterscropexpand.cpp
+++ b/gm/imagefilterscropexpand.cpp
@@ -151,12 +151,9 @@ private:
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();
diff --git a/gm/imagefiltersscaled.cpp b/gm/imagefiltersscaled.cpp
index 7576ee1375..da4467882b 100644
--- a/gm/imagefiltersscaled.cpp
+++ b/gm/imagefiltersscaled.cpp
@@ -145,12 +145,9 @@ private:
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();
diff --git a/gm/imagefilterstransformed.cpp b/gm/imagefilterstransformed.cpp
index 8e59b9242c..5b9d702efb 100644
--- a/gm/imagefilterstransformed.cpp
+++ b/gm/imagefilterstransformed.cpp
@@ -36,12 +36,9 @@ static SkImage* make_gradient_circle(int width, int height) {
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();
diff --git a/gm/imagefromyuvtextures.cpp b/gm/imagefromyuvtextures.cpp
index c53df295cd..6280ae740b 100644
--- a/gm/imagefromyuvtextures.cpp
+++ b/gm/imagefromyuvtextures.cpp
@@ -40,9 +40,9 @@ protected:
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);
diff --git a/gm/imagetoyuvplanes.cpp b/gm/imagetoyuvplanes.cpp
index 09b3dbb98b..87bff8ee64 100644
--- a/gm/imagetoyuvplanes.cpp
+++ b/gm/imagetoyuvplanes.cpp
@@ -28,9 +28,9 @@ static SkImage* create_image(GrContext* context, int width, int height) {
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();
diff --git a/gm/lcdblendmodes.cpp b/gm/lcdblendmodes.cpp
index d7a9024204..c3fe9ff149 100644
--- a/gm/lcdblendmodes.cpp
+++ b/gm/lcdblendmodes.cpp
@@ -22,7 +22,7 @@ static const int kNumCols = 4;
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() },
@@ -30,9 +30,8 @@ static SkShader* make_shader(const SkRect& bounds) {
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 {
@@ -136,7 +135,7 @@ protected:
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);
diff --git a/gm/lumafilter.cpp b/gm/lumafilter.cpp
index 3244b2b055..adffd008c1 100644
--- a/gm/lumafilter.cpp
+++ b/gm/lumafilter.cpp
@@ -26,9 +26,8 @@ static void draw_label(SkCanvas* canvas, const char* label,
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);
@@ -85,16 +84,10 @@ public:
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:
@@ -116,8 +109,8 @@ protected:
SkXfermode::kDstIn_Mode,
};
struct {
- SkShader* fShader1;
- SkShader* fShader2;
+ const sk_sp<SkShader>& fShader1;
+ const sk_sp<SkShader>& fShader2;
} shaders[] = {
{ nullptr, nullptr },
{ nullptr, fGr2 },
@@ -145,7 +138,7 @@ protected:
private:
SkAutoTUnref<SkColorFilter> fFilter;
- SkAutoTUnref<SkShader> fGr1, fGr2;
+ sk_sp<SkShader> fGr1, fGr2;
typedef skiagm::GM INHERITED;
};
diff --git a/gm/matrixconvolution.cpp b/gm/matrixconvolution.cpp
index 3b159f455b..b02f743f29 100644
--- a/gm/matrixconvolution.cpp
+++ b/gm/matrixconvolution.cpp
@@ -37,8 +37,8 @@ protected:
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);
}
diff --git a/gm/modecolorfilters.cpp b/gm/modecolorfilters.cpp
index b5ede710f1..de6a18a41c 100644
--- a/gm/modecolorfilters.cpp
+++ b/gm/modecolorfilters.cpp
@@ -6,7 +6,6 @@
*/
#include "gm.h"
-#include "SkBitmapProcShader.h"
#include "SkColorFilter.h"
#include "SkGradientShader.h"
@@ -16,27 +15,27 @@
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);
@@ -49,7 +48,7 @@ static SkShader* make_bg_shader(int checkSize) {
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 {
@@ -59,15 +58,15 @@ public:
}
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;
@@ -75,13 +74,13 @@ protected:
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(),
@@ -146,14 +145,10 @@ protected:
}
}
}
-
- 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;
};
diff --git a/gm/ovals.cpp b/gm/ovals.cpp
index e4cc46eb21..580426b244 100755
--- a/gm/ovals.cpp
+++ b/gm/ovals.cpp
@@ -246,12 +246,8 @@ protected:
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();
diff --git a/gm/patch.cpp b/gm/patch.cpp
index d9f6d57d6f..5b661f4b7c 100644
--- a/gm/patch.cpp
+++ b/gm/patch.cpp
@@ -10,15 +10,15 @@
#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]) {
@@ -92,7 +92,7 @@ DEF_SIMPLE_GM(patch_primitive, canvas, 800, 800) {
SkXfermode::kModulate_Mode,
};
- SkAutoTUnref<SkShader> shader(make_shader());
+ sk_sp<SkShader> shader(make_shader());
canvas->save();
for (int y = 0; y < 3; y++) {
diff --git a/gm/perspshaders.cpp b/gm/perspshaders.cpp
index 59fab47fc8..a29ef52f46 100644
--- a/gm/perspshaders.cpp
+++ b/gm/perspshaders.cpp
@@ -46,9 +46,8 @@ protected:
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) }
@@ -62,12 +61,10 @@ protected:
};
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);
@@ -160,9 +157,9 @@ private:
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;
diff --git a/gm/pictureimagegenerator.cpp b/gm/pictureimagegenerator.cpp
index 829006d808..2d50f3a6be 100644
--- a/gm/pictureimagegenerator.cpp
+++ b/gm/pictureimagegenerator.cpp
@@ -68,10 +68,8 @@ static void draw_vector_logo(SkCanvas* canvas, const SkRect& viewBox) {
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),
@@ -88,10 +86,8 @@ static void draw_vector_logo(SkCanvas* canvas, const SkRect& viewBox) {
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);
}
diff --git a/gm/pictureshader.cpp b/gm/pictureshader.cpp
index c35c5c964e..f27c4eda47 100644
--- a/gm/pictureshader.cpp
+++ b/gm/pictureshader.cpp
@@ -150,20 +150,17 @@ private:
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();
@@ -172,7 +169,7 @@ private:
SkScalar fTileSize;
SkScalar fSceneSize;
- SkAutoTUnref<SkPicture> fPicture;
+ sk_sp<SkPicture> fPicture;
SkBitmap fBitmap;
typedef GM INHERITED;
@@ -196,10 +193,10 @@ DEF_SIMPLE_GM(tiled_picture_shader, canvas, 400, 400) {
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);
diff --git a/gm/pictureshadertile.cpp b/gm/pictureshadertile.cpp
index 30776c338b..b6179f5421 100644
--- a/gm/pictureshadertile.cpp
+++ b/gm/pictureshadertile.cpp
@@ -95,14 +95,14 @@ protected:
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,
@@ -115,20 +115,18 @@ protected:
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);
}
}
@@ -150,7 +148,7 @@ protected:
}
private:
- SkAutoTUnref<SkShader> fShaders[SK_ARRAY_COUNT(tiles)];
+ sk_sp<SkShader> fShaders[SK_ARRAY_COUNT(tiles)];
typedef GM INHERITED;
};
diff --git a/gm/rectangletexture.cpp b/gm/rectangletexture.cpp
index 20f2ead593..4bdb4c9f11 100644
--- a/gm/rectangletexture.cpp
+++ b/gm/rectangletexture.cpp
@@ -42,14 +42,14 @@ protected:
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);
}
diff --git a/gm/rects.cpp b/gm/rects.cpp
index 38108fed22..6f4c75e22f 100644
--- a/gm/rects.cpp
+++ b/gm/rects.cpp
@@ -80,13 +80,9 @@ protected:
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);
}
diff --git a/gm/roundrects.cpp b/gm/roundrects.cpp
index b616e4d1cf..d0401f0595 100644
--- a/gm/roundrects.cpp
+++ b/gm/roundrects.cpp
@@ -261,12 +261,8 @@ protected:
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();
diff --git a/gm/samplerstress.cpp b/gm/samplerstress.cpp
index 4bec6784a8..f317cf9103 100644
--- a/gm/samplerstress.cpp
+++ b/gm/samplerstress.cpp
@@ -21,13 +21,9 @@ class SamplerStressGM : public GM {
public:
SamplerStressGM()
: fTextureCreated(false)
- , fShader(nullptr)
, fMaskFilter(nullptr) {
}
- virtual ~SamplerStressGM() {
- }
-
protected:
SkString onShortName() override {
@@ -69,15 +65,14 @@ protected:
}
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() {
@@ -140,9 +135,9 @@ protected:
}
private:
- SkBitmap fTexture;
- bool fTextureCreated;
- SkAutoTUnref<SkShader> fShader;
+ SkBitmap fTexture;
+ bool fTextureCreated;
+ sk_sp<SkShader> fShader;
SkAutoTUnref<SkMaskFilter> fMaskFilter;
typedef GM INHERITED;
diff --git a/gm/shaderbounds.cpp b/gm/shaderbounds.cpp
index fd42973dba..503f8f5b1e 100644
--- a/gm/shaderbounds.cpp
+++ b/gm/shaderbounds.cpp
@@ -4,30 +4,31 @@
* 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) {
@@ -62,20 +63,20 @@ protected:
// 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;
@@ -83,8 +84,7 @@ protected:
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:
@@ -93,7 +93,7 @@ private:
ShaderGenFunc fShaderMaker;
SkString fName;
- SkShader* MakeShader(bool background);
+ sk_sp<SkShader> MakeShader(bool background);
};
///////////////////////////////////////////////////////////////////////////////
diff --git a/gm/shadertext.cpp b/gm/shadertext.cpp
index e68ee98df0..13fa28325b 100644
--- a/gm/shadertext.cpp
+++ b/gm/shadertext.cpp
@@ -24,8 +24,8 @@ static void makebm(SkBitmap* bm, int w, int h) {
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);
}
@@ -46,38 +46,38 @@ static const GradData gGradData[] = {
{ 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
@@ -123,7 +123,7 @@ protected:
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) {
@@ -138,7 +138,7 @@ protected:
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]);
}
}
@@ -167,7 +167,7 @@ protected:
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();
diff --git a/gm/shadertext2.cpp b/gm/shadertext2.cpp
index 74f01a0c9d..2ec1952599 100644
--- a/gm/shadertext2.cpp
+++ b/gm/shadertext2.cpp
@@ -24,11 +24,11 @@ static void makebm(SkBitmap* bm, int w, int h) {
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);
}
@@ -136,11 +136,9 @@ DEF_SIMPLE_GM_BG(shadertext2, canvas, 1800, 900,
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);
diff --git a/gm/shadertext3.cpp b/gm/shadertext3.cpp
index 07ecd7184b..0d1c03e345 100644
--- a/gm/shadertext3.cpp
+++ b/gm/shadertext3.cpp
@@ -26,11 +26,11 @@ static void makebm(SkBitmap* bm, int w, int h) {
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);
}
@@ -100,17 +100,13 @@ protected:
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);
diff --git a/gm/shadows.cpp b/gm/shadows.cpp
index bb2bf3c5bd..5696240d21 100644
--- a/gm/shadows.cpp
+++ b/gm/shadows.cpp
@@ -128,12 +128,11 @@ protected:
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);
diff --git a/gm/shallowgradient.cpp b/gm/shallowgradient.cpp
index 764b1a5034..6990ba7c93 100644
--- a/gm/shallowgradient.cpp
+++ b/gm/shallowgradient.cpp
@@ -8,31 +8,27 @@
#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 {
@@ -62,7 +58,7 @@ protected:
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);
}
diff --git a/gm/skbug_257.cpp b/gm/skbug_257.cpp
index 052884236a..b11487d6c5 100644
--- a/gm/skbug_257.cpp
+++ b/gm/skbug_257.cpp
@@ -21,10 +21,9 @@ static void rotated_checkerboard_shader(SkPaint* 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,
diff --git a/gm/srcmode.cpp b/gm/srcmode.cpp
index 86fe89bd1a..28bb04bd4e 100644
--- a/gm/srcmode.cpp
+++ b/gm/srcmode.cpp
@@ -27,10 +27,8 @@ static void identity_paintproc(SkPaint* paint) {
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&);
diff --git a/gm/surface.cpp b/gm/surface.cpp
index c3eaf9e8d2..6874b5bea3 100644
--- a/gm/surface.cpp
+++ b/gm/surface.cpp
@@ -13,12 +13,12 @@
#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,
@@ -46,7 +46,7 @@ static void test_draw(SkCanvas* canvas, const char label[]) {
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);
diff --git a/gm/tablecolorfilter.cpp b/gm/tablecolorfilter.cpp
index 1053bb2518..dcc29f37cf 100644
--- a/gm/tablecolorfilter.cpp
+++ b/gm/tablecolorfilter.cpp
@@ -11,14 +11,14 @@
#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;
@@ -28,17 +28,17 @@ static void make_bm0(SkBitmap* bm) {
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;
@@ -50,7 +50,7 @@ static void make_bm1(SkBitmap* bm) {
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);
}
@@ -234,7 +234,7 @@ protected:
}
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;
diff --git a/gm/textbloblooper.cpp b/gm/textbloblooper.cpp
index fef3e248f4..8d462c9b09 100644
--- a/gm/textbloblooper.cpp
+++ b/gm/textbloblooper.cpp
@@ -80,7 +80,7 @@ static void path_effect(SkPaint* paint) {
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() },
@@ -89,15 +89,14 @@ static SkShader* make_shader(const SkRect& bounds) {
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();
}
diff --git a/gm/textblobshader.cpp b/gm/textblobshader.cpp
index 30674e1d68..6a8fa49289 100644
--- a/gm/textblobshader.cpp
+++ b/gm/textblobshader.cpp
@@ -68,11 +68,11 @@ protected:
}
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 {
@@ -104,7 +104,7 @@ protected:
private:
SkTDArray<uint16_t> fGlyphs;
SkAutoTUnref<const SkTextBlob> fBlob;
- SkAutoTUnref<SkShader> fShader;
+ sk_sp<SkShader> fShader;
typedef skiagm::GM INHERITED;
};
diff --git a/gm/texturedomaineffect.cpp b/gm/texturedomaineffect.cpp
index 72e40feb49..6bd6490c66 100644
--- a/gm/texturedomaineffect.cpp
+++ b/gm/texturedomaineffect.cpp
@@ -50,24 +50,24 @@ protected:
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 {
diff --git a/gm/tiledscaledbitmap.cpp b/gm/tiledscaledbitmap.cpp
index daecbb05e2..d74d40bf49 100644
--- a/gm/tiledscaledbitmap.cpp
+++ b/gm/tiledscaledbitmap.cpp
@@ -1,10 +1,10 @@
-
/*
* 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"
@@ -14,7 +14,6 @@
#include "SkShader.h"
#include "SkStream.h"
-
/***
*
* This GM reproduces Skia bug 2904, in which a tiled bitmap shader was failing to draw correctly
@@ -64,10 +63,8 @@ protected:
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);
}
diff --git a/gm/tilemodes.cpp b/gm/tilemodes.cpp
index 26b83486e8..d774939648 100644
--- a/gm/tilemodes.cpp
+++ b/gm/tilemodes.cpp
@@ -27,15 +27,14 @@ static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
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);
}
@@ -156,13 +155,13 @@ private:
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;
@@ -171,17 +170,16 @@ static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
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;
@@ -239,7 +237,7 @@ protected:
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);
diff --git a/gm/tilemodes_scaled.cpp b/gm/tilemodes_scaled.cpp
index 0d46fb66c5..21224b44e8 100644
--- a/gm/tilemodes_scaled.cpp
+++ b/gm/tilemodes_scaled.cpp
@@ -27,15 +27,14 @@ static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
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);
}
@@ -160,13 +159,13 @@ private:
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;
@@ -175,17 +174,17 @@ static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
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;
@@ -243,7 +242,7 @@ protected:
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);
diff --git a/gm/tinybitmap.cpp b/gm/tinybitmap.cpp
index 7942b4266a..1162b2d2d1 100644
--- a/gm/tinybitmap.cpp
+++ b/gm/tinybitmap.cpp
@@ -44,12 +44,10 @@ protected:
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);
}
diff --git a/gm/transparency.cpp b/gm/transparency.cpp
index 73bd8b2023..5e057617d4 100644
--- a/gm/transparency.cpp
+++ b/gm/transparency.cpp
@@ -9,9 +9,7 @@
#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);
@@ -31,30 +29,27 @@ static void make_transparency(SkCanvas* canvas,
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);
}
diff --git a/gm/vertices.cpp b/gm/vertices.cpp
index 31fb352724..177dc43c2b 100644
--- a/gm/vertices.cpp
+++ b/gm/vertices.cpp
@@ -11,20 +11,19 @@
#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() {
@@ -35,8 +34,8 @@ class VerticesGM : public skiagm::GM {
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:
@@ -59,8 +58,8 @@ protected:
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;
@@ -86,11 +85,11 @@ protected:
};
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 },
diff --git a/gm/verylargebitmap.cpp b/gm/verylargebitmap.cpp
index 5c67e77e3e..ab6821dc1a 100644
--- a/gm/verylargebitmap.cpp
+++ b/gm/verylargebitmap.cpp
@@ -15,10 +15,9 @@
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);
}
diff --git a/gm/xfermodes.cpp b/gm/xfermodes.cpp
index 1a71255d3e..a1427cf212 100644
--- a/gm/xfermodes.cpp
+++ b/gm/xfermodes.cpp
@@ -261,10 +261,8 @@ protected:
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);
@@ -325,7 +323,6 @@ protected:
y0 = 0;
}
}
- s->unref();
}
private:
diff --git a/gm/xfermodes2.cpp b/gm/xfermodes2.cpp
index db48c03d20..397f4e1e29 100644
--- a/gm/xfermodes2.cpp
+++ b/gm/xfermodes2.cpp
@@ -99,10 +99,8 @@ 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);
@@ -115,9 +113,8 @@ private:
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());
@@ -129,9 +126,8 @@ private:
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 {
@@ -139,9 +135,9 @@ private:
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;
};
diff --git a/gm/xfermodes3.cpp b/gm/xfermodes3.cpp
index 8c24bf72d1..4cd05df5c4 100644
--- a/gm/xfermodes3.cpp
+++ b/gm/xfermodes3.cpp
@@ -185,21 +185,17 @@ private:
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);
@@ -210,9 +206,8 @@ private:
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 {
@@ -221,8 +216,8 @@ private:
kTestsPerRow = 15,
};
- SkAutoTUnref<SkShader> fBGShader;
- SkAutoTUnref<SkShader> fBmpShader;
+ sk_sp<SkShader> fBGShader;
+ sk_sp<SkShader> fBmpShader;
typedef GM INHERITED;
};