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

Unified Diff: samplecode/SampleShaders.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/SampleShaderText.cpp ('k') | samplecode/SampleSlides.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « samplecode/SampleShaderText.cpp ('k') | samplecode/SampleSlides.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698