reed 2016-03-29 11:32:50 -07:00 committed by Commit bot
parent 3ebd2760dd
commit cfb6bdf767
69 changed files with 305 additions and 324 deletions

View File

@ -85,11 +85,7 @@ private:
class SrcModeRectBench : public RectBench {
public:
SrcModeRectBench() : INHERITED(1, 0) {
fMode = SkXfermode::Create(SkXfermode::kSrc_Mode);
}
virtual ~SrcModeRectBench() {
SkSafeUnref(fMode);
fMode = SkXfermode::Make(SkXfermode::kSrc_Mode);
}
protected:
@ -108,7 +104,7 @@ protected:
private:
SkString fName;
SkXfermode* fMode;
sk_sp<SkXfermode> fMode;
typedef RectBench INHERITED;
};

View File

@ -21,8 +21,7 @@ public:
: fDoN(doN)
, fFlags(flags & ~USE_AA)
{
fXfer.reset(SkXfermode::Create(mode));
fXfer = SkXfermode::Make(mode);
fProc1 = SkXfermode::GetD32Proc(fXfer, fFlags | SkXfermode::kSrcIsSingle_D32Flag);
fProcN = SkXfermode::GetD32Proc(fXfer, fFlags);
fName.printf("xfer4f_%s_%s_%c_%s_%s",
@ -53,15 +52,15 @@ protected:
void onDraw(int loops, SkCanvas*) override {
for (int i = 0; i < loops * INNER_LOOPS; ++i) {
if (fDoN) {
fProcN(fXfer, fDst, fSrc, N, fAA);
fProcN(fXfer.get(), fDst, fSrc, N, fAA);
} else {
fProc1(fXfer, fDst, fSrc, N, fAA);
fProc1(fXfer.get(), fDst, fSrc, N, fAA);
}
}
}
private:
SkAutoTUnref<SkXfermode> fXfer;
sk_sp<SkXfermode> fXfer;
SkString fName;
SkXfermode::D32Proc fProc1;
SkXfermode::D32Proc fProcN;

View File

@ -21,7 +21,7 @@ public:
: fDoN(doN)
, fFlags(flags & ~USE_AA)
{
fXfer.reset(SkXfermode::Create(mode));
fXfer = SkXfermode::Make(mode);
fProc1 = SkXfermode::GetD64Proc(fXfer, fFlags | SkXfermode::kSrcIsSingle_D64Flag);
fProcN = SkXfermode::GetD64Proc(fXfer, fFlags);
@ -53,15 +53,15 @@ protected:
void onDraw(int loops, SkCanvas*) override {
for (int i = 0; i < loops * INNER_LOOPS; ++i) {
if (fDoN) {
fProcN(fXfer, fDst, fSrc, N, fAA);
fProcN(fXfer.get(), fDst, fSrc, N, fAA);
} else {
fProc1(fXfer, fDst, fSrc, N, fAA);
fProc1(fXfer.get(), fDst, fSrc, N, fAA);
}
}
}
private:
SkAutoTUnref<SkXfermode> fXfer;
sk_sp<SkXfermode> fXfer;
SkString fName;
SkXfermode::D64Proc fProc1;
SkXfermode::D64Proc fProcN;

View File

@ -16,7 +16,7 @@
class XfermodeBench : public Benchmark {
public:
XfermodeBench(SkXfermode::Mode mode, bool aa) {
fXfermode.reset(SkXfermode::Create(mode));
fXfermode = SkXfermode::Make(mode);
fAA = aa;
SkASSERT(fXfermode.get() || SkXfermode::kSrcOver_Mode == mode);
fName.printf("Xfermode_%s%s", SkXfermode::ModeName(mode), aa ? "_aa" : "");
@ -39,7 +39,7 @@ protected:
SkRandom random;
for (int i = 0; i < loops; ++i) {
SkPaint paint;
paint.setXfermode(fXfermode.get());
paint.setXfermode(fXfermode);
paint.setColor(random.nextU());
if (fAA) {
// Draw text to exercise AA code paths.
@ -68,9 +68,9 @@ protected:
}
private:
SkAutoTUnref<SkXfermode> fXfermode;
SkString fName;
bool fAA;
sk_sp<SkXfermode> fXfermode;
SkString fName;
bool fAA;
typedef Benchmark INHERITED;
};
@ -87,8 +87,7 @@ protected:
void onDraw(int loops, SkCanvas* canvas) override {
for (int outer = 0; outer < loops * 10; ++outer) {
for (int i = 0; i <= SkXfermode::kLastMode; ++i) {
SkXfermode* xfer = SkXfermode::Create(SkXfermode::Mode(i));
SkSafeUnref(xfer);
(void)SkXfermode::Make(SkXfermode::Mode(i));
}
}
}

View File

@ -81,8 +81,7 @@ const int gHeight = 64;
const SkScalar W = SkIntToScalar(gWidth);
const SkScalar H = SkIntToScalar(gHeight);
static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode,
SkAlpha a0, SkAlpha a1) {
static SkScalar drawCell(SkCanvas* canvas, sk_sp<SkXfermode> mode, SkAlpha a0, SkAlpha a1) {
SkPaint paint;
paint.setAntiAlias(true);
@ -96,7 +95,7 @@ static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode,
paint.setColor(SK_ColorRED);
paint.setAlpha(a1);
paint.setXfermode(mode);
paint.setXfermode(std::move(mode));
SkScalar offset = SK_Scalar1 / 3;
SkRect rect = SkRect::MakeXYWH(W / 4 + offset,
@ -154,17 +153,14 @@ namespace skiagm {
canvas->translate(W * 5, 0);
canvas->save();
}
SkXfermode* mode = SkXfermode::Create(gModes[i].fMode);
canvas->drawRect(bounds, fBGPaint);
canvas->saveLayer(&bounds, nullptr);
SkScalar dy = drawCell(canvas, mode,
SkScalar dy = drawCell(canvas, SkXfermode::Make(gModes[i].fMode),
gAlphaValue[alpha & 1],
gAlphaValue[alpha & 2]);
canvas->restore();
canvas->translate(0, dy * 5 / 4);
SkSafeUnref(mode);
}
canvas->restore();
canvas->restore();

View File

@ -210,7 +210,7 @@ protected:
if (maxSum > 255) {
SkPaint dimPaint;
dimPaint.setAntiAlias(false);
dimPaint.setXfermode(SkXfermode::Create(SkXfermode::kDstIn_Mode));
dimPaint.setXfermode(SkXfermode::Make(SkXfermode::kDstIn_Mode));
if (255 != paint->getAlpha()) {
// Dim the src and dst colors.
dimPaint.setARGB(255 * 255 / maxSum, 0, 0, 0);
@ -230,13 +230,13 @@ protected:
SkPaint shapePaint(paint);
shapePaint.setAntiAlias(kSquare_Shape != shape);
SkAutoTUnref<SkXfermode> xfermode;
sk_sp<SkXfermode> xfermode;
if (mode <= SkXfermode::kLastMode) {
xfermode.reset(SkXfermode::Create(mode));
xfermode = SkXfermode::Make(mode);
} else {
xfermode.reset(SkArithmeticMode::Create(+1.0f, +0.25f, -0.5f, +0.1f));
xfermode = SkArithmeticMode::Make(+1.0f, +0.25f, -0.5f, +0.1f);
}
shapePaint.setXfermode(xfermode);
shapePaint.setXfermode(std::move(xfermode));
switch (shape) {
case kSquare_Shape:

View File

@ -110,9 +110,8 @@ protected:
SkRect rect = SkRect::MakeXYWH(x, y, SkIntToScalar(WW), SkIntToScalar(HH));
canvas->saveLayer(&rect, nullptr);
canvas->drawBitmap(dst, x, y, nullptr);
SkXfermode* xfer = SkArithmeticMode::Create(k[0], k[1], k[2], k[3]);
SkPaint paint;
paint.setXfermode(xfer)->unref();
paint.setXfermode(SkArithmeticMode::Make(k[0], k[1], k[2], k[3]));
canvas->drawBitmap(src, x, y, &paint);
canvas->restore();
x += gap;
@ -133,13 +132,11 @@ protected:
x += gap;
SkRect rect = SkRect::MakeXYWH(x, y, SkIntToScalar(WW), SkIntToScalar(HH));
canvas->saveLayer(&rect, nullptr);
SkXfermode* xfer1 = SkArithmeticMode::Create(0, -one / 2, 0, 1, enforcePMColor);
SkPaint paint1;
paint1.setXfermode(xfer1)->unref();
paint1.setXfermode(SkArithmeticMode::Make(0, -one / 2, 0, 1, enforcePMColor));
canvas->drawBitmap(dst, x, y, &paint1);
SkXfermode* xfer2 = SkArithmeticMode::Create(0, one / 2, -one, 1);
SkPaint paint2;
paint2.setXfermode(xfer2)->unref();
paint2.setXfermode(SkArithmeticMode::Make(0, one / 2, -one, 1));
canvas->drawBitmap(dst, x, y, &paint2);
canvas->restore();
x += gap;

View File

@ -37,9 +37,7 @@ protected:
// UL corner: replace white with black with a tight tolerance
SkPaint p1;
p1.setColor(SK_ColorBLACK);
p1.setXfermode(SkAvoidXfermode::Create(SK_ColorWHITE,
5,
SkAvoidXfermode::kTargetColor_Mode))->unref();
p1.setXfermode(SkAvoidXfermode::Make(SK_ColorWHITE, 5, SkAvoidXfermode::kTargetColor_Mode));
canvas->drawRect(r, p1);
@ -48,9 +46,8 @@ protected:
// UR corner: draw black everywhere except white with a tight tolerance
SkPaint p2;
p2.setColor(SK_ColorBLACK);
p2.setXfermode(SkAvoidXfermode::Create(SK_ColorWHITE,
250,
SkAvoidXfermode::kAvoidColor_Mode))->unref();
p2.setXfermode(SkAvoidXfermode::Make(SK_ColorWHITE, 250,
SkAvoidXfermode::kAvoidColor_Mode));
canvas->drawRect(r, p2);
@ -59,9 +56,7 @@ protected:
// LL corner: replace red with transparent blue with a loose tolerance
SkPaint p3;
p3.setColor(0x7F0000FF);
p3.setXfermode(SkAvoidXfermode::Create(SK_ColorRED,
250,
SkAvoidXfermode::kTargetColor_Mode))->unref();
p3.setXfermode(SkAvoidXfermode::Make(SK_ColorRED, 250, SkAvoidXfermode::kTargetColor_Mode));
canvas->drawRect(r, p3);
@ -70,9 +65,7 @@ protected:
// LR corner: draw black everywhere except red with a loose tolerance
SkPaint p4;
p4.setColor(SK_ColorBLACK);
p4.setXfermode(SkAvoidXfermode::Create(SK_ColorRED,
5,
SkAvoidXfermode::kAvoidColor_Mode))->unref();
p4.setXfermode(SkAvoidXfermode::Make(SK_ColorRED, 5, SkAvoidXfermode::kAvoidColor_Mode));
canvas->drawRect(r, p4);
}

View File

@ -35,9 +35,8 @@ protected:
// UL corner: replace the green with a tight tolerance
SkPaint p1;
p1.setColor(SK_ColorRED);
p1.setXfermode(SkAvoidXfermode::Create(SK_ColorGREEN,
55,
SkAvoidXfermode::kTargetColor_Mode))->unref();
p1.setXfermode(SkAvoidXfermode::Make(SK_ColorGREEN, 55,
SkAvoidXfermode::kTargetColor_Mode));
canvas->drawRect(r, p1);
@ -46,9 +45,8 @@ protected:
// UR corner: avoid the green with a tight tolerance
SkPaint p2;
p2.setColor(SK_ColorRED);
p2.setXfermode(SkAvoidXfermode::Create(SK_ColorGREEN,
200,
SkAvoidXfermode::kAvoidColor_Mode))->unref();
p2.setXfermode(SkAvoidXfermode::Make(SK_ColorGREEN, 200,
SkAvoidXfermode::kAvoidColor_Mode));
canvas->drawRect(r, p2);
@ -57,9 +55,8 @@ protected:
// LL corner: replace the green with a loose tolerance
SkPaint p3;
p3.setColor(SK_ColorRED);
p3.setXfermode(SkAvoidXfermode::Create(SK_ColorGREEN,
200,
SkAvoidXfermode::kTargetColor_Mode))->unref();
p3.setXfermode(SkAvoidXfermode::Make(SK_ColorGREEN, 200,
SkAvoidXfermode::kTargetColor_Mode));
canvas->drawRect(r, p3);
@ -68,9 +65,7 @@ protected:
// LR corner: avoid the green with a loose tolerance
SkPaint p4;
p4.setColor(SK_ColorRED);
p4.setXfermode(SkAvoidXfermode::Create(SK_ColorGREEN,
55,
SkAvoidXfermode::kAvoidColor_Mode))->unref();
p4.setXfermode(SkAvoidXfermode::Make(SK_ColorGREEN, 55, SkAvoidXfermode::kAvoidColor_Mode));
canvas->drawRect(r, p4);
}

View File

@ -38,9 +38,7 @@ protected:
SkPaint p1;
p1.setColor(SK_ColorGREEN);
p1.setAntiAlias(true);
p1.setXfermode(SkAvoidXfermode::Create(SK_ColorWHITE,
5,
SkAvoidXfermode::kTargetColor_Mode))->unref();
p1.setXfermode(SkAvoidXfermode::Make(SK_ColorWHITE, 5, SkAvoidXfermode::kTargetColor_Mode));
canvas->drawRect(r, p1);
@ -50,9 +48,8 @@ protected:
SkPaint p2;
p2.setColor(SK_ColorRED);
p2.setAntiAlias(true);
p2.setXfermode(SkAvoidXfermode::Create(SK_ColorWHITE,
250,
SkAvoidXfermode::kAvoidColor_Mode))->unref();
p2.setXfermode(SkAvoidXfermode::Make(SK_ColorWHITE, 250,
SkAvoidXfermode::kAvoidColor_Mode));
canvas->drawRect(r, p2);
@ -62,9 +59,8 @@ protected:
SkPaint p3;
p3.setColor(SK_ColorBLUE);
p3.setAntiAlias(true);
p3.setXfermode(SkAvoidXfermode::Create(SK_ColorWHITE,
250,
SkAvoidXfermode::kTargetColor_Mode))->unref();
p3.setXfermode(SkAvoidXfermode::Make(SK_ColorWHITE, 250,
SkAvoidXfermode::kTargetColor_Mode));
canvas->drawRect(r, p3);
@ -74,9 +70,7 @@ protected:
SkPaint p4;
p4.setColor(SK_ColorYELLOW);
p4.setAntiAlias(true);
p4.setXfermode(SkAvoidXfermode::Create(SK_ColorWHITE,
5,
SkAvoidXfermode::kAvoidColor_Mode))->unref();
p4.setXfermode(SkAvoidXfermode::Make(SK_ColorWHITE, 5, SkAvoidXfermode::kAvoidColor_Mode));
canvas->drawRect(r, p4);
}

View File

@ -199,12 +199,9 @@ protected:
}
void onDraw(SkCanvas* canvas) override {
SkXfermode* mode = SkXfermode::Create(SkXfermode::kXor_Mode);
SkPaint paint;
paint.setAlpha(128);
paint.setXfermode(mode)->unref();
paint.setXfermode(SkXfermode::Make(SkXfermode::kXor_Mode));
SkRect srcR1 = { 0.0f, 0.0f, 4096.0f, 2040.0f };
SkRect dstR1 = { 10.1f, 10.1f, 629.9f, 400.9f };

View File

@ -34,7 +34,7 @@ protected:
void onDraw(SkCanvas* canvas) override {
SkPaint whitePaint;
whitePaint.setColor(SK_ColorWHITE);
whitePaint.setXfermode(SkXfermode::Create(SkXfermode::kSrc_Mode))->unref();
whitePaint.setXfermode(SkXfermode::Make(SkXfermode::kSrc_Mode));
whitePaint.setAntiAlias(true);
// This scale exercises precision limits in the circle blur effect (crbug.com/560651)

View File

@ -121,8 +121,6 @@ protected:
SkScalar y0 = 0;
SkScalar x = x0, y = y0;
for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
SkXfermode* mode = SkXfermode::Create(gModes[i].fMode);
SkAutoUnref aur(mode);
SkRect r;
r.set(x, y, x+w, y+h);
@ -136,7 +134,7 @@ protected:
p.setShader(nullptr);
canvas->drawRect(r, p);
textP.setXfermode(mode);
textP.setXfermode(SkXfermode::Make(gModes[i].fMode));
canvas->drawText("H", 1, x+ w/10.f, y + 7.f*h/8.f, textP);
#if 1
canvas->drawText(gModes[i].fLabel, strlen(gModes[i].fLabel),

View File

@ -30,9 +30,8 @@ static sk_sp<SkShader> make_shader(SkXfermode::Mode mode) {
colors[1] = SkColorSetARGB(0x80, 0, 0, 0);
auto shaderB = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode));
return SkShader::MakeComposeShader(std::move(shaderA), std::move(shaderB), xfer);
return SkShader::MakeComposeShader(std::move(shaderA), std::move(shaderB),
SkXfermode::Make(mode));
}
class ComposeShaderGM : public skiagm::GM {
@ -176,7 +175,7 @@ protected:
}
void onDraw(SkCanvas* canvas) override {
SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kDstOver_Mode));
auto xfer(SkXfermode::Make(SkXfermode::kDstOver_Mode));
sk_sp<SkShader> shaders[] = {
// gradient should appear over color bitmap

View File

@ -26,7 +26,7 @@ static sk_sp<SkImage> make_atlas(SkCanvas* caller, int atlasSize) {
SkCanvas* canvas = surface->getCanvas();
SkPaint paint;
paint.setXfermode(SkXfermode::Create(SkXfermode::kSrc_Mode));
paint.setXfermode(SkXfermode::Make(SkXfermode::kSrc_Mode));
paint.setColor(SK_ColorWHITE);
SkRect r = SkRect::MakeXYWH(0, 0,

View File

@ -33,7 +33,7 @@ const int gHeight = 64;
const SkScalar W = SkIntToScalar(gWidth);
const SkScalar H = SkIntToScalar(gHeight);
static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode, SkAlpha a0, SkAlpha a1) {
static SkScalar drawCell(SkCanvas* canvas, sk_sp<SkXfermode> mode, SkAlpha a0, SkAlpha a1) {
SkPaint paint;
paint.setAntiAlias(true);
@ -47,7 +47,7 @@ static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode, SkAlpha a0, SkAlpha
paint.setColor(SK_ColorRED);
paint.setAlpha(a1);
paint.setXfermode(mode);
paint.setXfermode(std::move(mode));
for (int angle = 0; angle < 24; ++angle) {
SkScalar x = SkScalarCos(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gWidth;
SkScalar y = SkScalarSin(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gHeight;
@ -101,17 +101,15 @@ namespace skiagm {
canvas->translate(W * 5, 0);
canvas->save();
}
SkXfermode* mode = SkXfermode::Create(gModes[i].fMode);
canvas->drawRect(bounds, fBGPaint);
canvas->saveLayer(&bounds, nullptr);
SkScalar dy = drawCell(canvas, mode,
SkScalar dy = drawCell(canvas, SkXfermode::Make(gModes[i].fMode),
gAlphaValue[alpha & 1],
gAlphaValue[alpha & 2]);
canvas->restore();
canvas->translate(0, dy * 5 / 4);
SkSafeUnref(mode);
}
canvas->restore();
canvas->restore();

View File

@ -140,11 +140,10 @@ protected:
auto matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Create(matrixFilter.get(), morph));
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
SkAutoTUnref<SkImageFilter> blendColor(SkXfermodeImageFilter::Create(mode, colorMorph));
SkPaint paint;
paint.setImageFilter(blendColor);
paint.setImageFilter(SkXfermodeImageFilter::Make(
SkXfermode::Make(SkXfermode::kSrcOver_Mode), colorMorph));
DrawClippedImage(canvas, fImage.get(), paint);
canvas->translate(SkIntToScalar(100), 0);
}
@ -158,12 +157,11 @@ protected:
SkAutoTUnref<SkImageFilter> offsetFilter(
SimpleOffsetFilter::Create(10.0f, 10.f, matrixFilter));
SkAutoTUnref<SkXfermode> arith(SkArithmeticMode::Create(0, SK_Scalar1, SK_Scalar1, 0));
SkAutoTUnref<SkImageFilter> arithFilter(
SkXfermodeImageFilter::Create(arith, matrixFilter, offsetFilter));
SkPaint paint;
paint.setImageFilter(arithFilter);
paint.setImageFilter(
SkXfermodeImageFilter::Make(SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0),
matrixFilter, offsetFilter, nullptr));
DrawClippedImage(canvas, fImage.get(), paint);
canvas->translate(SkIntToScalar(100), 0);
}
@ -171,13 +169,11 @@ protected:
SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(
SkIntToScalar(10), SkIntToScalar(10)));
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcIn_Mode));
SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), SkIntToScalar(100)));
SkAutoTUnref<SkImageFilter> blend(
SkXfermodeImageFilter::Create(mode, blur, nullptr, &cropRect));
SkPaint paint;
paint.setImageFilter(blend);
paint.setImageFilter(
SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kSrcIn_Mode), blur,
nullptr, &cropRect));
DrawClippedImage(canvas, fImage.get(), paint);
canvas->translate(SkIntToScalar(100), 0);
}
@ -188,8 +184,6 @@ protected:
// (supplied by the dilate).
SkAutoTUnref<SkImageFilter> dilate(SkDilateImageFilter::Create(5, 5));
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcIn_Mode));
SkScalar kernel[9] = {
SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1),
SkIntToScalar(-1), SkIntToScalar( 7 ), SkIntToScalar(-1),

