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;
0xCF, 0xCE);
const SkMatrix m = SkMatrix::MakeScale(SkIntToScalar(6), SkIntToScalar(6));
- SkShader* s = SkShader::CreateBitmapShader(bm,
- SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode,
- &m);
-
- return s;
+ return SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode,
+ &m);
}
namespace skiagm {
SkPaint fBGPaint;
public:
AARectModesGM () {
- fBGPaint.setShader(make_bg_shader())->unref();
+ fBGPaint.setShader(make_bg_shader());
}
protected:
SkMatrix s;
s.reset();
s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
- SkShader* shader = SkShader::CreateBitmapShader(
- bmp,
- SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode,
- &s);
- paint.setShader(shader)->unref();
+ paint.setShader(SkShader::MakeBitmapShader(bmp, SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode, &s));
paint.setAntiAlias(false);
paint.setFilterQuality(kLow_SkFilterQuality);
rect.setLTRB(pt.fX - small, pt.fY - small,
-
/*
* 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 "gm.h"
#include "SkCanvas.h"
#include "SkGradientShader.h"
paint.setAntiAlias(true);
const SkPoint pts[] = { { 0, 0 }, { 64, 64 } };
const SkColor colors[] = { SK_ColorWHITE, SK_ColorBLUE };
- paint.setShader(SkGradientShader::CreateLinear(pts, colors, nullptr, 2,
- SkShader::kClamp_TileMode))->unref();
+ paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2,
+ SkShader::kClamp_TileMode));
canvas.drawCircle(32, 32, 32, paint);
}
ctx, result, width, height, kAlpha_8_GrPixelConfig, kZero, kOne, k3Q, kHalf, k1Q);
}
-static SkShader* make_shader() {
+static sk_sp<SkShader> make_shader() {
static const SkPoint pts[] = { {0, 0}, {20, 20} };
static const SkColor colors[] = { SK_ColorGREEN, SK_ColorYELLOW };
- return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kMirror_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kMirror_TileMode);
}
-static SkShader* make_null_shader() { return nullptr; }
+static sk_sp<SkShader> make_null_shader() { return nullptr; }
enum BleedTest {
kUseBitmap_BleedTest,
const struct {
const char* fName;
bool (*fPixelMaker)(GrContext*, TestPixels* result, int width, int height);
- SkShader* (*fShaderMaker)();
+ sk_sp<SkShader> (*fShaderMaker)();
} gBleedRec[] = {
{ "bleed", make_ringed_color_bitmap, make_null_shader },
{ "bleed_texture_bmp", make_ringed_oversized_color_texture_bitmap, make_null_shader },
return;
}
- fShader.reset(gBleedRec[fBT].fShaderMaker());
+ fShader = gBleedRec[fBT].fShaderMaker();
canvas->clear(SK_ColorGRAY);
SkTDArray<SkMatrix> matrices;
static const int kSmallTextureSize = 6;
static const int kMaxTileSize = 32;
- bool fCreatedPixels;
- TestPixels fBigTestPixels;
- TestPixels fSmallTestPixels;
+ bool fCreatedPixels;
+ TestPixels fBigTestPixels;
+ TestPixels fSmallTestPixels;
- SkAutoTUnref<SkShader> fShader;
+ sk_sp<SkShader> fShader;
- const BleedTest fBT;
+ const BleedTest fBT;
typedef GM INHERITED;
};
/*
* Spits out a dummy gradient to test blur with shader on paint
*/
-static SkShader* MakeRadial() {
+static sk_sp<SkShader> MakeRadial() {
SkPoint pts[2] = {
{ 0, 0 },
{ SkIntToScalar(100), SkIntToScalar(100) }
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,
- colors, pos, SK_ARRAY_COUNT(colors), tm,
- 0, &scale);
+ return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
+ center0, (pts[1].fX - pts[0].fX) / 2,
+ colors, pos, SK_ARRAY_COUNT(colors), tm,
+ 0, &scale);
}
typedef void (*PaintProc)(SkPaint*, SkScalar width);
paint.setAlpha(fAlpha);
SkPaint paintWithRadial = paint;
- paintWithRadial.setShader(MakeRadial())->unref();
+ paintWithRadial.setShader(MakeRadial());
static const Proc procs[] = {
fill_rect, draw_donut, draw_donut_skewed
/*
* Spits out a dummy gradient to test blur with shader on paint
*/
-static SkShader* MakeRadial() {
+static sk_sp<SkShader> MakeRadial() {
SkPoint pts[2] = {
{ 0, 0 },
{ SkIntToScalar(100), SkIntToScalar(100) }
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,
- colors, pos, SK_ARRAY_COUNT(colors), tm,
- 0, &scale);
+ return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
+ center0, (pts[1].fX - pts[0].fX) / 2,
+ colors, pos, SK_ARRAY_COUNT(colors), tm,
+ 0, &scale);
}
// Simpler blurred RR test cases where all the radii are the same.
bool useRadial = SkToBool(k);
if (useRadial) {
- paint.setShader(MakeRadial())->unref();
+ paint.setShader(MakeRadial());
}
SkRRect rrect;
lm.setTranslateY(330);
static const SkShader::TileMode kTM = SkShader::kRepeat_TileMode;
- bmpPaint.setShader(SkShader::CreateBitmapShader(fBmp, kTM, kTM, &lm))->unref();
+ bmpPaint.setShader(SkShader::MakeBitmapShader(fBmp, kTM, kTM, &lm));
SkRect rect = SkRect::MakeLTRB(20, 60, 220, 210);
canvas->drawRect(rect, bmpPaint);
paint.setAntiAlias(true);
SkPoint center = SkPoint::Make(SkIntToScalar(40), SkIntToScalar(40));
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);
}
s.reset();
s.setScale(8, 8);
s.postTranslate(SLIDE_SIZE / 2, SLIDE_SIZE / 2);
- SkShader* shader = SkShader::CreateBitmapShader(
- bmp, fMode, fMode, &s);
-
SkPaint paint;
- paint.setShader(shader)->unref();
+ paint.setShader(SkShader::MakeBitmapShader(bmp, fMode, fMode, &s));
if (fHQ) {
paint.setFilterQuality(kHigh_SkFilterQuality);
#include "SkColorMatrixFilter.h"
#include "SkGradientShader.h"
-static SkShader* make_opaque_color() {
- return SkShader::CreateColorShader(0xFFFF0000);
+static sk_sp<SkShader> make_opaque_color() {
+ return SkShader::MakeColorShader(0xFFFF0000);
}
-static SkShader* make_alpha_color() {
- return SkShader::CreateColorShader(0x80FF0000);
+static sk_sp<SkShader> make_alpha_color() {
+ return SkShader::MakeColorShader(0x80FF0000);
}
static SkColorFilter* make_cf_null() {
static void draw_into_canvas(SkCanvas* canvas) {
const SkRect r = SkRect::MakeWH(50, 100);
- SkShader* (*shaders[])() { make_opaque_color, make_alpha_color };
+ sk_sp<SkShader> (*shaders[])() { make_opaque_color, make_alpha_color };
SkColorFilter* (*filters[])() { make_cf_null, make_cf0, make_cf1, make_cf2 };
SkPaint paint;
for (auto shProc : shaders) {
- paint.setShader(shProc())->unref();
+ paint.setShader(shProc());
for (auto cfProc : filters) {
SkSafeUnref(paint.setColorFilter(cfProc()));
canvas->drawRect(r, paint);
namespace skiagm {
-static SkShader* MakeLinear() {
+static sk_sp<SkShader> MakeLinear() {
static const SkPoint pts[2] = {
{ 0, 0 },
{ SkIntToScalar(80), SkIntToScalar(80) }
};
static const SkColor colors[] = { SK_ColorYELLOW, SK_ColorBLUE };
- return SkGradientShader::CreateLinear(
- pts, colors, nullptr, 2, SkShader::kRepeat_TileMode, 0, &SkMatrix::I());
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kRepeat_TileMode, 0,
+ &SkMatrix::I());
}
class ColorCubeGM : public GM {
canvas.clear(0x00000000);
SkPaint paint;
paint.setAntiAlias(true);
- SkShader* shader = MakeLinear();
- paint.setShader(shader);
- SkRect r = { 0, 0, SkIntToScalar(80), SkIntToScalar(80) };
- canvas.drawRect(r, paint);
- shader->unref();
+ paint.setShader(MakeLinear());
+ canvas.drawRect(SkRect::MakeWH(80, 80), paint);
}
void make_3Dlut(SkData** data, int size, bool invR, bool invG, bool invB) {
/*
* Spits out a dummy gradient to test blur with shader on paint
*/
-static SkShader* MakeLinear() {
+static sk_sp<SkShader> MakeLinear() {
static const SkPoint kPts[] = { { 0, 0 }, { 32, 32 } };
static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
static const SkColor kColors[] = {0x80F00080, 0xF0F08000, 0x800080F0 };
- return SkGradientShader::CreateLinear(kPts, kColors, kPos,
- SK_ARRAY_COUNT(kColors), SkShader::kClamp_TileMode);
+ return SkGradientShader::MakeLinear(kPts, kColors, kPos, SK_ARRAY_COUNT(kColors),
+ SkShader::kClamp_TileMode);
}
static SkImageFilter* make_grayscale(SkImageFilter* input = nullptr) {
SkPaint shaderPaint;
shaderPaint.setTypeface(paint.getTypeface());
if (SkToBool(makeLinear)) {
- shaderPaint.setShader(MakeLinear())->unref();
+ shaderPaint.setShader(MakeLinear());
}
if (SkToBool(makeBlur) && SkToBool(makeGray)) {
#include "SkImage.h"
#include "Resources.h"
-static SkShader* sh_make_lineargradient0() {
+static sk_sp<SkShader> sh_make_lineargradient0() {
const SkPoint pts[] = { { 0, 0 }, { 100, 100 } };
const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
- return SkGradientShader::CreateLinear(pts, colors, nullptr, 3, SkShader::kRepeat_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, 3, SkShader::kRepeat_TileMode);
}
-static SkShader* sh_make_lineargradient1() {
+static sk_sp<SkShader> sh_make_lineargradient1() {
const SkPoint pts[] = { { 0, 0 }, { 100, 100 } };
const SkColor colors[] = { SK_ColorRED, 0x0000FF00, SK_ColorBLUE };
- return SkGradientShader::CreateLinear(pts, colors, nullptr, 3, SkShader::kRepeat_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, 3, SkShader::kRepeat_TileMode);
}
-static SkShader* sh_make_image() {
+static sk_sp<SkShader> sh_make_image() {
SkAutoTUnref<SkImage> image(GetResourceAsImage("mandrill_128.png"));
if (!image) {
return nullptr;
}
- return image->newShader(SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);
+ return sk_sp<SkShader>(image->newShader(SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode));
}
static void sk_gm_get_shaders(SkTDArray<SkShader*>* array) {
- if (SkShader* shader = sh_make_lineargradient0()) {
- *array->append() = shader;
+ if (auto shader = sh_make_lineargradient0()) {
+ *array->append() = shader.release();
}
- if (SkShader* shader = sh_make_lineargradient1()) {
- *array->append() = shader;
+ if (auto shader = sh_make_lineargradient1()) {
+ *array->append() = shader.release();
}
- if (SkShader* shader = sh_make_image()) {
- *array->append() = shader;
+ if (auto shader = sh_make_image()) {
+ *array->append() = shader.release();
}
}
#include "SkColorMatrixFilter.h"
#include "SkGradientShader.h"
-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() },
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);
}
typedef void (*InstallPaint)(SkPaint*, uint32_t, uint32_t);
SkPaint paint;
SkRect r;
r.setWH(600, 50);
- paint.setShader(make_shader(r))->unref();
+ paint.setShader(make_shader(r));
const struct {
InstallPaint fProc;
SkPoint pts[] = {{0, 0}, {SkIntToScalar(width), SkIntToScalar(height)}};
SkColor colors[] = {0x00000000, 0xFFFFFFFF};
SkPaint paint;
- paint.setShader(SkGradientShader::CreateLinear(pts, colors, nullptr, 2,
- SkShader::kClamp_TileMode))->unref();
+ paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2,
+ SkShader::kClamp_TileMode));
canvas.drawRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)), paint);
return SkImage::NewFromBitmap(bm);
}
};
SkMatrix local;
local.setRotate(180);
- SkShader* s = SkGradientShader::CreateSweep(0,0, colors, nullptr,
- SK_ARRAY_COUNT(colors), 0, &local);
-
SkPaint paint;
paint.setAntiAlias(true);
- paint.setShader(s)->unref();
+ paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_ARRAY_COUNT(colors),
+ 0, &local));
- SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif",
- SkTypeface::kBold);
+ SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold);
if (nullptr == orig) {
orig = SkTypeface::RefDefault();
}
};
SkMatrix local;
local.setRotate(180);
- SkShader* s = SkGradientShader::CreateSweep(0,0, colors, nullptr,
- SK_ARRAY_COUNT(colors), 0, &local);
-
SkPaint paint;
paint.setAntiAlias(true);
- paint.setShader(s)->unref();
+ paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_ARRAY_COUNT(colors),
+ 0, &local));
- SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif",
- SkTypeface::kBold);
+ SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold);
if (nullptr == orig) {
orig = SkTypeface::RefDefault();
}
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);
y += h + SkIntToScalar(30);
}
}
- s->unref();
}
private:
#include "gm.h"
-#include "SkBitmapProcShader.h"
#include "SkCanvas.h"
#include "SkGradientShader.h"
#include "SkGraphics.h"
#include "SkString.h"
#include "SkXfermode.h"
-static SkShader* make_shader(SkXfermode::Mode mode) {
+static sk_sp<SkShader> make_shader(SkXfermode::Mode mode) {
SkPoint pts[2];
SkColor colors[2];
pts[1].set(SkIntToScalar(100), 0);
colors[0] = SK_ColorRED;
colors[1] = SK_ColorBLUE;
- SkAutoTUnref<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);
- SkAutoTUnref<SkShader> shaderB(SkGradientShader::CreateLinear(pts, colors, nullptr, 2,
- SkShader::kClamp_TileMode));
+ auto shaderB = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode));
- return SkShader::CreateComposeShader(shaderA, shaderB, xfer);
+ return SkShader::MakeComposeShader(std::move(shaderA), std::move(shaderB), xfer);
}
class ComposeShaderGM : public skiagm::GM {
fShader = make_shader(SkXfermode::kDstIn_Mode);
}
- virtual ~ComposeShaderGM() {
- SkSafeUnref(fShader);
- }
-
protected:
SkString onShortName() override {
return SkString("composeshader");
}
void onDraw(SkCanvas* canvas) override {
-
SkPaint paint;
-
paint.setColor(SK_ColorGREEN);
canvas->drawRectCoords(0, 0, SkIntToScalar(100), SkIntToScalar(100), paint);
paint.setShader(fShader);
}
protected:
- SkShader* fShader;
+ sk_sp<SkShader> fShader;
private:
typedef GM INHERITED ;
}
void onDraw(SkCanvas* canvas) override {
- SkAutoTUnref<SkShader> shader0(make_shader(SkXfermode::kDstIn_Mode));
- SkAutoTUnref<SkShader> shader1(make_shader(SkXfermode::kSrcOver_Mode));
- SkShader* shaders[] = { shader0.get(), shader1.get() };
+ sk_sp<SkShader> shaders[] = {
+ make_shader(SkXfermode::kDstIn_Mode),
+ make_shader(SkXfermode::kSrcOver_Mode),
+ };
SkPaint paint;
paint.setColor(SK_ColorGREEN);
const SkRect r = SkRect::MakeXYWH(5, 5, 100, 100);
for (size_t y = 0; y < SK_ARRAY_COUNT(shaders); ++y) {
- SkShader* shader = shaders[y];
canvas->save();
for (int alpha = 0xFF; alpha > 0; alpha -= 0x28) {
paint.setAlpha(0xFF);
canvas->drawRect(r, paint);
paint.setAlpha(alpha);
- paint.setShader(shader);
+ paint.setShader(shaders[y]);
canvas->drawRect(r, paint);
canvas->translate(r.width() + 5, 0);
}
// creates a linear gradient shader
-static SkShader* make_linear_gradient_shader(int length) {
+static sk_sp<SkShader> make_linear_gradient_shader(int length) {
SkPoint pts[2];
SkColor colors[2];
pts[0].set(0, 0);
pts[1].set(SkIntToScalar(length), 0);
colors[0] = SK_ColorBLUE;
colors[1] = SkColorSetARGB(0, 0, 0, 0xFF);
- return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
}
class ComposeShaderBitmapGM : public skiagm::GM {
public:
ComposeShaderBitmapGM() {}
- ~ComposeShaderBitmapGM() {
- SkSafeUnref(fColorBitmapShader);
- SkSafeUnref(fAlpha8BitmapShader);
- SkSafeUnref(fLinearGradientShader);
- }
protected:
void onOnceBeforeDraw() override {
draw_alpha8_bm(&fAlpha8Bitmap, squareLength);
SkMatrix s;
s.reset();
- fColorBitmapShader = new SkBitmapProcShader(fColorBitmap, SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode, &s);
- fAlpha8BitmapShader = new SkBitmapProcShader(fAlpha8Bitmap, SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode, &s);
+ fColorBitmapShader = SkShader::MakeBitmapShader(fColorBitmap, SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode, &s);
+ fAlpha8BitmapShader = SkShader::MakeBitmapShader(fAlpha8Bitmap, SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode, &s);
fLinearGradientShader = make_linear_gradient_shader(squareLength);
}
void onDraw(SkCanvas* canvas) override {
SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kDstOver_Mode));
- // gradient should appear over color bitmap
- SkAutoTUnref<SkShader> shader0(SkShader::CreateComposeShader(fLinearGradientShader,
- fColorBitmapShader,
- xfer));
- // gradient should appear over alpha8 bitmap colorized by the paint color
- SkAutoTUnref<SkShader> shader1(SkShader::CreateComposeShader(fLinearGradientShader,
- fAlpha8BitmapShader,
- xfer));
-
- SkShader* shaders[] = { shader0.get(), shader1.get() };
+ sk_sp<SkShader> shaders[] = {
+ // gradient should appear over color bitmap
+ SkShader::MakeComposeShader(fLinearGradientShader, fColorBitmapShader, xfer),
+ // gradient should appear over alpha8 bitmap colorized by the paint color
+ SkShader::MakeComposeShader(fLinearGradientShader, fAlpha8BitmapShader, xfer),
+ };
SkPaint paint;
paint.setColor(SK_ColorYELLOW);
SkIntToScalar(squareLength));
for (size_t y = 0; y < SK_ARRAY_COUNT(shaders); ++y) {
- SkShader* shader = shaders[y];
canvas->save();
for (int alpha = 0xFF; alpha > 0; alpha -= 0x28) {
paint.setAlpha(alpha);
- paint.setShader(shader);
+ paint.setShader(shaders[y]);
canvas->drawRect(r, paint);
canvas->translate(r.width() + 5, 0);
SkBitmap fColorBitmap;
SkBitmap fAlpha8Bitmap;
- SkShader* fColorBitmapShader{nullptr};
- SkShader* fAlpha8BitmapShader{nullptr};
- SkShader* fLinearGradientShader{nullptr};
+ sk_sp<SkShader> fColorBitmapShader;
+ sk_sp<SkShader> fAlpha8BitmapShader;
+ sk_sp<SkShader> fLinearGradientShader;
typedef GM INHERITED;
};
-
/*
* Copyright 2015 Google Inc.
*
void onOnceBeforeDraw() override {
SkColor colors[] = { 0xFFFF0000, 0x2000FF00, 0xFF0000FF};
SkPoint pts[] = { SkPoint::Make(0, 0), SkPoint::Make(kRectSize, kRectSize) };
- fShader.reset(SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
- SkShader::kClamp_TileMode));
+ fShader = SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+ SkShader::kClamp_TileMode);
}
void onDraw(SkCanvas* canvas) override {
private:
// Use this as a way of generating and input FP
- SkAutoTUnref<SkShader> fShader;
+ sk_sp<SkShader> fShader;
static const SkScalar kPad;
static const SkScalar kRectSize;
SkRect rect = SkRect::MakeWH(wScalar, hScalar);
SkMatrix mat = SkMatrix::I();
for (int i = 0; i < 4; ++i) {
- paint.setShader(SkGradientShader::CreateRadial(
+ paint.setShader(SkGradientShader::MakeRadial(
pt, radius,
colors, pos,
SK_ARRAY_COUNT(colors),
SkShader::kRepeat_TileMode,
- 0, &mat))->unref();
+ 0, &mat));
canvas.drawRect(rect, paint);
rect.inset(wScalar / 8, hScalar / 8);
mat.preTranslate(6 * wScalar, 6 * hScalar);
SkRect rect = SkRect::MakeWH(wScalar, hScalar);
SkMatrix mat = SkMatrix::I();
for (int i = 0; i < 4; ++i) {
- paint.setShader(SkGradientShader::CreateRadial(
+ paint.setShader(SkGradientShader::MakeRadial(
pt, radius,
colors, pos,
SK_ARRAY_COUNT(colors),
SkShader::kRepeat_TileMode,
- 0, &mat))->unref();
+ 0, &mat));
canvas->drawRect(rect, paint);
rect.inset(wScalar / 8, hScalar / 8);
mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
SkRect rect = SkRect::MakeWH(wScalar, hScalar);
SkMatrix mat = SkMatrix::I();
for (int i = 0; i < 4; ++i) {
- paint.setShader(SkGradientShader::CreateRadial(
+ paint.setShader(SkGradientShader::MakeRadial(
pt, radius,
colors, pos,
SK_ARRAY_COUNT(colors),
SkShader::kRepeat_TileMode,
- 0, &mat))->unref();
+ 0, &mat));
canvas->drawRect(rect, paint);
rect.inset(wScalar / 8, hScalar / 8);
mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
SkPoint center = SkPoint::Make(SkIntToScalar(100), SkIntToScalar(100));
SkColor colors[] = {SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN};
SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1};
- SkShader* s = SkGradientShader::CreateRadial(center,
+ paint.setShader(SkGradientShader::MakeRadial(center,
SkIntToScalar(100),
colors,
pos,
SK_ARRAY_COUNT(colors),
- SkShader::kClamp_TileMode);
- paint.setShader(s)->unref();
+ SkShader::kClamp_TileMode));
paint.setAntiAlias(aa);
showPath(canvas, 0, 0, SkPath::kWinding_FillType,
SK_ColorYELLOW, SK_ColorWHITE};
SkScalar pos[] = {0, SK_ScalarHalf / 2,
3 * SK_ScalarHalf / 2, SK_Scalar1};
- SkShader* s = SkGradientShader::CreateRadial(center,
- SkIntToScalar(1000),
- colors,
- pos,
- SK_ARRAY_COUNT(colors),
- SkShader::kClamp_TileMode);
- bkgnrd.setShader(s)->unref();
+ bkgnrd.setShader(SkGradientShader::MakeRadial(center,
+ SkIntToScalar(1000),
+ colors,
+ pos,
+ SK_ARRAY_COUNT(colors),
+ SkShader::kClamp_TileMode));
canvas->save();
canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
SkMatrix mat;
canvas->save();
// Black/white dither, pixel perfect. This is ground truth.
- p.setShader(SkShader::CreateBitmapShader(
- ditherBmp, rpt, rpt))->unref();
+ p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt));
p.setFilterQuality(SkFilterQuality::kNone_SkFilterQuality);
nextRect("Dither", "Reference");
// the raster pipeline into *not* snapping to nearest.
SkMatrix offsetMatrix = SkMatrix::Concat(
SkMatrix::MakeScale(-1.0f), SkMatrix::MakeTrans(0.5f, 0.0f));
- p.setShader(SkShader::CreateBitmapShader(
- ditherBmp, rpt, rpt, &offsetMatrix))->unref();
+ p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt, &offsetMatrix));
p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality);
nextRect("Dither", "Bilerp");
// Black/white dither, scaled down by 2x. Tests minification.
SkMatrix scaleMatrix = SkMatrix::MakeScale(0.5f);
- p.setShader(SkShader::CreateBitmapShader(
- ditherBmp, rpt, rpt, &scaleMatrix))->unref();
+ p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt, &scaleMatrix));
p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality);
nextRect("Dither", "Scale");
SkPoint::Make(sz + (sz * 10), 0)
};
SkColor colors[2] = { SK_ColorBLACK, SK_ColorWHITE };
- p.setShader(SkGradientShader::CreateLinear(
- points, colors, nullptr, 2, SkShader::kClamp_TileMode))->unref();
+ p.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2,
+ SkShader::kClamp_TileMode));
nextRect("Gradient", 0);
// 50% grey from linear bitmap, with drawBitmap
nextBitmap(srgbGreyBmp, "sRGB BMP");
// Bitmap wrapped in a shader (linear):
- p.setShader(SkShader::CreateBitmapShader(linearGreyBmp, rpt, rpt))->unref();
+ p.setShader(SkShader::MakeBitmapShader(linearGreyBmp, rpt, rpt));
p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality);
nextRect("Lnr BMP", "Shader");
// Bitmap wrapped in a shader (sRGB):
- p.setShader(SkShader::CreateBitmapShader(srgbGreyBmp, rpt, rpt))->unref();
+ p.setShader(SkShader::MakeBitmapShader(srgbGreyBmp, rpt, rpt));
p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality);
nextRect("sRGB BMP", "Shader");
#include "SkGradientShader.h"
#include "SkTypeface.h"
-static SkShader* make_heatGradient(const SkPoint pts[2]) {
+static sk_sp<SkShader> make_heatGradient(const SkPoint pts[2]) {
const SkColor bw[] = { SK_ColorBLACK, SK_ColorWHITE };
- return SkGradientShader::CreateLinear(pts, bw, nullptr,
- SK_ARRAY_COUNT(bw),
- SkShader::kClamp_TileMode);
+ return SkGradientShader::MakeLinear(pts, bw, nullptr, SK_ARRAY_COUNT(bw),
+ SkShader::kClamp_TileMode);
}
static bool setFont(SkPaint* paint, const char name[]) {
}
static void drawGrad(SkCanvas* canvas) {
- SkPoint pts[] = { { 0, 0 }, { 0, SkIntToScalar(HEIGHT) } };
- SkShader* s = make_heatGradient(pts);
+ const SkPoint pts[] = { { 0, 0 }, { 0, SkIntToScalar(HEIGHT) } };
canvas->clear(SK_ColorRED);
SkPaint paint;
- paint.setShader(s)->unref();
+ paint.setShader(make_heatGradient(pts));
SkRect r = { 0, 0, SkIntToScalar(1024), SkIntToScalar(HEIGHT) };
canvas->drawRect(r, paint);
}
//////////////////////////////////////////////////////////////////////////////
-static SkShader* make_gradient(SkColor c) {
+static sk_sp<SkShader> make_gradient(SkColor c) {
const SkPoint pts[] = { { 0, 0 }, { 240, 0 } };
SkColor colors[2];
colors[0] = c;
colors[1] = SkColorSetA(c, 0);
- return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
+ return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
}
static void set_face(SkPaint* paint) {
SkSafeUnref(paint->setTypeface(face));
}
-static void draw_pair(SkCanvas* canvas, SkPaint* paint, SkShader* shader) {
+static void draw_pair(SkCanvas* canvas, SkPaint* paint, const sk_sp<SkShader>& shader) {
const char text[] = "Now is the time for all good";
const size_t len = strlen(text);
paint->setShader(nullptr);
canvas->drawText(text, len, 10, 20, *paint);
- paint->setShader(SkShader::CreateColorShader(paint->getColor()))->unref();
+ paint->setShader(SkShader::MakeColorShader(paint->getColor()));
canvas->drawText(text, len, 10, 40, *paint);
paint->setShader(shader);
canvas->drawText(text, len, 10, 60, *paint);
}
class GammaShaderTextGM : public skiagm::GM {
- SkShader* fShaders[3];
+ sk_sp<SkShader> fShaders[3];
SkColor fColors[3];
public:
GammaShaderTextGM() {
const SkColor colors[] = { SK_ColorBLACK, SK_ColorRED, SK_ColorBLUE };
for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) {
- fShaders[i] = nullptr;
fColors[i] = colors[i];
}
}
- ~GammaShaderTextGM() override {
- for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) {
- SkSafeUnref(fShaders[i]);
- }
- }
-
protected:
SkString onShortName() override {
return SkString("gammagradienttext");
SkScalar scale = 11*SK_Scalar1/12;
m.setScale(scale, scale);
}
- SkShader* s = SkShader::CreateBitmapShader(getBitmap(), fMode, fMode, &m);
-
- paint.setShader(s)->unref();
+ paint.setShader(SkShader::MakeBitmapShader(getBitmap(), fMode, fMode, &m));
paint.setFilterQuality(fDoFilter ? kLow_SkFilterQuality : kNone_SkFilterQuality);
canvas->translate(SkIntToScalar(50), SkIntToScalar(50));
paint.setFakeBoldText(true);
const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
const SkPoint pts[] = {{0, 0}, {kWidth, kHeight}};
- SkAutoTUnref<SkShader> grad(SkGradientShader::CreateLinear(pts, colors, nullptr,
- SK_ARRAY_COUNT(colors),
- SkShader::kMirror_TileMode));
- paint.setShader(grad);
-
-
+ paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+ SkShader::kMirror_TileMode));
paint.setTextAlign(SkPaint::kRight_Align);
drawTestCase(canvas, "Right Align", kTextHeight, paint);
return ref;
}
+template <typename T> void push_ref(lua_State* L, sk_sp<T> sp) {
+ *(T**)lua_newuserdata(L, sizeof(T*)) = sp.release();
+ luaL_getmetatable(L, get_mtname<T>());
+ lua_setmetatable(L, -2);
+}
+
template <typename T> T* get_ref(lua_State* L, int index) {
return *(T**)luaL_checkudata(L, index, get_mtname<T>());
}
SkPoint pts[] = { { x0, y0 }, { x1, y1 } };
SkColor colors[] = { c0, c1 };
- SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
- if (nullptr == s) {
+ auto s = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
+ if (!s) {
lua_pushnil(L);
} else {
- push_ref(L, s)->unref();
+ push_ref(L, std::move(s));
}
return 1;
}