dullPaint.setAntiAlias(true);
SkPaint loopedPaint;
- loopedPaint.setLooper(looperBuilder.detachLooper())->unref();
+ loopedPaint.setLooper(looperBuilder.detach());
loopedPaint.setAntiAlias(true);
loopedPaint.setColor(SK_ColorCYAN);
SkScalar translate = 2.0f * size;
SkPaint paint;
- paint.setLooper(this->createLooper(-translate, blurSigma))->unref();
+ paint.setLooper(this->createLooper(-translate, blurSigma));
paint.setColor(0xff000000 | Random.nextU());
paint.setAntiAlias(true);
H = 480,
};
- SkLayerDrawLooper* createLooper(SkScalar xOff, SkScalar sigma) {
+ sk_sp<SkDrawLooper> createLooper(SkScalar xOff, SkScalar sigma) {
SkLayerDrawLooper::Builder looperBuilder;
//-----------------------------------------------
info.fOffset.set(0, 0);
paint = looperBuilder.addLayer(info);
- return looperBuilder.detachLooper();
+ return looperBuilder.detach();
}
typedef Benchmark INHERITED;
SkPaint paint;
canvas->drawRect(fRRect.rect(), paint);
- paint.setLooper(looperBuilder.detachLooper())->unref();
+ paint.setLooper(looperBuilder.detach());
paint.setColor(SK_ColorCYAN);
paint.setAntiAlias(true);
// AA with blur
SkPaint p;
p.setAntiAlias(true);
- SkDrawLooper* shadowLooper =
- SkBlurDrawLooper::Create(SK_ColorBLUE,
+ p.setLooper(SkBlurDrawLooper::Make(SK_ColorBLUE,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
SkIntToScalar(5), SkIntToScalar(10),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag |
- SkBlurDrawLooper::kHighQuality_BlurFlag);
- SkAutoUnref aurL0(shadowLooper);
- p.setLooper(shadowLooper);
+ SkBlurDrawLooper::kHighQuality_BlurFlag));
fPaints.push_back(p);
}
this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
}
- virtual ~DrawLooperGM() {
- SkSafeUnref(fLooper);
- }
-
protected:
virtual SkISize onISize() override {
return SkISize::Make(520, 160);
}
private:
- SkLayerDrawLooper* fLooper;
+ sk_sp<SkDrawLooper> fLooper;
void init() {
if (fLooper) return;
paint->setMaskFilter(mf)->unref();
}
}
- fLooper = looperBuilder.detachLooper();
+ fLooper = looperBuilder.detach();
}
typedef GM INHERITED;
for (int i = 0; i < 4; ++i) {
SkPaint loopPaint;
- loopPaint.setLooper(create1Looper(-kOffsetToOutsideClip, 0, gColors[i]))->unref();
+ loopPaint.setLooper(create1Looper(-kOffsetToOutsideClip, 0, gColors[i]));
loopPaint.setAntiAlias(true);
SkRect outerClip = {
}
// Create a 1-tier drawlooper
- SkLayerDrawLooper* create1Looper(SkScalar xOff, SkScalar yOff, SkColor color) {
+ sk_sp<SkDrawLooper> create1Looper(SkScalar xOff, SkScalar yOff, SkColor color) {
SkLayerDrawLooper::Builder looperBuilder;
SkLayerDrawLooper::LayerInfo info;
SkColorFilter* cf = SkColorFilter::CreateModeFilter(color, SkXfermode::kSrcIn_Mode);
paint->setColorFilter(cf)->unref();
- return looperBuilder.detachLooper();
+ return looperBuilder.detach();
}
void draw1x4(SkCanvas* canvas, SkScalar x, SkScalar y) {
SkPaint paint;
paint.setAntiAlias(true);
- paint.setLooper(create4Looper(-kOffsetToOutsideClip-kHalfSquareSize, 0))->unref();
+ paint.setLooper(create4Looper(-kOffsetToOutsideClip-kHalfSquareSize, 0));
canvas->save();
canvas->clipRect(outerClip, SkRegion::kIntersect_Op);
}
// Create a 4-tier draw looper
- SkLayerDrawLooper* create4Looper(SkScalar xOff, SkScalar yOff) {
+ sk_sp<SkDrawLooper> create4Looper(SkScalar xOff, SkScalar yOff) {
SkLayerDrawLooper::Builder looperBuilder;
SkLayerDrawLooper::LayerInfo info;
paint->setColorFilter(cf)->unref();
}
- return looperBuilder.detachLooper();
+ return looperBuilder.detach();
}
typedef GM INHERITED;
SkPaint p;
p.setColor(SK_ColorWHITE);
p.setAntiAlias(true);
- SkDrawLooper* shadowLooper =
- SkBlurDrawLooper::Create(SK_ColorWHITE,
+ p.setLooper(SkBlurDrawLooper::Make(SK_ColorWHITE,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
SkIntToScalar(5), SkIntToScalar(10),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag |
- SkBlurDrawLooper::kHighQuality_BlurFlag);
- SkAutoUnref aurL0(shadowLooper);
- p.setLooper(shadowLooper);
+ SkBlurDrawLooper::kHighQuality_BlurFlag));
fPaints.push_back(p);
}
}
void onDraw(SkCanvas* canvas) override {
- SkDrawLooper* shadowLoopers[5];
- shadowLoopers[0] =
- SkBlurDrawLooper::Create(SK_ColorBLUE,
+ sk_sp<SkDrawLooper> shadowLoopers[] = {
+ SkBlurDrawLooper::Make(SK_ColorBLUE,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
SkIntToScalar(5), SkIntToScalar(10),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag |
- SkBlurDrawLooper::kHighQuality_BlurFlag);
- SkAutoUnref aurL0(shadowLoopers[0]);
- shadowLoopers[1] =
- SkBlurDrawLooper::Create(SK_ColorBLUE,
+ SkBlurDrawLooper::kHighQuality_BlurFlag),
+ SkBlurDrawLooper::Make(SK_ColorBLUE,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
SkIntToScalar(5), SkIntToScalar(10),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
- SkBlurDrawLooper::kOverrideColor_BlurFlag);
- SkAutoUnref aurL1(shadowLoopers[1]);
- shadowLoopers[2] =
- SkBlurDrawLooper::Create(SK_ColorBLACK,
+ SkBlurDrawLooper::kOverrideColor_BlurFlag),
+ SkBlurDrawLooper::Make(SK_ColorBLACK,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
SkIntToScalar(5),
SkIntToScalar(10),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
- SkBlurDrawLooper::kHighQuality_BlurFlag);
- SkAutoUnref aurL2(shadowLoopers[2]);
- shadowLoopers[3] =
- SkBlurDrawLooper::Create(0x7FFF0000,
+ SkBlurDrawLooper::kHighQuality_BlurFlag),
+ SkBlurDrawLooper::Make(0x7FFF0000,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
SkIntToScalar(-5), SkIntToScalar(-10),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag |
- SkBlurDrawLooper::kHighQuality_BlurFlag);
- SkAutoUnref aurL3(shadowLoopers[3]);
- shadowLoopers[4] =
- SkBlurDrawLooper::Create(SK_ColorBLACK, SkIntToScalar(0),
+ SkBlurDrawLooper::kHighQuality_BlurFlag),
+ SkBlurDrawLooper::Make(SK_ColorBLACK, SkIntToScalar(0),
SkIntToScalar(5), SkIntToScalar(5),
SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
SkBlurDrawLooper::kOverrideColor_BlurFlag |
- SkBlurDrawLooper::kHighQuality_BlurFlag);
- SkAutoUnref aurL4(shadowLoopers[4]);
+ SkBlurDrawLooper::kHighQuality_BlurFlag),
+ };
static const struct {
SkColor fColor;
}
-static SkLayerDrawLooper* setupLooper(SkLayerDrawLooper::BitFlags bits,
- LooperProc proc,
- const LooperSettings settings[],
- size_t size) {
+static sk_sp<SkDrawLooper> setupLooper(SkLayerDrawLooper::BitFlags bits,
+ LooperProc proc,
+ const LooperSettings settings[],
+ size_t size) {
SkLayerDrawLooper::Builder looperBuilder;
SkLayerDrawLooper::LayerInfo info;
(*proc)(paint);
}
}
- return looperBuilder.detachLooper();
+ return looperBuilder.detach();
}
class TextBlobLooperGM : public GM {
{ SkXfermode::kSrcOver_Mode, 0x50FF00FF, SkPaint::kFill_Style, 0, 20.f, 0, false },
};
- fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kMaskFilter_Bit |
- SkLayerDrawLooper::kXfermode_Bit |
- SkLayerDrawLooper::kStyle_Bit, &mask_filter,
- compound, SK_ARRAY_COUNT(compound)));
- fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kPathEffect_Bit |
- SkLayerDrawLooper::kXfermode_Bit, &path_effect,
- looperSandwhich, SK_ARRAY_COUNT(looperSandwhich)));
- fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kShader_Bit |
- SkLayerDrawLooper::kColorFilter_Bit |
- SkLayerDrawLooper::kXfermode_Bit, &color_filter,
- looperSandwhich, SK_ARRAY_COUNT(looperSandwhich)));
- fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kShader_Bit |
- SkLayerDrawLooper::kColorFilter_Bit |
- SkLayerDrawLooper::kXfermode_Bit, &color_filter,
- xfermode, SK_ARRAY_COUNT(xfermode)));
- fLoopers.push_back().reset(setupLooper(0, nullptr, skew, SK_ARRAY_COUNT(skew)));
- fLoopers.push_back().reset(setupLooper(SkLayerDrawLooper::kMaskFilter_Bit |
- SkLayerDrawLooper::kShader_Bit |
- SkLayerDrawLooper::kColorFilter_Bit |
- SkLayerDrawLooper::kPathEffect_Bit |
- SkLayerDrawLooper::kStyle_Bit |
- SkLayerDrawLooper::kXfermode_Bit, &kitchen_sink,
- kitchenSink, SK_ARRAY_COUNT(kitchenSink)));
+ fLoopers.push_back(setupLooper(SkLayerDrawLooper::kMaskFilter_Bit |
+ SkLayerDrawLooper::kXfermode_Bit |
+ SkLayerDrawLooper::kStyle_Bit, &mask_filter,
+ compound, SK_ARRAY_COUNT(compound)));
+ fLoopers.push_back(setupLooper(SkLayerDrawLooper::kPathEffect_Bit |
+ SkLayerDrawLooper::kXfermode_Bit, &path_effect,
+ looperSandwhich, SK_ARRAY_COUNT(looperSandwhich)));
+ fLoopers.push_back(setupLooper(SkLayerDrawLooper::kShader_Bit |
+ SkLayerDrawLooper::kColorFilter_Bit |
+ SkLayerDrawLooper::kXfermode_Bit, &color_filter,
+ looperSandwhich, SK_ARRAY_COUNT(looperSandwhich)));
+ fLoopers.push_back(setupLooper(SkLayerDrawLooper::kShader_Bit |
+ SkLayerDrawLooper::kColorFilter_Bit |
+ SkLayerDrawLooper::kXfermode_Bit, &color_filter,
+ xfermode, SK_ARRAY_COUNT(xfermode)));
+ fLoopers.push_back(setupLooper(0, nullptr, skew, SK_ARRAY_COUNT(skew)));
+ fLoopers.push_back(setupLooper(SkLayerDrawLooper::kMaskFilter_Bit |
+ SkLayerDrawLooper::kShader_Bit |
+ SkLayerDrawLooper::kColorFilter_Bit |
+ SkLayerDrawLooper::kPathEffect_Bit |
+ SkLayerDrawLooper::kStyle_Bit |
+ SkLayerDrawLooper::kXfermode_Bit, &kitchen_sink,
+ kitchenSink, SK_ARRAY_COUNT(kitchenSink)));
// Test we respect overrides
- fLoopers.push_back().reset(setupLooper(0, &kitchen_sink,
- kitchenSink, SK_ARRAY_COUNT(kitchenSink)));
+ fLoopers.push_back(setupLooper(0, &kitchen_sink,
+ kitchenSink, SK_ARRAY_COUNT(kitchenSink)));
}
SkString onShortName() override {
private:
SkAutoTUnref<const SkTextBlob> fBlob;
- SkTArray<SkAutoTUnref<SkLayerDrawLooper>, true> fLoopers;
+ SkTArray<sk_sp<SkDrawLooper>, true> fLoopers;
typedef GM INHERITED;
};
p.setAntiAlias(false);
SkLayerRasterizer::Builder rastBuilder2;
r5(&rastBuilder2, p);
- p.setRasterizer(rastBuilder2.detachRasterizer())->unref();
+ p.setRasterizer(rastBuilder2.detach());
p.setXfermodeMode(SkXfermode::kClear_Mode);
rastBuilder->addLayer(p);
}
static void apply_shader(SkPaint* paint, int index) {
raster_proc proc = gRastProcs[index];
- if (proc)
- {
+ if (proc) {
SkPaint p;
SkLayerRasterizer::Builder rastBuilder;
p.setAntiAlias(true);
proc(&rastBuilder, p);
- paint->setRasterizer(rastBuilder.detachRasterizer())->unref();
+ paint->setRasterizer(rastBuilder.detach());
}
#if 0
# Needed until we fix https://bug.skia.org/2440 .
'SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG',
'SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS',
+ 'SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR',
'SK_SUPPORT_LEGACY_GRADIENT_DITHERING',
'SK_SUPPORT_LEGACY_DRAWFILTER',
'SK_SUPPORT_LEGACY_CREATESHADER_PTR',
the paint.
@return rasterizer
*/
+#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
SkRasterizer* setRasterizer(SkRasterizer* rasterizer);
+#endif
void setRasterizer(sk_sp<SkRasterizer>);
SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
* @param looper May be NULL. The new looper to be installed in the paint.
* @return looper
*/
+#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
SkDrawLooper* setLooper(SkDrawLooper* looper);
+#endif
void setLooper(sk_sp<SkDrawLooper>);
enum Align {
kAll_BlurFlag = 0x07
};
+ static sk_sp<SkDrawLooper> Make(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
+ uint32_t flags = kNone_BlurFlag) {
+ return sk_sp<SkDrawLooper>(new SkBlurDrawLooper(color, sigma, dx, dy, flags));
+ }
+#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
static SkDrawLooper* Create(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
uint32_t flags = kNone_BlurFlag) {
- return new SkBlurDrawLooper(color, sigma, dx, dy, flags);
+ return Make(color, sigma, dx, dy, flags).release();
}
+#endif
virtual ~SkBlurDrawLooper();
* Pass list of layers on to newly built looper and return it. This will
* also reset the builder, so it can be used to build another looper.
*/
- SkLayerDrawLooper* detachLooper();
+ sk_sp<SkDrawLooper> detach();
+#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
+ SkLayerDrawLooper* detachLooper() {
+ return (SkLayerDrawLooper*)this->detach().release();
+ }
+#endif
private:
Rec* fRecs;
-
/*
* Copyright 2006 The Android Open Source Project
*
* found in the LICENSE file.
*/
-
#ifndef SkLayerRasterizer_DEFINED
#define SkLayerRasterizer_DEFINED
*
* The caller is responsible for calling unref() on the returned object, if non NULL.
*/
- SkLayerRasterizer* detachRasterizer();
+ sk_sp<SkLayerRasterizer> detach();
/**
* Create and return a new immutable SkLayerRasterizer that contains a shapshot of the
*
* The caller is responsible for calling unref() on the returned object, if non NULL.
*/
- SkLayerRasterizer* snapshotRasterizer() const;
+ sk_sp<SkLayerRasterizer> snapshot() const;
+
+#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
+ SkLayerRasterizer* detachRasterizer() {
+ return this->detach().release();
+ }
+ SkLayerRasterizer* snapshotRasterizer() const {
+ return this->snapshot().release();
+ }
+#endif
private:
SkDeque* fLayers;
# Chrome DEFINES.
"SK_USE_FLOATBITS",
"SK_USE_FREETYPE_EMBOLDEN",
+ "SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR",
"SK_SUPPORT_LEGACY_PATHEFFECT_PTR",
# Turn on a few Google3-specific build fixes.
"GOOGLE3",
p.setAntiAlias(true);
r7(&rastBuilder, p, scale);
- paint->setRasterizer(rastBuilder.detachRasterizer())->unref();
+ paint->setRasterizer(rastBuilder.detach());
paint->setColor(SK_ColorBLUE);
}
p.setAntiAlias(false);
SkLayerRasterizer::Builder rastBuilder2;
r5(&rastBuilder2, p);
- p.setRasterizer(rastBuilder2.detachRasterizer())->unref();
+ p.setRasterizer(rastBuilder2.detach());
p.setXfermodeMode(SkXfermode::kClear_Mode);
rastBuilder->addLayer(p);
}
p.setAntiAlias(true);
proc(&rastBuilder, p);
- paint->setRasterizer(rastBuilder.detachRasterizer())->unref();
+ paint->setRasterizer(rastBuilder.detach());
}
#if 1
paintForRasterizer = make_paint();
}
rasterizerBuilder.addLayer(paintForRasterizer);
- SkAutoTUnref<SkRasterizer> rasterizer(rasterizerBuilder.detachRasterizer());
- paint.setRasterizer(rasterizer);
+ paint.setRasterizer(rasterizerBuilder.detach());
paint.setImageFilter(make_image_filter());
SkAutoDataUnref data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool()));
paint.setTextAlign(make_paint_align());
paint.setARGB(0xFF, 0, 0, 0);
paint.setPathEffect(make_warp_pe(fPhase));
TestRastBuilder testRastBuilder;
- paint.setRasterizer(testRastBuilder.detachRasterizer())->unref();
+ paint.setRasterizer(testRastBuilder.detach());
canvas->drawPath(fPath, paint);
}
p.setAntiAlias(false);
SkLayerRasterizer::Builder rastBuilder2;
r5(&rastBuilder2, p);
- p.setRasterizer(rastBuilder2.detachRasterizer())->unref();
+ p.setRasterizer(rastBuilder2.detach());
p.setXfermodeMode(SkXfermode::kClear_Mode);
rastBuilder->addLayer(p);
}
p.setAntiAlias(true);
proc(&rastBuilder, p);
- paint->setRasterizer(rastBuilder.detachRasterizer())->unref();
+ paint->setRasterizer(rastBuilder.detach());
paint->setColor(SK_ColorBLUE);
}
canvas->drawPath(path, paint);
- paint.setLooper(SkBlurDrawLooper::Create(SK_ColorBLACK,
- SkBlurMask::ConvertRadiusToSigma(0.002f),
- 0.0f,
- 0.0f))->unref();
+ paint.setLooper(SkBlurDrawLooper::Make(SK_ColorBLACK, SkBlurMask::ConvertRadiusToSigma(0.002f),
+ 0.0f, 0.0f));
const char* text = "DRAWING STROKED TEXT WITH A BLUR ON A PATH";
size_t len = strlen(text);
class TilingView : public SampleView {
sk_sp<SkPicture> fTextPicture;
- SkAutoTUnref<SkDrawLooper> fLooper;
+ sk_sp<SkDrawLooper> fLooper;
public:
TilingView()
- : fLooper(SkBlurDrawLooper::Create(0x88000000,
- SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)),
- SkIntToScalar(2), SkIntToScalar(2))) {
+ : fLooper(SkBlurDrawLooper::Make(0x88000000,
+ SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)),
+ SkIntToScalar(2), SkIntToScalar(2))) {
for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) {
makebm(&fTexture[i], gColorTypes[i], gWidth, gHeight);
}
SkPaint paint;
paint.setAntiAlias(true);
paint.setTextSize(SkIntToScalar(24));
- SkAutoTUnref<SkDrawLooper> looper(
- SkBlurDrawLooper::Create(SK_ColorBLUE,
- SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(2)),
- 0, 0));
+ auto looper(
+ SkBlurDrawLooper::Make(SK_ColorBLUE, SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(2)),
+ 0, 0));
paint.setLooper(looper);
SkScalar height = paint.getFontMetrics(nullptr);
if (!fDecodeSucceeded) {
return f; \
}
SET_PTR(Typeface)
+#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
SET_PTR(Rasterizer)
+#endif
SET_PTR(ImageFilter)
SET_PTR(Shader)
SET_PTR(ColorFilter)
SET_PTR(MaskFilter)
#undef SET_PTR
+#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) {
fLooper.reset(SkSafeRef(looper));
return looper;
}
+#endif
SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) {
fXfermode.reset(SkXfermode::Create(mode));
SkSafeUnref(this->setXfermode(buffer.readXfermode()));
SkSafeUnref(this->setMaskFilter(buffer.readMaskFilter()));
SkSafeUnref(this->setColorFilter(buffer.readColorFilter()));
- SkSafeUnref(this->setRasterizer(buffer.readRasterizer()));
- SkSafeUnref(this->setLooper(buffer.readDrawLooper()));
+ this->setRasterizer(buffer.readRasterizer());
+ this->setLooper(buffer.readDrawLooper());
SkSafeUnref(this->setImageFilter(buffer.readImageFilter()));
if (buffer.isVersionLT(SkReadBuffer::kAnnotationsMovedToCanvas_Version)) {
return (T*) this->readFlattenable(T::GetFlattenableType());
}
SkColorFilter* readColorFilter() { return this->readFlattenable<SkColorFilter>(); }
- SkDrawLooper* readDrawLooper() { return this->readFlattenable<SkDrawLooper>(); }
+ sk_sp<SkDrawLooper> readDrawLooper() {
+ return sk_sp<SkDrawLooper>(this->readFlattenable<SkDrawLooper>());
+ }
SkImageFilter* readImageFilter() { return this->readFlattenable<SkImageFilter>(); }
SkMaskFilter* readMaskFilter() { return this->readFlattenable<SkMaskFilter>(); }
sk_sp<SkPathEffect> readPathEffect() {
return sk_sp<SkPathEffect>(this->readFlattenable<SkPathEffect>());
}
- SkRasterizer* readRasterizer() { return this->readFlattenable<SkRasterizer>(); }
+ sk_sp<SkRasterizer> readRasterizer() {
+ return sk_sp<SkRasterizer>(this->readFlattenable<SkRasterizer>());
+ }
sk_sp<SkShader> readShader() { return sk_sp<SkShader>(this->readFlattenable<SkShader>()); }
SkXfermode* readXfermode() { return this->readFlattenable<SkXfermode>(); }
const SkScalar dx = buffer.readScalar();
const SkScalar dy = buffer.readScalar();
const uint32_t flags = buffer.read32();
- return Create(color, sigma, dx, dy, flags);
+ return Make(color, sigma, dx, dy, flags).release();
}
void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const {
info.fPostTranslate = buffer.readBool();
buffer.readPaint(builder.addLayerOnTop(info));
}
- return builder.detachLooper();
+ return builder.detach().release();
}
#ifndef SK_IGNORE_TO_STRING
return &rec->fPaint;
}
-SkLayerDrawLooper* SkLayerDrawLooper::Builder::detachLooper() {
+sk_sp<SkDrawLooper> SkLayerDrawLooper::Builder::detach() {
SkLayerDrawLooper* looper = new SkLayerDrawLooper;
looper->fCount = fCount;
looper->fRecs = fRecs;
fRecs = nullptr;
fTopRec = nullptr;
- return looper;
+ return sk_sp<SkDrawLooper>(looper);
}
rec->fOffset.set(dx, dy);
}
-SkLayerRasterizer* SkLayerRasterizer::Builder::detachRasterizer() {
+sk_sp<SkLayerRasterizer> SkLayerRasterizer::Builder::detach() {
SkLayerRasterizer* rasterizer;
if (0 == fLayers->count()) {
rasterizer = nullptr;
rasterizer = new SkLayerRasterizer(fLayers);
}
fLayers = nullptr;
- return rasterizer;
+ return sk_sp<SkLayerRasterizer>(rasterizer);
}
-SkLayerRasterizer* SkLayerRasterizer::Builder::snapshotRasterizer() const {
+sk_sp<SkLayerRasterizer> SkLayerRasterizer::Builder::snapshot() const {
if (0 == fLayers->count()) {
return nullptr;
}
}
SkASSERT(fLayers->count() == count);
SkASSERT(layers->count() == count);
- SkLayerRasterizer* rasterizer = new SkLayerRasterizer(layers);
- return rasterizer;
+ return sk_sp<SkLayerRasterizer>(new SkLayerRasterizer(layers));
}
const SkBlurQuality quality = blurMaskFilterFlags_as_quality(blurMaskFilterFlags);
uint32_t flags = blurMaskFilterFlags_to_blurDrawLooperFlags(blurMaskFilterFlags);
- SkAutoTUnref<SkDrawLooper> lp(SkBlurDrawLooper::Create(color, sigma, dx, dy, flags));
+ sk_sp<SkDrawLooper> lp(SkBlurDrawLooper::Make(color, sigma, dx, dy, flags));
const bool expectSuccess = sigma > 0 &&
0 == (flags & SkBlurDrawLooper::kIgnoreTransform_BlurFlag);
- if (nullptr == lp.get()) {
+ if (nullptr == lp) {
REPORTER_ASSERT(reporter, sigma <= 0);
} else {
SkDrawLooper::BlurShadowRec rec;
}
}
-static void test_delete_looper(skiatest::Reporter* reporter, SkDrawLooper* lp, SkScalar sigma,
- SkBlurStyle style, SkBlurQuality quality, bool expectSuccess) {
+static void test_looper(skiatest::Reporter* reporter, sk_sp<SkDrawLooper> lp, SkScalar sigma,
+ SkBlurStyle style, SkBlurQuality quality, bool expectSuccess) {
SkDrawLooper::BlurShadowRec rec;
bool success = lp->asABlurShadow(&rec);
REPORTER_ASSERT(reporter, success == expectSuccess);
REPORTER_ASSERT(reporter, rec.fStyle == style);
REPORTER_ASSERT(reporter, rec.fQuality == quality);
}
- lp->unref();
}
static void make_noop_layer(SkLayerDrawLooper::Builder* builder) {
// 1 layer is too few
make_noop_layer(&builder);
- test_delete_looper(reporter, builder.detachLooper(), sigma, style, quality, false);
+ test_looper(reporter, builder.detach(), sigma, style, quality, false);
// 2 layers is good, but need blur
make_noop_layer(&builder);
make_noop_layer(&builder);
- test_delete_looper(reporter, builder.detachLooper(), sigma, style, quality, false);
+ test_looper(reporter, builder.detach(), sigma, style, quality, false);
// 2 layers is just right
make_noop_layer(&builder);
make_blur_layer(&builder, mf);
- test_delete_looper(reporter, builder.detachLooper(), sigma, style, quality, expectSuccess);
+ test_looper(reporter, builder.detach(), sigma, style, quality, expectSuccess);
// 3 layers is too many
make_noop_layer(&builder);
make_blur_layer(&builder, mf);
make_noop_layer(&builder);
- test_delete_looper(reporter, builder.detachLooper(), sigma, style, quality, false);
+ test_looper(reporter, builder.detach(), sigma, style, quality, false);
}
DEF_TEST(BlurAsABlur, reporter) {
FakeDevice device;
SkCanvas canvas(&device);
SkPaint paint;
- SkAutoTUnref<SkLayerDrawLooper> looper(looperBuilder.detachLooper());
+ auto looper(looperBuilder.detach());
SkSmallAllocator<1, 32> allocator;
void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize());
SkDrawLooper::Context* context = looper->createContext(&canvas, buffer);
FakeDevice device;
SkCanvas canvas(&device);
SkPaint paint;
- SkAutoTUnref<SkLayerDrawLooper> looper(looperBuilder.detachLooper());
+ auto looper(looperBuilder.detach());
SkSmallAllocator<1, 32> allocator;
void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize());
SkDrawLooper::Context* context = looper->createContext(&canvas, buffer);
FakeDevice device;
SkCanvas canvas(&device);
SkPaint paint;
- SkAutoTUnref<SkLayerDrawLooper> looper(looperBuilder.detachLooper());
+ sk_sp<SkDrawLooper> looper(looperBuilder.detach());
SkSmallAllocator<1, 32> allocator;
void* buffer = allocator.reserveT<SkDrawLooper::Context>(looper->contextSize());
SkDrawLooper::Context* context = looper->createContext(&canvas, buffer);
DEF_TEST(LayerRasterizer_destructor, reporter) {
{
SkPaint paint;
- paint.setRasterizer(new DummyRasterizer)->unref();
+ paint.setRasterizer(sk_make_sp<DummyRasterizer>());
REPORTER_ASSERT(reporter, DummyRasterizer::GetCount() == 1);
SkLayerRasterizer::Builder builder;
DEF_TEST(LayerRasterizer_copy, reporter) {
SkLayerRasterizer::Builder builder;
- REPORTER_ASSERT(reporter, nullptr == builder.snapshotRasterizer());
+ REPORTER_ASSERT(reporter, nullptr == builder.snapshot());
SkPaint paint;
// Create a bunch of paints with different flags.
for (uint32_t flags = 0x01; flags < SkPaint::kAllFlags; flags <<= 1) {
}
// Create a layer rasterizer with all the existing layers.
- SkAutoTUnref<SkLayerRasterizer> firstCopy(builder.snapshotRasterizer());
+ sk_sp<SkLayerRasterizer> firstCopy(builder.snapshot());
// Add one more layer.
paint.setFlags(SkPaint::kAllFlags);
builder.addLayer(paint);
- SkAutoTUnref<SkLayerRasterizer> oneLarger(builder.snapshotRasterizer());
- SkAutoTUnref<SkLayerRasterizer> detached(builder.detachRasterizer());
+ sk_sp<SkLayerRasterizer> oneLarger(builder.snapshot());
+ sk_sp<SkLayerRasterizer> detached(builder.detach());
// Check the counts for consistency.
const int largerCount = LayerRasterizerTester::CountLayers(*oneLarger.get());
DEF_TEST(LayerRasterizer_detachEmpty, reporter) {
SkLayerRasterizer::Builder builder;
- REPORTER_ASSERT(reporter, nullptr == builder.detachRasterizer());
+ REPORTER_ASSERT(reporter, nullptr == builder.detach());
}
paint.setStrokeWidth(SkIntToScalar(2));
// set a few pointers
SkLayerDrawLooper::Builder looperBuilder;
- SkLayerDrawLooper* looper = looperBuilder.detachLooper();
- paint.setLooper(looper)->unref();
+ paint.setLooper(looperBuilder.detach());
SkMaskFilter* mask = SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)));
paint.setMaskFilter(mask)->unref();
// to the left. The test is to ensure that canvas' quickReject machinary
// allows us through, even though sans-looper we would look like we should
// be clipped out.
- paint.setLooper(new TestLooper)->unref();
+ paint.setLooper(sk_make_sp<TestLooper>());
canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint);
REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5));
}
#include "SkAndroidSDKCanvas.h"
#include "SkColorFilter.h"
+#include "SkDrawLooper.h"
#include "SkPaint.h"
#include "SkPathEffect.h"
#include "SkShader.h"
SkPaint* target) {
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_LOOPER)) {
Json::Value jsonLooper = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_LOOPER];
- SkDrawLooper* looper = (SkDrawLooper*) load_flattenable(jsonLooper, urlDataManager);
+ sk_sp<SkDrawLooper> looper((SkDrawLooper*) load_flattenable(jsonLooper, urlDataManager));
if (looper != nullptr) {
- target->setLooper(looper);
- looper->unref();
+ target->setLooper(std::move(looper));
}
}
}