Index: samplecode/SampleGradients.cpp |
diff --git a/samplecode/SampleGradients.cpp b/samplecode/SampleGradients.cpp |
index 2d6f7d4bb1dfb7f5b163f7e22b0a517ab2b323da..5e9450e84ded5194b84f7f977ae8e5ad3b60a175 100644 |
--- a/samplecode/SampleGradients.cpp |
+++ b/samplecode/SampleGradients.cpp |
@@ -10,10 +10,10 @@ |
#include "SkCanvas.h" |
#include "SkGradientShader.h" |
-static SkShader* setgrad(const SkRect& r, SkColor c0, SkColor c1) { |
+static sk_sp<SkShader> setgrad(const SkRect& r, SkColor c0, SkColor c1) { |
SkColor colors[] = { c0, c1 }; |
SkPoint pts[] = { { r.fLeft, r.fTop }, { r.fRight, r.fTop } }; |
- return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode); |
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode); |
} |
static void test_alphagradients(SkCanvas* canvas) { |
@@ -23,17 +23,17 @@ static void test_alphagradients(SkCanvas* canvas) { |
SkPaint p, p2; |
p2.setStyle(SkPaint::kStroke_Style); |
- p.setShader(setgrad(r, 0xFF00FF00, 0x0000FF00))->unref(); |
+ p.setShader(setgrad(r, 0xFF00FF00, 0x0000FF00)); |
canvas->drawRect(r, p); |
canvas->drawRect(r, p2); |
r.offset(0, r.height() + SkIntToScalar(4)); |
- p.setShader(setgrad(r, 0xFF00FF00, 0x00000000))->unref(); |
+ p.setShader(setgrad(r, 0xFF00FF00, 0x00000000)); |
canvas->drawRect(r, p); |
canvas->drawRect(r, p2); |
r.offset(0, r.height() + SkIntToScalar(4)); |
- p.setShader(setgrad(r, 0xFF00FF00, 0x00FF0000))->unref(); |
+ p.setShader(setgrad(r, 0xFF00FF00, 0x00FF0000)); |
canvas->drawRect(r, p); |
canvas->drawRect(r, p2); |
} |
@@ -63,49 +63,49 @@ static const GradData gGradData[] = { |
{ 5, gColors, gPos2 } |
}; |
-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); |
} |
-static SkShader* Make2ConicalConcentric(const SkPoint pts[2], const GradData& data, |
+static sk_sp<SkShader> Make2ConicalConcentric(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::CreateTwoPointConical( |
+ return SkGradientShader::MakeTwoPointConical( |
center, (pts[1].fX - pts[0].fX) / 7, |
center, (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, Make2ConicalConcentric |
@@ -120,8 +120,7 @@ public: |
} |
protected: |
- // overrides from SkEventSink |
- virtual bool onQuery(SkEvent* evt) { |
+ bool onQuery(SkEvent* evt) override { |
if (SampleCode::TitleQ(*evt)) { |
SampleCode::TitleR(evt, "Gradients"); |
return true; |
@@ -129,7 +128,7 @@ protected: |
return this->INHERITED::onQuery(evt); |
} |
- virtual void onDrawContent(SkCanvas* canvas) { |
+ void onDrawContent(SkCanvas* canvas) override { |
SkPoint pts[2] = { |
{ 0, 0 }, |
{ SkIntToScalar(100), SkIntToScalar(100) } |
@@ -146,9 +145,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; |
- shader = gGradMakers[j](pts, gGradData[i], (SkShader::TileMode)tm); |
- paint.setShader(shader)->unref(); |
+ paint.setShader(gGradMakers[j](pts, gGradData[i], (SkShader::TileMode)tm)); |
canvas->drawRect(r, paint); |
canvas->translate(0, SkIntToScalar(120)); |
} |