Index: samplecode/SampleShaders.cpp |
diff --git a/samplecode/SampleShaders.cpp b/samplecode/SampleShaders.cpp |
index 2c0a6ab749c256e1e3b5bd2c279c8abb6908af10..71ddc2ec69d401074bb09cc83c2b179f76bc3d9a 100644 |
--- a/samplecode/SampleShaders.cpp |
+++ b/samplecode/SampleShaders.cpp |
@@ -1,10 +1,10 @@ |
- |
/* |
* Copyright 2011 Google Inc. |
* |
* Use of this source code is governed by a BSD-style license that can be |
* found in the LICENSE file. |
*/ |
+ |
#include "SampleCode.h" |
#include "SkView.h" |
#include "SkCanvas.h" |
@@ -21,8 +21,7 @@ |
#include "SkTime.h" |
#include "SkTypeface.h" |
-static SkShader* make_bitmapfade(const SkBitmap& bm) |
-{ |
+static sk_sp<SkShader> make_bitmapfade(const SkBitmap& bm) { |
SkPoint pts[2]; |
SkColor colors[2]; |
@@ -30,25 +29,20 @@ static SkShader* make_bitmapfade(const SkBitmap& bm) |
pts[1].set(0, SkIntToScalar(bm.height())); |
colors[0] = SK_ColorBLACK; |
colors[1] = SkColorSetARGB(0, 0, 0, 0); |
- SkShader* shaderA = SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode); |
+ auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode); |
- SkShader* shaderB = SkShader::CreateBitmapShader(bm, |
+ auto shaderB = SkShader::MakeBitmapShader(bm, |
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); |
- SkXfermode* mode = SkXfermode::Create(SkXfermode::kDstIn_Mode); |
+ SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kDstIn_Mode)); |
- SkShader* shader = SkShader::CreateComposeShader(shaderB, shaderA, mode); |
- shaderA->unref(); |
- shaderB->unref(); |
- mode->unref(); |
- |
- return shader; |
+ return SkShader::MakeComposeShader(std::move(shaderB), std::move(shaderA), mode); |
} |
class ShaderView : public SampleView { |
public: |
- SkShader* fShader; |
- SkBitmap fBitmap; |
+ sk_sp<SkShader> fShader; |
+ SkBitmap fBitmap; |
ShaderView() { |
SkImageDecoder::DecodeFile("/skimages/logo.gif", &fBitmap); |
@@ -60,23 +54,17 @@ public: |
pts[1].set(SkIntToScalar(100), 0); |
colors[0] = SK_ColorRED; |
colors[1] = SK_ColorBLUE; |
- SkShader* shaderA = SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode); |
+ auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode); |
pts[0].set(0, 0); |
pts[1].set(0, SkIntToScalar(100)); |
colors[0] = SK_ColorBLACK; |
colors[1] = SkColorSetARGB(0x80, 0, 0, 0); |
- SkShader* shaderB = SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode); |
+ auto shaderB = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode); |
- SkXfermode* mode = SkXfermode::Create(SkXfermode::kDstIn_Mode); |
+ SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kDstIn_Mode)); |
- fShader = SkShader::CreateComposeShader(shaderA, shaderB, mode); |
- shaderA->unref(); |
- shaderB->unref(); |
- mode->unref(); |
- } |
- virtual ~ShaderView() { |
- SkSafeUnref(fShader); |
+ fShader = SkShader::MakeComposeShader(std::move(shaderA), std::move(shaderB), mode); |
} |
protected: |
@@ -112,7 +100,7 @@ protected: |
paint.setShader(nullptr); |
canvas->drawRect(r, paint); |
- paint.setShader(make_bitmapfade(fBitmap))->unref(); |
+ paint.setShader(make_bitmapfade(fBitmap)); |
canvas->drawRect(r, paint); |
} |