View File

@ -76,8 +76,7 @@ protected:
this->drawColumn(surfCanvas, SK_ColorCYAN, SK_ColorMAGENTA, true);
SkPaint surfPaint;
SkAutoTUnref<SkXfermode> xfermode(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
surfPaint.setXfermode(xfermode);
surfPaint.setXfermode(SkXfermode::Make(SkXfermode::kSrcOver_Mode));
surface->draw(canvas, 0, 0, &surfPaint);
}
@ -123,14 +122,13 @@ protected:
backgroundPaint);
SkScalar y = fTextHeight;
for (size_t m = 0; m < SK_ARRAY_COUNT(gModes); m++) {
SkAutoTUnref<SkXfermode> xfermode(SkXfermode::Create(gModes[m].fMode));
SkPaint paint;
paint.setColor(textColor);
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setLCDRenderText(true);
paint.setTextSize(fTextHeight);
paint.setXfermode(xfermode);
paint.setXfermode(SkXfermode::Make(gModes[m].fMode));
sk_tool_utils::set_portable_typeface(&paint);
if (useGrad) {
SkRect r;

View File

@ -60,8 +60,8 @@ protected:
SK_ColorMAGENTA,
};
SkAutoTUnref<SkXfermode> xfermode(SkXfermode::Create(mode));
SkAutoTUnref<SkXfermode> xfermode2(SkXfermode::Create(mode2));
sk_sp<SkXfermode> xfermode(SkXfermode::Make(mode));
sk_sp<SkXfermode> xfermode2(SkXfermode::Make(mode2));
for (size_t i = 0; i < SK_ARRAY_COUNT(colors); i++) {
canvas->save();
canvas->translate(x, y);

View File

@ -95,7 +95,7 @@ DEF_SIMPLE_GM(patch_primitive, canvas, 800, 800) {
canvas->save();
for (int y = 0; y < 3; y++) {
SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(modes[y]));
sk_sp<SkXfermode> xfer(SkXfermode::Make(modes[y]));
for (int x = 0; x < 4; x++) {
canvas->save();

View File

@ -38,7 +38,7 @@ protected:
// the green & blue channels alone
SkPaint p1;
p1.setColor(SK_ColorBLACK); // noop
p1.setXfermode(SkPixelXorXfermode::Create(0x7FFF0000))->unref();
p1.setXfermode(SkPixelXorXfermode::Make(0x7FFF0000));
canvas->drawRect(r, p1);
@ -47,7 +47,7 @@ protected:
// Negate the dst color via the src color
SkPaint p2;
p2.setColor(SK_ColorWHITE);
p2.setXfermode(SkPixelXorXfermode::Create(SK_ColorBLACK))->unref(); // noop
p2.setXfermode(SkPixelXorXfermode::Make(SK_ColorBLACK)); // noop
canvas->drawRect(r, p2);
@ -56,7 +56,7 @@ protected:
// Just return the original color
SkPaint p3;
p3.setColor(SK_ColorBLACK); // noop
p3.setXfermode(SkPixelXorXfermode::Create(SK_ColorBLACK))->unref(); // noop
p3.setXfermode(SkPixelXorXfermode::Make(SK_ColorBLACK)); // noop
canvas->drawRect(r, p3);
@ -66,7 +66,7 @@ protected:
// the blue channel alone
SkPaint p4;
p4.setColor(SK_ColorBLACK); // noop
p4.setXfermode(SkPixelXorXfermode::Create(SK_ColorYELLOW))->unref();
p4.setXfermode(SkPixelXorXfermode::Make(SK_ColorYELLOW));
canvas->drawRect(r, p4);
}

View File

@ -154,7 +154,7 @@ protected:
canvas->translate(4, 4);
int x = 0;
for (size_t j = 0; j < SK_ARRAY_COUNT(modes); ++j) {
SkXfermode* xfer = SkXfermode::Create(modes[j]);
auto xfer = SkXfermode::Make(modes[j]);
canvas->save();
for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
paint.setShader(rec[i].fShader);
@ -170,7 +170,6 @@ protected:
}
canvas->restore();
canvas->translate(0, 40);
SkSafeUnref(xfer);
}
}

View File

@ -87,9 +87,8 @@ protected:
int x = 0, y = 0;
SkAutoTUnref<SkImageFilter> background(SkImageSource::Create(fCheckerboard.get()));
for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(gModes[i].fMode));
SkAutoTUnref<SkImageFilter> filter(SkXfermodeImageFilter::Create(mode, background));
paint.setImageFilter(filter);
paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(gModes[i].fMode),
background));
DrawClippedBitmap(canvas, fBitmap, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -98,9 +97,8 @@ protected:
}
}
// Test arithmetic mode as image filter
SkAutoTUnref<SkXfermode> mode(SkArithmeticMode::Create(0, SK_Scalar1, SK_Scalar1, 0));
SkAutoTUnref<SkImageFilter> filter(SkXfermodeImageFilter::Create(mode, background));
paint.setImageFilter(filter);
paint.setImageFilter(SkXfermodeImageFilter::Make(
SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0), background));
DrawClippedBitmap(canvas, fBitmap, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -108,8 +106,7 @@ protected:
y += fBitmap.height() + MARGIN;
}
// Test nullptr mode
filter.reset(SkXfermodeImageFilter::Create(nullptr, background));
paint.setImageFilter(filter);
paint.setImageFilter(SkXfermodeImageFilter::Make(nullptr, background));
DrawClippedBitmap(canvas, fBitmap, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -125,9 +122,9 @@ protected:
SkIntToScalar(4), SkIntToScalar(-4), foreground));
SkAutoTUnref<SkImageFilter> offsetBackground(SkOffsetImageFilter::Create(
SkIntToScalar(4), SkIntToScalar(4), background));
mode.reset(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
filter.reset(SkXfermodeImageFilter::Create(mode, offsetBackground, offsetForeground));
paint.setImageFilter(filter);
paint.setImageFilter(SkXfermodeImageFilter::Make(
SkXfermode::Make(SkXfermode::kSrcOver_Mode), offsetBackground,
offsetForeground, nullptr));
DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -135,9 +132,8 @@ protected:
y += fBitmap.height() + MARGIN;
}
// Test offsets on Darken (uses shader blend)
mode.reset(SkXfermode::Create(SkXfermode::kDarken_Mode));
filter.reset(SkXfermodeImageFilter::Create(mode, offsetBackground, offsetForeground));
paint.setImageFilter(filter);
paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kDarken_Mode),
offsetBackground, offsetForeground, nullptr));
DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -158,10 +154,8 @@ protected:
fBitmap.width() + offsets[i][2],
fBitmap.height() + offsets[i][3]);
SkImageFilter::CropRect rect(SkRect::Make(cropRect));
mode.reset(SkXfermode::Create(sampledModes[i]));
filter.reset(SkXfermodeImageFilter::Create(
mode, offsetBackground, offsetForeground, &rect));
paint.setImageFilter(filter);
paint.setImageFilter(SkXfermodeImageFilter::Make(
SkXfermode::Make(sampledModes[i]), offsetBackground, offsetForeground, &rect));
DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -170,12 +164,11 @@ protected:
}
}
// Test small bg, large fg with Screen (uses shader blend)
mode.reset(SkXfermode::Create(SkXfermode::kScreen_Mode));
auto mode = SkXfermode::Make(SkXfermode::kScreen_Mode);
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60));
SkAutoTUnref<SkImageFilter> cropped(
SkOffsetImageFilter::Create(0, 0, foreground, &cropRect));
filter.reset(SkXfermodeImageFilter::Create(mode, cropped, background));
paint.setImageFilter(filter);
paint.setImageFilter(SkXfermodeImageFilter::Make(mode, cropped, background, nullptr));
DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
@ -183,8 +176,7 @@ protected:
y += fBitmap.height() + MARGIN;
}
// Test small fg, large bg with Screen (uses shader blend)
filter.reset(SkXfermodeImageFilter::Create(mode, background, cropped));
paint.setImageFilter(filter);
paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background, cropped, nullptr));
DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {

View File

@ -24,19 +24,19 @@ enum CustomModes {
kAvoid_CustomMode = 3 << kCustomShift,
};
static SkXfermode* make_custom(int customMode) {
static sk_sp<SkXfermode> make_custom(int customMode) {
switch (customMode) {
case kArithmetic_CustomMode: {
const SkScalar k1 = 0.25;
const SkScalar k2 = 0.75;
const SkScalar k3 = 0.75;
const SkScalar k4 = -0.25;
return SkArithmeticMode::Create(k1, k2, k3, k4);
return SkArithmeticMode::Make(k1, k2, k3, k4);
}
case kPixelXor_CustomMode:
return SkPixelXorXfermode::Create(0xFF88CC44);
return SkPixelXorXfermode::Make(0xFF88CC44);
case kAvoid_CustomMode:
return SkAvoidXfermode::Create(0xFFFF0000, 0x44, SkAvoidXfermode::kAvoidColor_Mode);
return SkAvoidXfermode::Make(0xFFFF0000, 0x44, SkAvoidXfermode::kAvoidColor_Mode);
default:
break;
}
@ -155,7 +155,7 @@ class XfermodesGM : public skiagm::GM {
* uses the implied shape of the drawing command and these modes
* demonstrate that.
*/
void draw_mode(SkCanvas* canvas, SkXfermode* mode, SrcType srcType,
void draw_mode(SkCanvas* canvas, sk_sp<SkXfermode> mode, SrcType srcType,
SkScalar x, SkScalar y) {
SkPaint p;
SkMatrix m;
@ -163,7 +163,7 @@ class XfermodesGM : public skiagm::GM {
m.setTranslate(x, y);
canvas->drawBitmap(fSrcB, x, y, &p);
p.setXfermode(mode);
p.setXfermode(std::move(mode));
switch (srcType) {
case kSmallTransparentImage_SrcType: {
m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y);
@ -279,11 +279,11 @@ protected:
if ((gModes[i].fSourceTypeMask & sourceType) == 0) {
continue;
}
SkAutoTUnref<SkXfermode> mode;
sk_sp<SkXfermode> mode;
if (gModes[i].fSourceTypeMask & kCustomMask) {
mode.reset(make_custom(gModes[i].fSourceTypeMask & kCustomMask));
mode = make_custom(gModes[i].fSourceTypeMask & kCustomMask);
} else {
mode.reset(SkXfermode::Create(gModes[i].fMode));
mode = SkXfermode::Make(gModes[i].fMode);
}
SkRect r;
r.set(x, y, x+w, y+h);
@ -294,7 +294,7 @@ protected:
canvas->drawRect(r, p);
canvas->saveLayer(&r, nullptr);
draw_mode(canvas, mode, static_cast<SrcType>(sourceType),
draw_mode(canvas, std::move(mode), static_cast<SrcType>(sourceType),
r.fLeft, r.fTop);
canvas->restore();

View File

@ -41,8 +41,6 @@ protected:
SkScalar x = 0, y = 0;
for (size_t m = 0; m <= SkXfermode::kLastMode; m++) {
SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(m);
SkXfermode* xm = SkXfermode::Create(mode);
SkAutoUnref aur(xm);
canvas->save();
@ -59,7 +57,7 @@ protected:
p.setShader(fDst);
canvas->drawRect(r, p);
p.setShader(fSrc);
p.setXfermode(xm);
p.setXfermode(SkXfermode::Make(mode));
canvas->drawRect(r, p);
canvas->restore();

View File

@ -25,6 +25,7 @@
'SK_SUPPORT_LEGACY_PATHEFFECT_PTR',
'SK_SUPPORT_LEGACY_NEW_SURFACE_API',
'SK_SUPPORT_LEGACY_PICTURE_PTR',
'SK_SUPPORT_LEGACY_XFERMODE_PTR',
],
},
}

View File

@ -39,9 +39,14 @@ public:
Tolerance near 0: draw only on colors that are nearly identical to the op-color
Tolerance near 255: draw on any colors even remotely similar to the op-color
*/
static SkAvoidXfermode* Create(SkColor opColor, U8CPU tolerance, Mode mode) {
return new SkAvoidXfermode(opColor, tolerance, mode);
static sk_sp<SkXfermode> Make(SkColor opColor, U8CPU tolerance, Mode mode) {
return sk_sp<SkXfermode>(new SkAvoidXfermode(opColor, tolerance, mode));
}
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
static SkAvoidXfermode* Create(SkColor opColor, U8CPU tolerance, Mode mode) {
return (SkAvoidXfermode*)(Make(opColor, tolerance, mode).release());
}
#endif
// overrides from SkXfermode
void xfer32(SkPMColor dst[], const SkPMColor src[], int count,

View File

@ -17,9 +17,14 @@
*/
class SK_API SkPixelXorXfermode : public SkXfermode {
public:
static SkXfermode* Create(SkColor opColor) {
return new SkPixelXorXfermode(opColor);
static sk_sp<SkXfermode> Make(SkColor opColor) {
return sk_sp<SkXfermode>(new SkPixelXorXfermode(opColor));
}
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
static SkXfermode* Create(SkColor opColor) {
return Make(opColor).release();
}
#endif
#if SK_SUPPORT_GPU
const GrFragmentProcessor* getFragmentProcessorForImageFilter(

View File

@ -1053,6 +1053,14 @@ public:
const SkColor colors[], SkXfermode* xmode,
const uint16_t indices[], int indexCount,
const SkPaint& paint);
void drawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], sk_sp<SkXfermode>& xmode,
const uint16_t indices[], int indexCount,
const SkPaint& paint) {
this->drawVertices(vmode, vertexCount, vertices, texs, colors, xmode.get(),
indices, indexCount, paint);
}
/**
Draw a cubic coons patch
@ -1069,6 +1077,10 @@ public:
*/
void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint);
void drawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4],
const sk_sp<SkXfermode>& xmode, const SkPaint& paint) {
this->drawPatch(cubics, colors, texCoords, xmode.get(), paint);
}
/**
* Draw a set of sprites from the atlas. Each is specified by a tex rectangle in the

View File

@ -539,8 +539,10 @@ public:
paint
@return xfermode
*/
SkXfermode* setXfermode(SkXfermode* xfermode);
void setXfermode(sk_sp<SkXfermode>);
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
SkXfermode* setXfermode(SkXfermode* xfermode);
#endif
/** Create an xfermode based on the specified Mode, and assign it into the
paint, returning the mode that was set. If the Mode is SrcOver, then

View File

@ -403,8 +403,12 @@ public:
*
* The caller is responsible for managing its reference-count for the xfer (if not null).
*/
static sk_sp<SkShader> MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader> src,
sk_sp<SkXfermode> xfer);
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
static sk_sp<SkShader> MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader> src,
SkXfermode* xfer);
#endif
/** Call this to create a new shader that will draw with the specified bitmap.
*

View File

@ -126,6 +126,9 @@ public:
* if the xfermode is NULL, and if so, treats it as kSrcOver_Mode.
*/
static bool AsMode(const SkXfermode*, Mode* mode);
static bool AsMode(const sk_sp<SkXfermode>& xfer, Mode* mode) {
return AsMode(xfer.get(), mode);
}
/**
* Returns true if the xfermode claims to be the specified Mode. This works
@ -138,10 +141,22 @@ public:
* }
*/
static bool IsMode(const SkXfermode* xfer, Mode mode);
static bool IsMode(const sk_sp<SkXfermode>& xfer, Mode mode) {
return IsMode(xfer.get(), mode);
}
/** Return an SkXfermode object for the specified mode.
*/
static SkXfermode* Create(Mode mode);
static sk_sp<SkXfermode> Make(Mode);
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
static SkXfermode* Create(Mode mode) {
return Make(mode).release();
}
SK_ATTR_DEPRECATED("use AsMode(...)")
static bool IsMode(const SkXfermode* xfer, Mode* mode) {
return AsMode(xfer, mode);
}
#endif
/** Return a function pointer to a routine that applies the specified
porter-duff transfer mode.
@ -159,11 +174,6 @@ public:
*/
static bool ModeAsCoeff(Mode mode, Coeff* src, Coeff* dst);
SK_ATTR_DEPRECATED("use AsMode(...)")
static bool IsMode(const SkXfermode* xfer, Mode* mode) {
return AsMode(xfer, mode);
}
/**
* Returns whether or not the xfer mode can support treating coverage as alpha
*/
@ -174,6 +184,9 @@ public:
* the xfermode is NULL, and if so, treats it as kSrcOver_Mode.
*/
static bool SupportsCoverageAsAlpha(const SkXfermode* xfer);
static bool SupportsCoverageAsAlpha(const sk_sp<SkXfermode>& xfer) {
return SupportsCoverageAsAlpha(xfer.get());
}
enum SrcColorOpacity {
// The src color is known to be opaque (alpha == 255)
@ -198,6 +211,9 @@ public:
* the xfermode is NULL, and if so, treats it as kSrcOver_Mode.
*/
static bool IsOpaque(const SkXfermode* xfer, SrcColorOpacity opacityType);
static bool IsOpaque(const sk_sp<SkXfermode>& xfer, SrcColorOpacity opacityType) {
return IsOpaque(xfer.get(), opacityType);
}
#if SK_SUPPORT_GPU
/** Used by the SkXfermodeImageFilter to blend two colors via a GrFragmentProcessor.
@ -228,6 +244,9 @@ public:
typedef void (*D32Proc)(const SkXfermode*, uint32_t dst[], const SkPM4f src[],
int count, const SkAlpha coverage[]);
static D32Proc GetD32Proc(SkXfermode*, uint32_t flags);
static D32Proc GetD32Proc(const sk_sp<SkXfermode>& xfer, uint32_t flags) {
return GetD32Proc(xfer.get(), flags);
}
enum D64Flags {
kSrcIsOpaque_D64Flag = 1 << 0,
@ -237,6 +256,9 @@ public:
typedef void (*D64Proc)(const SkXfermode*, uint64_t dst[], const SkPM4f src[], int count,
const SkAlpha coverage[]);
static D64Proc GetD64Proc(SkXfermode*, uint32_t flags);
static D64Proc GetD64Proc(const sk_sp<SkXfermode>& xfer, uint32_t flags) {
return GetD64Proc(xfer.get(), flags);
}
enum LCDFlags {
kSrcIsOpaque_LCDFlag = 1 << 0, // else src(s) may have alpha < 1

View File

@ -10,8 +10,7 @@
#include "SkFlattenable.h"
#include "SkScalar.h"
class SkXfermode;
#include "SkXfermode.h"
class SK_API SkArithmeticMode {
public:
@ -22,9 +21,15 @@ public:
* k1=k3=k4=0, k2=1.0 results in returning the src
* k1=k2=k4=0, k3=1.0 results in returning the dst
*/
static sk_sp<SkXfermode> Make(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4,
bool enforcePMColor = true);
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
static SkXfermode* Create(SkScalar k1, SkScalar k2,
SkScalar k3, SkScalar k4,
bool enforcePMColor = true);
bool enforcePMColor = true) {
return Make(k1, k2, k3, k4, enforcePMColor).release();
}
#endif
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP();

View File

@ -21,13 +21,19 @@ class SK_API SkXfermodeImageFilter : public SkImageFilter {
*/
public:
static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, SkImageFilter* background,
SkImageFilter* foreground, const CropRect* cropRect);
static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, SkImageFilter* background) {
return Make(std::move(mode), background, nullptr, nullptr);
}
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
static SkImageFilter* Create(SkXfermode* mode, SkImageFilter* background,
SkImageFilter* foreground = NULL,
const CropRect* cropRect = NULL) {
SkImageFilter* inputs[2] = { background, foreground };
return new SkXfermodeImageFilter(mode, inputs, cropRect);
return Make(sk_ref_sp(mode), background, foreground, cropRect).release();
}
#endif
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkXfermodeImageFilter)
@ -43,12 +49,12 @@ public:
#endif
protected:
SkXfermodeImageFilter(SkXfermode* mode, SkImageFilter* inputs[2],
SkXfermodeImageFilter(sk_sp<SkXfermode> mode, SkImageFilter* inputs[2],
const CropRect* cropRect);
void flatten(SkWriteBuffer&) const override;
private:
SkAutoTUnref<SkXfermode> fMode;
sk_sp<SkXfermode> fMode;
typedef SkImageFilter INHERITED;
};

View File

@ -524,6 +524,7 @@ DEFINES_ALL = [
"SK_SUPPORT_LEGACY_COLORFILTER_PTR",
"SK_SUPPORT_LEGACY_CREATESHADER_PTR",
"SK_SUPPORT_LEGACY_PICTURE_PTR",
"SK_SUPPORT_LEGACY_XFERMODE_PTR",
]
################################################################################

View File

@ -138,8 +138,8 @@ protected:
{ fTexX + texWidth, fTexY + texHeight},
{ fTexX - texWidth, fTexY + texHeight}}
;
SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kSrc_Mode));
sk_sp<SkXfermode> xfer(SkXfermode::Make(SkXfermode::kSrc_Mode));
SkScalar scaleFreq = 2.0;
fShader1 = SkPerlinNoiseShader2::MakeImprovedNoise(fXFreq/scaleFreq, fYFreq/scaleFreq, 4,

View File

@ -35,9 +35,7 @@ const int gHeight = 64;
const SkScalar W = SkIntToScalar(gWidth);
const SkScalar H = SkIntToScalar(gHeight);
static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode,
SkAlpha a0, SkAlpha a1) {
static SkScalar drawCell(SkCanvas* canvas, const sk_sp<SkXfermode>& mode, SkAlpha a0, SkAlpha a1) {
SkPaint paint;
paint.setAntiAlias(true);
@ -109,17 +107,15 @@ protected:
canvas->translate(W * 5, 0);
canvas->save();
}
SkXfermode* mode = SkXfermode::Create(gModes[i].fMode);
sk_sp<SkXfermode> mode = SkXfermode::Make(gModes[i].fMode);
canvas->drawRect(bounds, fBGPaint);
canvas->saveLayer(&bounds, nullptr);
SkScalar dy = drawCell(canvas, mode,
gAlphaValue[alpha & 1],
SkScalar dy = drawCell(canvas, mode, gAlphaValue[alpha & 1],
gAlphaValue[alpha & 2]);
canvas->restore();
canvas->translate(0, dy * 5 / 4);
SkSafeUnref(mode);
}
canvas->restore();
canvas->restore();

View File

@ -382,7 +382,6 @@ protected:
SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(12)/5);
SkMaskFilter* embossFilter = SkEmbossMaskFilter::Create(sigma, light);
SkXfermode* xfermode = SkXfermode::Create(SkXfermode::kXor_Mode);
auto lightingFilter = SkColorMatrixFilter::MakeLightingFilter(
0xff89bc45, 0xff112233);
@ -404,7 +403,7 @@ protected:
paint.setColor(SK_ColorGREEN);
paint.setStrokeWidth(SkIntToScalar(10));
paint.setStyle(SkPaint::kStroke_Style);
paint.setXfermode(xfermode)->unref();
paint.setXfermode(SkXfermode::Make(SkXfermode::kXor_Mode));
paint.setColorFilter(lightingFilter);
canvas->drawLine(start.fX, start.fY, stop.fX, stop.fY, paint); // should not be green
paint.setXfermode(nullptr);
@ -505,8 +504,8 @@ protected:
SkColor colors2[] = {SK_ColorBLACK, SkColorSetARGB(0x80, 0, 0, 0)};
auto shaderB = SkGradientShader::MakeLinear(pts, colors2, nullptr,
2, SkShader::kClamp_TileMode);
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kDstIn_Mode));
return SkShader::MakeComposeShader(shaderA, shaderB, mode);
return SkShader::MakeComposeShader(std::move(shaderA), std::move(shaderB),
SkXfermode::Make(SkXfermode::kDstIn_Mode));
}
virtual void startTest() {

View File

@ -582,10 +582,9 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
filter = SkDownSampleImageFilter::Create(make_scalar());
break;
case XFERMODE:
{
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(make_xfermode()));
filter = SkXfermodeImageFilter::Create(mode, make_image_filter(), make_image_filter());
}
filter = SkXfermodeImageFilter::Make(SkXfermode::Make(make_xfermode()),
make_image_filter(), make_image_filter(),
nullptr).release();
break;
case OFFSET:
filter = SkOffsetImageFilter::Create(make_scalar(), make_scalar(), make_image_filter());

