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

Unified Diff: samplecode/SampleShaderText.cpp

Issue 1772463002: use Make instead of Create to return a shared shader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samplecode/SampleRepeatTile.cpp ('k') | samplecode/SampleShaders.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleShaderText.cpp
diff --git a/samplecode/SampleShaderText.cpp b/samplecode/SampleShaderText.cpp
index f13fd4edc7927fb430c92ed6043e5033be6a473b..cf0cb0fe75e7c0c453491325c19b9b392f22c5a1 100644
--- a/samplecode/SampleShaderText.cpp
+++ b/samplecode/SampleShaderText.cpp
@@ -23,18 +23,18 @@ 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);
}
-static SkShader* MakeBitmapShader(SkShader::TileMode tx, SkShader::TileMode ty,
- int w, int h) {
+static sk_sp<SkShader> MakeBitmapShader(SkShader::TileMode tx, SkShader::TileMode ty,
+ int w, int h) {
static SkBitmap bmp;
if (bmp.isNull()) {
makebm(&bmp, w/2, h/4);
}
- return SkShader::CreateBitmapShader(bmp, tx, ty);
+ return SkShader::MakeBitmapShader(bmp, tx, ty);
}
///////////////////////////////////////////////////////////////////////////////
@@ -54,38 +54,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 tm) {
+static sk_sp<SkShader> MakeSweep(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::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
@@ -133,7 +133,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) {
@@ -175,7 +175,7 @@ protected:
size_t 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();
« no previous file with comments | « samplecode/SampleRepeatTile.cpp ('k') | samplecode/SampleShaders.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698