View File

@ -35,8 +35,7 @@ const int gHeight = 64;
const SkScalar W = SkIntToScalar(gWidth);
const SkScalar H = SkIntToScalar(gHeight);
static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode, SkAlpha a0, SkAlpha a1) {
static SkScalar drawCell(SkCanvas* canvas, sk_sp<SkXfermode> mode, SkAlpha a0, SkAlpha a1) {
SkPaint paint;
paint.setAntiAlias(true);
@ -105,17 +104,14 @@ protected:
canvas->translate(W * 5, 0);
canvas->save();
}
SkXfermode* mode = SkXfermode::Create(gModes[i].fMode);
canvas->drawRect(bounds, fBGPaint);
canvas->saveLayer(&bounds, nullptr);
SkScalar dy = drawCell(canvas, mode,
SkScalar dy = drawCell(canvas, SkXfermode::Make(gModes[i].fMode),
gAlphaValue[alpha & 1],
gAlphaValue[alpha & 2]);
canvas->restore();
canvas->translate(0, dy * 5 / 4);
SkSafeUnref(mode);
}
canvas->restore();
canvas->restore();

View File

@ -32,11 +32,10 @@ static sk_sp<SkShader> make_bitmapfade(const SkBitmap& bm) {
auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
auto shaderB = SkShader::MakeBitmapShader(bm,
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kDstIn_Mode));
return SkShader::MakeComposeShader(std::move(shaderB), std::move(shaderA), mode);
return SkShader::MakeComposeShader(std::move(shaderB), std::move(shaderA),
SkXfermode::Make(SkXfermode::kDstIn_Mode));
}
class ShaderView : public SampleView {
@ -62,9 +61,8 @@ public:
colors[1] = SkColorSetARGB(0x80, 0, 0, 0);
auto shaderB = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kDstIn_Mode));
fShader = SkShader::MakeComposeShader(std::move(shaderA), std::move(shaderB), mode);
fShader = SkShader::MakeComposeShader(std::move(shaderA), std::move(shaderB),
SkXfermode::Make(SkXfermode::kDstIn_Mode));
}
protected:

View File

@ -39,7 +39,7 @@ class XfermodesBlurView : public SampleView {
SkBitmap fBG;
SkBitmap fSrcB, fDstB;
void draw_mode(SkCanvas* canvas, SkXfermode* mode, int alpha,
void draw_mode(SkCanvas* canvas, sk_sp<SkXfermode> mode, int alpha,
SkScalar x, SkScalar y) {
SkPaint p;
SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
@ -58,7 +58,7 @@ class XfermodesBlurView : public SampleView {
r.offset(x, y);
canvas->drawOval(r, p);
p.setXfermode(mode);
p.setXfermode(std::move(mode));
// draw a square overlapping the circle
// in the lower right of the canvas
@ -163,8 +163,6 @@ protected:
for (int twice = 0; twice < 2; twice++) {
SkScalar x = x0, y = 0;
for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
SkXfermode* mode = SkXfermode::Create(gModes[i].fMode);
SkAutoUnref aur(mode);
SkRect r;
r.set(x, y, x+w, y+h);
@ -174,7 +172,8 @@ protected:
canvas->drawRect(r, p);
canvas->saveLayer(&r, nullptr);
draw_mode(canvas, mode, twice ? 0x88 : 0xFF, r.fLeft, r.fTop);
draw_mode(canvas, SkXfermode::Make(gModes[i].fMode),
twice ? 0x88 : 0xFF, r.fLeft, r.fTop);
canvas->restore();
r.inset(-SK_ScalarHalf, -SK_ScalarHalf);

View File

@ -132,7 +132,7 @@ public:
// To implement the old shadeSpan entry-point, we need to efficiently convert our native
// floats into SkPMColor. The SkXfermode::D32Procs do exactly that.
//
sk_sp<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kSrc_Mode));
sk_sp<SkXfermode> xfer(SkXfermode::Make(SkXfermode::kSrc_Mode));
fXferProc = SkXfermode::GetD32Proc(xfer.get(), 0);
}

View File

@ -481,7 +481,7 @@ public:
*/
SkPaint tmp;
tmp.setImageFilter(fPaint->getImageFilter());
tmp.setXfermode(fPaint->getXfermode());
tmp.setXfermode(sk_ref_sp(fPaint->getXfermode()));
SkRect storage;
if (rawBounds) {
// Make rawBounds include all paint outsets except for those due to image filters.

View File

@ -16,19 +16,6 @@
///////////////////////////////////////////////////////////////////////////////
SkComposeShader::SkComposeShader(sk_sp<SkShader> sA, sk_sp<SkShader> sB, SkXfermode* mode)
: fShaderA(std::move(sA))
, fShaderB(std::move(sB))
{
// mode may be null
fMode = mode;
SkSafeRef(mode);
}
SkComposeShader::~SkComposeShader() {
SkSafeUnref(fMode);
}
size_t SkComposeShader::onContextSize(const ContextRec& rec) const {
return sizeof(ComposeShaderContext)
+ fShaderA->contextSize(rec)
@ -55,17 +42,17 @@ private:
SkFlattenable* SkComposeShader::CreateProc(SkReadBuffer& buffer) {
sk_sp<SkShader> shaderA(buffer.readShader());
sk_sp<SkShader> shaderB(buffer.readShader());
SkAutoTUnref<SkXfermode> mode(buffer.readXfermode());
sk_sp<SkXfermode> mode(buffer.readXfermode());
if (!shaderA || !shaderB) {
return nullptr;
}
return new SkComposeShader(std::move(shaderA), std::move(shaderB), mode);
return new SkComposeShader(std::move(shaderA), std::move(shaderB), std::move(mode));
}
void SkComposeShader::flatten(SkWriteBuffer& buffer) const {
buffer.writeFlattenable(fShaderA.get());
buffer.writeFlattenable(fShaderB.get());
buffer.writeFlattenable(fMode);
buffer.writeFlattenable(fMode.get());
}
template <typename T> void safe_call_destructor(T* obj) {
@ -120,7 +107,7 @@ bool SkComposeShader::asACompose(ComposeRec* rec) const {
if (rec) {
rec->fShaderA = fShaderA.get();
rec->fShaderB = fShaderB.get();
rec->fMode = fMode;
rec->fMode = fMode.get();
}
return true;
}
@ -133,7 +120,7 @@ bool SkComposeShader::asACompose(ComposeRec* rec) const {
void SkComposeShader::ComposeShaderContext::shadeSpan(int x, int y, SkPMColor result[], int count) {
SkShader::Context* shaderContextA = fShaderContextA;
SkShader::Context* shaderContextB = fShaderContextB;
SkXfermode* mode = static_cast<const SkComposeShader&>(fShader).fMode;
SkXfermode* mode = static_cast<const SkComposeShader&>(fShader).fMode.get();
unsigned scale = SkAlpha255To256(this->getPaintAlpha());
SkPMColor tmp[TMP_COLOR_COUNT];
@ -255,15 +242,14 @@ void SkComposeShader::toString(SkString* str) const {
///////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<SkShader> SkShader::MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader> src,
SkXfermode* xfer) {
sk_sp<SkXfermode> xfer) {
if (!dst || !src) {
return nullptr;
}
return sk_make_sp<SkComposeShader>(std::move(dst), std::move(src), xfer);
return sk_make_sp<SkComposeShader>(std::move(dst), std::move(src), std::move(xfer));
}
sk_sp<SkShader> SkShader::MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader> src,
SkXfermode::Mode mode) {
SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode));
return MakeComposeShader(std::move(dst), std::move(src), xfer);
return MakeComposeShader(std::move(dst), std::move(src), SkXfermode::Make(mode));
}

View File

@ -5,13 +5,11 @@
* found in the LICENSE file.
*/
#ifndef SkComposeShader_DEFINED
#define SkComposeShader_DEFINED
#include "SkShader.h"
class SkXfermode;
#include "SkXfermode.h"
///////////////////////////////////////////////////////////////////////////////////////////
@ -30,8 +28,11 @@ public:
@param mode The xfermode that combines the colors from the two shaders. If mode
is null, then SRC_OVER is assumed.
*/
SkComposeShader(sk_sp<SkShader> sA, sk_sp<SkShader> sB, SkXfermode* mode = NULL);
virtual ~SkComposeShader();
SkComposeShader(sk_sp<SkShader> sA, sk_sp<SkShader> sB, sk_sp<SkXfermode> mode)
: fShaderA(std::move(sA))
, fShaderB(std::move(sB))
, fMode(std::move(mode))
{}
#if SK_SUPPORT_GPU
const GrFragmentProcessor* asFragmentProcessor(GrContext*,
@ -72,15 +73,15 @@ public:
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeShader)
protected:
SkComposeShader(SkReadBuffer& );
SkComposeShader(SkReadBuffer&);
void flatten(SkWriteBuffer&) const override;
size_t onContextSize(const ContextRec&) const override;
Context* onCreateContext(const ContextRec&, void*) const override;
private:
sk_sp<SkShader> fShaderA;
sk_sp<SkShader> fShaderB;
SkXfermode* fMode;
sk_sp<SkShader> fShaderA;
sk_sp<SkShader> fShaderB;
sk_sp<SkXfermode> fMode;
typedef SkShader INHERITED;
};

View File

@ -32,6 +32,7 @@
#include "SkTLazy.h"
#include "SkUtils.h"
#include "SkVertState.h"
#include "SkXfermode.h"
#include "SkBitmapProcShader.h"
#include "SkDrawProcs.h"
@ -1900,15 +1901,9 @@ void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count,
} else {
// colors * texture
SkASSERT(shader);
bool releaseMode = false;
if (nullptr == xmode) {
xmode = SkXfermode::Create(SkXfermode::kModulate_Mode);
releaseMode = true;
}
p.setShader(sk_make_sp<SkComposeShader>(triShader, sk_ref_sp(shader), xmode));
if (releaseMode) {
xmode->unref();
}
sk_sp<SkXfermode> xfer = xmode ? sk_ref_sp(xmode)
: SkXfermode::Make(SkXfermode::kModulate_Mode);
p.setShader(SkShader::MakeComposeShader(triShader, sk_ref_sp(shader), std::move(xfer)));
}
}

View File

@ -380,7 +380,9 @@ SET_PTR(Shader)
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
SET_PTR(ColorFilter)
#endif
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
SET_PTR(Xfermode)
#endif
#ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
SET_PTR(PathEffect)
#endif
@ -395,8 +397,8 @@ SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) {
#endif
SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) {
fXfermode.reset(SkXfermode::Create(mode));
return fXfermode.get();
fXfermode = SkXfermode::Make(mode);
return fXfermode.get(); // can/should we change this API to be void, like the other setters?
}
///////////////////////////////////////////////////////////////////////////////
@ -1927,7 +1929,7 @@ void SkPaint::unflatten(SkReadBuffer& buffer) {
if (flatFlags & kHasEffects_FlatFlag) {
this->setPathEffect(buffer.readPathEffect());
this->setShader(buffer.readShader());
SkSafeUnref(this->setXfermode(buffer.readXfermode()));
this->setXfermode(buffer.readXfermode());
SkSafeUnref(this->setMaskFilter(buffer.readMaskFilter()));
this->setColorFilter(buffer.readColorFilter());
this->setRasterizer(buffer.readRasterizer());

View File

@ -307,15 +307,15 @@ void SkPicturePlayback::handleOp(SkReader32* reader,
texCoords = (const SkPoint*)reader->skip(SkPatchUtils::kNumCorners *
sizeof(SkPoint));
}
SkAutoTUnref<SkXfermode> xfer;
sk_sp<SkXfermode> xfer;
if (flag & DRAW_VERTICES_HAS_XFER) {
int mode = reader->readInt();
if (mode < 0 || mode > SkXfermode::kLastMode) {
mode = SkXfermode::kModulate_Mode;
}
xfer.reset(SkXfermode::Create((SkXfermode::Mode)mode));
xfer = SkXfermode::Make((SkXfermode::Mode)mode);
}
canvas->drawPatch(cubics, colors, texCoords, xfer, paint);
canvas->drawPatch(cubics, colors, texCoords, std::move(xfer), paint);
} break;
case DRAW_PATH: {
const SkPaint& paint = *fPictureData->getPaint(reader);
@ -435,7 +435,7 @@ void SkPicturePlayback::handleOp(SkReader32* reader,
canvas->drawTextOnPath(text.text(), text.length(), path, &matrix, paint);
} break;
case DRAW_VERTICES: {
SkAutoTUnref<SkXfermode> xfer;
sk_sp<SkXfermode> xfer;
const SkPaint& paint = *fPictureData->getPaint(reader);
DrawVertexFlags flags = (DrawVertexFlags)reader->readInt();
SkCanvas::VertexMode vmode = (SkCanvas::VertexMode)reader->readInt();
@ -460,7 +460,7 @@ void SkPicturePlayback::handleOp(SkReader32* reader,
if (mode < 0 || mode > SkXfermode::kLastMode) {
mode = SkXfermode::kModulate_Mode;
}
xfer.reset(SkXfermode::Create((SkXfermode::Mode)mode));
xfer = SkXfermode::Make((SkXfermode::Mode)mode);
}
canvas->drawVertices(vmode, vCount, verts, texs, colors, xfer, indices, iCount, paint);
} break;

View File

@ -145,7 +145,9 @@ public:
return sk_sp<SkRasterizer>(this->readFlattenable<SkRasterizer>());
}
sk_sp<SkShader> readShader() { return sk_sp<SkShader>(this->readFlattenable<SkShader>()); }
SkXfermode* readXfermode() { return this->readFlattenable<SkXfermode>(); }
sk_sp<SkXfermode> readXfermode() {
return sk_sp<SkXfermode>(this->readFlattenable<SkXfermode>());
}
/**
* Like readFlattenable() but explicitly just skips the data that was written for the

View File

@ -453,3 +453,11 @@ SkShader* SkShader::newWithColorFilter(SkColorFilter* filter) const {
return this->makeWithColorFilter(sk_ref_sp(filter)).release();
}
#endif
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
#include "SkXfermode.h"
sk_sp<SkShader> SkShader::MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader> src,
SkXfermode* xfer) {
return MakeComposeShader(std::move(dst), std::move(src), sk_ref_sp(xfer));
}
#endif

View File

@ -1097,7 +1097,7 @@ SkFlattenable* SkProcCoeffXfermode::CreateProc(SkReadBuffer& buffer) {
if (!buffer.validate(mode32 < SK_ARRAY_COUNT(gProcCoeffs))) {
return nullptr;
}
return SkXfermode::Create((SkXfermode::Mode)mode32);
return SkXfermode::Make((SkXfermode::Mode)mode32).release();
}
void SkProcCoeffXfermode::flatten(SkWriteBuffer& buffer) const {
@ -1305,7 +1305,7 @@ void SkProcCoeffXfermode::toString(SkString* str) const {
SK_DECLARE_STATIC_ONCE_PTR(SkXfermode, cached[SkXfermode::kLastMode + 1]);
SkXfermode* SkXfermode::Create(Mode mode) {
sk_sp<SkXfermode> SkXfermode::Make(Mode mode) {
SkASSERT(SK_ARRAY_COUNT(gProcCoeffs) == kModeCount);
if ((unsigned)mode >= kModeCount) {
@ -1319,7 +1319,7 @@ SkXfermode* SkXfermode::Create(Mode mode) {
return nullptr;
}
return SkSafeRef(cached[mode].get([=]{
return sk_ref_sp(cached[mode].get([=]{
ProcCoeff rec = gProcCoeffs[mode];
if (auto xfermode = SkOpts::create_xfermode(rec, mode)) {
return xfermode;

View File

@ -60,7 +60,7 @@ SkFlattenable* SkArithmeticMode_scalar::CreateProc(SkReadBuffer& buffer) {
const SkScalar k3 = buffer.readScalar();
const SkScalar k4 = buffer.readScalar();
const bool enforcePMColor = buffer.readBool();
return SkArithmeticMode::Create(k1, k2, k3, k4, enforcePMColor);
return SkArithmeticMode::Make(k1, k2, k3, k4, enforcePMColor).release();
}
static int pinToByte(int value) {
@ -137,18 +137,16 @@ void SkArithmeticMode_scalar::toString(SkString* str) const {
///////////////////////////////////////////////////////////////////////////////
SkXfermode* SkArithmeticMode::Create(SkScalar k1, SkScalar k2,
SkScalar k3, SkScalar k4,
bool enforcePMColor) {
sk_sp<SkXfermode> SkArithmeticMode::Make(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4,
bool enforcePMColor) {
if (SkScalarNearlyZero(k1) && SkScalarNearlyEqual(k2, SK_Scalar1) &&
SkScalarNearlyZero(k3) && SkScalarNearlyZero(k4)) {
return SkXfermode::Create(SkXfermode::kSrc_Mode);
return SkXfermode::Make(SkXfermode::kSrc_Mode);
} else if (SkScalarNearlyZero(k1) && SkScalarNearlyZero(k2) &&
SkScalarNearlyEqual(k3, SK_Scalar1) && SkScalarNearlyZero(k4)) {
return SkXfermode::Create(SkXfermode::kDst_Mode);
return SkXfermode::Make(SkXfermode::kDst_Mode);
}
return new SkArithmeticMode_scalar(k1, k2, k3, k4, enforcePMColor);
return sk_make_sp<SkArithmeticMode_scalar>(k1, k2, k3, k4, enforcePMColor);
}

View File

@ -25,7 +25,7 @@ SkFlattenable* SkAvoidXfermode::CreateProc(SkReadBuffer& buffer) {
const SkColor color = buffer.readColor();
const unsigned tolerance = buffer.readUInt();
const unsigned mode = buffer.readUInt();
return Create(color, tolerance, (Mode)mode);
return Make(color, tolerance, (Mode)mode).release();
}
void SkAvoidXfermode::flatten(SkWriteBuffer& buffer) const {

View File

@ -104,7 +104,7 @@ void SkLayerDrawLooper::LayerDrawLooperContext::ApplyInfo(
dst->setColorFilter(sk_ref_sp(src.getColorFilter()));
}
if (bits & kXfermode_Bit) {
dst->setXfermode(src.getXfermode());
dst->setXfermode(sk_ref_sp(src.getXfermode()));
}
// we don't override these

View File

@ -27,7 +27,7 @@ void SkPixelXorXfermode::flatten(SkWriteBuffer& wb) const {
}
SkFlattenable* SkPixelXorXfermode::CreateProc(SkReadBuffer& buffer) {
return Create(buffer.readColor());
return Make(buffer.readColor()).release();
}
#ifndef SK_IGNORE_TO_STRING

View File

@ -23,22 +23,30 @@
///////////////////////////////////////////////////////////////////////////////
SkXfermodeImageFilter::SkXfermodeImageFilter(SkXfermode* mode,
sk_sp<SkImageFilter> SkXfermodeImageFilter::Make(sk_sp<SkXfermode> mode, SkImageFilter* background,
SkImageFilter* foreground,
const CropRect* cropRect) {
SkImageFilter* inputs[2] = { background, foreground };
return sk_sp<SkImageFilter>(new SkXfermodeImageFilter(mode, inputs, cropRect));
}
SkXfermodeImageFilter::SkXfermodeImageFilter(sk_sp<SkXfermode> mode,
SkImageFilter* inputs[2],
const CropRect* cropRect)
: INHERITED(2, inputs, cropRect)
, fMode(SkSafeRef(mode)) {
}
, fMode(std::move(mode))
{}
SkFlattenable* SkXfermodeImageFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 2);
SkAutoTUnref<SkXfermode> mode(buffer.readXfermode());
return Create(mode, common.getInput(0), common.getInput(1), &common.cropRect());
sk_sp<SkXfermode> mode(buffer.readXfermode());
return Make(std::move(mode), common.getInput(0),
common.getInput(1), &common.cropRect()).release();
}
void SkXfermodeImageFilter::flatten(SkWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
buffer.writeFlattenable(fMode);
buffer.writeFlattenable(fMode.get());
}
bool SkXfermodeImageFilter::onFilterImageDeprecated(Proxy* proxy,

View File

@ -105,17 +105,13 @@ void GrSWMaskHelper::draw(const SkRect& rect, SkRegion::Op op,
bool antiAlias, uint8_t alpha) {
SkPaint paint;
SkXfermode* mode = SkXfermode::Create(op_to_mode(op));
SkASSERT(kNone_CompressionMode == fCompressionMode);
paint.setXfermode(mode);
paint.setXfermode(SkXfermode::Make(op_to_mode(op)));
paint.setAntiAlias(antiAlias);
paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha));
fDraw.drawRect(rect, paint);
SkSafeUnref(mode);
}
/**

View File

@ -1098,7 +1098,7 @@ static int lpaint_getXfermode(lua_State* L) {
static int lpaint_setXfermode(lua_State* L) {
SkPaint* paint = get_obj<SkPaint>(L, 1);
paint->setXfermode(get_ref<SkXfermode>(L, 2));
paint->setXfermode(sk_ref_sp(get_ref<SkXfermode>(L, 2)));
return 0;
}

View File

@ -80,7 +80,7 @@ DEF_TEST(Blend_premul_begets_premul, r) {
if (mode == SkXfermode::kSrcOver_Mode) {
return; // TODO: can't create a SrcOver xfermode.
}
SkAutoTUnref<SkXfermode> xfermode(SkXfermode::Create(mode));
auto xfermode(SkXfermode::Make(mode));
SkASSERT(xfermode);
// We'll test all alphas and legal color values, assuming all colors work the same.
// This is not true for non-separable blend modes, but this test still can't hurt.

View File

@ -31,7 +31,7 @@ DEF_TEST(GrGetCoeffBlendKnownComponents, reporter) {
SkRandom random;
for (int i = 0; i < SkXfermode::kLastCoeffMode; ++i) {
SkXfermode::Mode mode = (SkXfermode::Mode)i;
SkAutoTUnref<SkXfermode> xm(SkXfermode::Create(mode));
auto xm(SkXfermode::Make(mode));
SkXfermode::Coeff srcCoeff, dstCoeff;
SkAssertResult(SkXfermode::ModeAsCoeff(mode, &srcCoeff, &dstCoeff));
for (int j = 0; j < 1000; ++j) {
@ -44,7 +44,7 @@ DEF_TEST(GrGetCoeffBlendKnownComponents, reporter) {
src, kRGBA_GrColorComponentFlags,
dst, kRGBA_GrColorComponentFlags,
&outColor, &outFlags);
GrColor baselineColor = make_baseline_color(src, dst, xm);
GrColor baselineColor = make_baseline_color(src, dst, xm.get());
if (SkAbs32(GrColorUnpackA(baselineColor) - GrColorUnpackA(outColor)) > 1 ||
SkAbs32(GrColorUnpackR(baselineColor) - GrColorUnpackR(outColor)) > 1 ||
SkAbs32(GrColorUnpackG(baselineColor) - GrColorUnpackG(outColor)) > 1 ||

View File

@ -191,8 +191,8 @@ public:
five, five, pictureFilter.get(), cropRect));
this->addFilter("paint and blur", SkBlurImageFilter::Create(
five, five, paintFilter.get(), cropRect));
this->addFilter("xfermode", SkXfermodeImageFilter::Create(
SkXfermode::Create(SkXfermode::kSrc_Mode), input, input, cropRect));
this->addFilter("xfermode", SkXfermodeImageFilter::Make(
SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect).release());
}
int count() const { return fFilters.count(); }
SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.get(); }
@ -799,16 +799,15 @@ DEF_TEST(ImageFilterUnionBounds, reporter) {
// Regardless of which order they appear in, the image filter bounds should
// be combined correctly.
{
SkAutoTUnref<SkImageFilter> composite(SkXfermodeImageFilter::Create(
nullptr, offset.get(), nullptr));
sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, offset.get()));
SkRect bounds = SkRect::MakeWH(100, 100);
// Intentionally aliasing here, as that's what the real callers do.
bounds = composite->computeFastBounds(bounds);
REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100));
}
{
SkAutoTUnref<SkImageFilter> composite(SkXfermodeImageFilter::Create(
nullptr, nullptr, offset.get()));
sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, nullptr,
offset.get(), nullptr));
SkRect bounds = SkRect::MakeWH(100, 100);
// Intentionally aliasing here, as that's what the real callers do.
bounds = composite->computeFastBounds(bounds);
@ -1249,13 +1248,10 @@ static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* re
// Check that an xfermode image filter whose input has been cropped out still draws the other
// input. Also check that drawing with both inputs cropped out doesn't cause a GPU warning.
SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrcOver_Mode);
SkAutoTUnref<SkImageFilter> xfermodeNoFg(
SkXfermodeImageFilter::Create(mode, greenFilter, croppedOut));
SkAutoTUnref<SkImageFilter> xfermodeNoBg(
SkXfermodeImageFilter::Create(mode, croppedOut, greenFilter));
SkAutoTUnref<SkImageFilter> xfermodeNoFgNoBg(
SkXfermodeImageFilter::Create(mode, croppedOut, croppedOut));
auto mode = SkXfermode::Make(SkXfermode::kSrcOver_Mode);
auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode, greenFilter, croppedOut, nullptr));
auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, greenFilter, nullptr));
auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, croppedOut, nullptr));
SkPaint paint;
paint.setImageFilter(xfermodeNoFg);

View File

@ -292,7 +292,7 @@ DEF_TEST(Paint_MoreFlattening, r) {
paint.setColor(0x00AABBCC);
paint.setTextScaleX(1.0f); // Default value, ignored.
paint.setTextSize(19);
paint.setXfermode(SkXfermode::Create(SkXfermode::kModulate_Mode))->unref();
paint.setXfermode(SkXfermode::Make(SkXfermode::kModulate_Mode));
paint.setLooper(nullptr); // Default value, ignored.
SkWriteBuffer writer;

View File

@ -246,13 +246,13 @@ static void TestBitmapSerialization(const SkBitmap& validBitmap,
SkAutoTUnref<SkImageFilter> validBitmapSource(SkImageSource::Create(validImage.get()));
sk_sp<SkImage> invalidImage(SkImage::MakeFromBitmap(invalidBitmap));
SkAutoTUnref<SkImageFilter> invalidBitmapSource(SkImageSource::Create(invalidImage.get()));
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
SkAutoTUnref<SkImageFilter> xfermodeImageFilter(
SkXfermodeImageFilter::Create(mode, invalidBitmapSource, validBitmapSource));
sk_sp<SkImageFilter> xfermodeImageFilter(
SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kSrcOver_Mode),
invalidBitmapSource, validBitmapSource, nullptr));
SkAutoTUnref<SkImageFilter> deserializedFilter(
TestFlattenableSerialization<SkImageFilter>(
xfermodeImageFilter, shouldSucceed, reporter));
xfermodeImageFilter.get(), shouldSucceed, reporter));
// Try to render a small bitmap using the invalid deserialized filter
// to make sure we don't crash while trying to render it
@ -274,8 +274,8 @@ static void TestXfermodeSerialization(skiatest::Reporter* reporter) {
// skip SrcOver, as it is allowed to return nullptr from Create()
continue;
}
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(static_cast<SkXfermode::Mode>(i)));
REPORTER_ASSERT(reporter, mode.get());
auto mode(SkXfermode::Make(static_cast<SkXfermode::Mode>(i)));
REPORTER_ASSERT(reporter, mode);
SkAutoTUnref<SkXfermode> copy(
TestFlattenableSerialization<SkXfermode>(mode.get(), true, reporter));
}

View File

@ -13,7 +13,7 @@
static void test_asMode(skiatest::Reporter* reporter) {
for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) {
SkXfermode* xfer = SkXfermode::Create((SkXfermode::Mode) mode);
auto xfer = SkXfermode::Make((SkXfermode::Mode) mode);
SkXfermode::Mode reportedMode = ILLEGAL_MODE;
REPORTER_ASSERT(reporter, reportedMode != mode);
@ -27,7 +27,6 @@ static void test_asMode(skiatest::Reporter* reporter) {
reportedMode = (SkXfermode::Mode) -1;
REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode));
REPORTER_ASSERT(reporter, reportedMode == mode);
xfer->unref();
} else {
REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode);
}
@ -41,9 +40,8 @@ static void test_IsMode(skiatest::Reporter* reporter) {
for (int i = 0; i <= SkXfermode::kLastMode; ++i) {
SkXfermode::Mode mode = (SkXfermode::Mode)i;
SkXfermode* xfer = SkXfermode::Create(mode);
auto xfer = SkXfermode::Make(mode);
REPORTER_ASSERT(reporter, SkXfermode::IsMode(xfer, mode));
SkSafeUnref(xfer);
if (SkXfermode::kSrcOver_Mode != mode) {
REPORTER_ASSERT(reporter, !SkXfermode::IsMode(nullptr, mode));

View File

@ -33,7 +33,7 @@ public:
bool overrideFilterQuality,
SkFilterQuality quality)
: INHERITED(width, height)
, fOverdrawXfermode(overdrawViz ? SkOverdrawMode::Create() : nullptr)
, fOverdrawXfermode(overdrawViz ? SkOverdrawMode::Make() : nullptr)
, fOverrideFilterQuality(overrideFilterQuality)
, fFilterQuality(quality) {}
@ -42,7 +42,7 @@ protected:
if (*paint) {
if (nullptr != fOverdrawXfermode.get()) {
paint->writable()->setAntiAlias(false);
paint->writable()->setXfermode(fOverdrawXfermode.get());
paint->writable()->setXfermode(fOverdrawXfermode);
}
if (fOverrideFilterQuality) {
@ -60,7 +60,7 @@ protected:
}
private:
SkAutoTUnref<SkXfermode> fOverdrawXfermode;
sk_sp<SkXfermode> fOverdrawXfermode;
bool fOverrideFilterQuality;
SkFilterQuality fFilterQuality;

View File

@ -1169,10 +1169,9 @@ static void extract_json_paint_xfermode(Json::Value& jsonPaint, UrlDataManager&
SkPaint* target) {
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_XFERMODE)) {
Json::Value jsonXfermode = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_XFERMODE];
SkXfermode* xfermode = (SkXfermode*) load_flattenable(jsonXfermode, urlDataManager);
sk_sp<SkXfermode> xfermode((SkXfermode*) load_flattenable(jsonXfermode, urlDataManager));
if (xfermode != nullptr) {
target->setXfermode(xfermode);
xfermode->unref();
}
}
}

View File

@ -317,7 +317,7 @@ SkFlattenable* SkOverdrawXfermode::CreateProc(SkReadBuffer& buffer) {
return Create();
}
SkXfermode* SkOverdrawMode::Create() { return new SkOverdrawXfermode; }
sk_sp<SkXfermode> SkOverdrawMode::Make() { return sk_make_sp<SkOverdrawXfermode>(); }
SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkOverdrawMode)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkOverdrawXfermode)

View File

@ -14,7 +14,7 @@ class SkXfermode;
class SkOverdrawMode {
public:
static SkXfermode* Create();
static sk_sp<SkXfermode> Make();
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP();