Revert of add setter on SkPaint that takes sk_sp (patchset #1 id:1 of https://codereview.chromium.org/1769803002/ )
Reason for revert: investigate leak Original issue's description: > add setter on SkPaint that takes sk_sp > > BUG=skia: > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1769803002 > > TBR= > > Committed: https://skia.googlesource.com/skia/+/a917eba6ea8a6936f2c9271e487b14d14b99c98e TBR= # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/1771613002
This commit is contained in:
parent
a917eba6ea
commit
992854d62e
@ -476,7 +476,7 @@ public:
|
||||
The shader's reference count is not affected.
|
||||
@return the paint's shader (or NULL)
|
||||
*/
|
||||
SkShader* getShader() const { return fShader.get(); }
|
||||
SkShader* getShader() const { return fShader; }
|
||||
|
||||
/** Set or clear the shader object.
|
||||
* Shaders specify the source color(s) for what is being drawn. If a paint
|
||||
@ -500,13 +500,12 @@ public:
|
||||
* @return shader
|
||||
*/
|
||||
SkShader* setShader(SkShader* shader);
|
||||
void setShader(sk_sp<SkShader>);
|
||||
|
||||
/** Get the paint's colorfilter. If there is a colorfilter, its reference
|
||||
count is not changed.
|
||||
@return the paint's colorfilter (or NULL)
|
||||
*/
|
||||
SkColorFilter* getColorFilter() const { return fColorFilter.get(); }
|
||||
SkColorFilter* getColorFilter() const { return fColorFilter; }
|
||||
|
||||
/** Set or clear the paint's colorfilter, returning the parameter.
|
||||
<p />
|
||||
@ -516,14 +515,13 @@ public:
|
||||
@return filter
|
||||
*/
|
||||
SkColorFilter* setColorFilter(SkColorFilter* filter);
|
||||
void setColorFilter(sk_sp<SkColorFilter>);
|
||||
|
||||
/** Get the paint's xfermode object.
|
||||
<p />
|
||||
The xfermode's reference count is not affected.
|
||||
@return the paint's xfermode (or NULL)
|
||||
*/
|
||||
SkXfermode* getXfermode() const { return fXfermode.get(); }
|
||||
SkXfermode* getXfermode() const { return fXfermode; }
|
||||
|
||||
/** Set or clear the xfermode object.
|
||||
<p />
|
||||
@ -536,7 +534,6 @@ public:
|
||||
@return xfermode
|
||||
*/
|
||||
SkXfermode* setXfermode(SkXfermode* xfermode);
|
||||
void setXfermode(sk_sp<SkXfermode>);
|
||||
|
||||
/** 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
|
||||
@ -549,7 +546,7 @@ public:
|
||||
The patheffect reference count is not affected.
|
||||
@return the paint's patheffect (or NULL)
|
||||
*/
|
||||
SkPathEffect* getPathEffect() const { return fPathEffect.get(); }
|
||||
SkPathEffect* getPathEffect() const { return fPathEffect; }
|
||||
|
||||
/** Set or clear the patheffect object.
|
||||
<p />
|
||||
@ -562,14 +559,13 @@ public:
|
||||
@return effect
|
||||
*/
|
||||
SkPathEffect* setPathEffect(SkPathEffect* effect);
|
||||
void setPathEffect(sk_sp<SkPathEffect>);
|
||||
|
||||
/** Get the paint's maskfilter object.
|
||||
<p />
|
||||
The maskfilter reference count is not affected.
|
||||
@return the paint's maskfilter (or NULL)
|
||||
*/
|
||||
SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); }
|
||||
SkMaskFilter* getMaskFilter() const { return fMaskFilter; }
|
||||
|
||||
/** Set or clear the maskfilter object.
|
||||
<p />
|
||||
@ -582,7 +578,6 @@ public:
|
||||
@return maskfilter
|
||||
*/
|
||||
SkMaskFilter* setMaskFilter(SkMaskFilter* maskfilter);
|
||||
void setMaskFilter(sk_sp<SkMaskFilter>);
|
||||
|
||||
// These attributes are for text/fonts
|
||||
|
||||
@ -592,7 +587,7 @@ public:
|
||||
measuring text. The typeface reference count is not affected.
|
||||
@return the paint's typeface (or NULL)
|
||||
*/
|
||||
SkTypeface* getTypeface() const { return fTypeface.get(); }
|
||||
SkTypeface* getTypeface() const { return fTypeface; }
|
||||
|
||||
/** Set or clear the typeface object.
|
||||
<p />
|
||||
@ -605,14 +600,13 @@ public:
|
||||
@return typeface
|
||||
*/
|
||||
SkTypeface* setTypeface(SkTypeface* typeface);
|
||||
void setTypeface(sk_sp<SkTypeface>);
|
||||
|
||||
/** Get the paint's rasterizer (or NULL).
|
||||
<p />
|
||||
The raster controls how paths/text are turned into alpha masks.
|
||||
@return the paint's rasterizer (or NULL)
|
||||
*/
|
||||
SkRasterizer* getRasterizer() const { return fRasterizer.get(); }
|
||||
SkRasterizer* getRasterizer() const { return fRasterizer; }
|
||||
|
||||
/** Set or clear the rasterizer object.
|
||||
<p />
|
||||
@ -626,17 +620,15 @@ public:
|
||||
@return rasterizer
|
||||
*/
|
||||
SkRasterizer* setRasterizer(SkRasterizer* rasterizer);
|
||||
void setRasterizer(sk_sp<SkRasterizer>);
|
||||
|
||||
SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
|
||||
SkImageFilter* getImageFilter() const { return fImageFilter; }
|
||||
SkImageFilter* setImageFilter(SkImageFilter*);
|
||||
void setImageFilter(sk_sp<SkImageFilter>);
|
||||
|
||||
/**
|
||||
* Return the paint's SkDrawLooper (if any). Does not affect the looper's
|
||||
* reference count.
|
||||
*/
|
||||
SkDrawLooper* getLooper() const { return fLooper.get(); }
|
||||
SkDrawLooper* getLooper() const { return fLooper; }
|
||||
|
||||
/**
|
||||
* Set or clear the looper object.
|
||||
@ -650,7 +642,6 @@ public:
|
||||
* @return looper
|
||||
*/
|
||||
SkDrawLooper* setLooper(SkDrawLooper* looper);
|
||||
void setLooper(sk_sp<SkDrawLooper>);
|
||||
|
||||
enum Align {
|
||||
kLeft_Align,
|
||||
@ -1035,15 +1026,15 @@ public:
|
||||
SK_TO_STRING_NONVIRT()
|
||||
|
||||
private:
|
||||
sk_sp<SkTypeface> fTypeface;
|
||||
sk_sp<SkPathEffect> fPathEffect;
|
||||
sk_sp<SkShader> fShader;
|
||||
sk_sp<SkXfermode> fXfermode;
|
||||
sk_sp<SkMaskFilter> fMaskFilter;
|
||||
sk_sp<SkColorFilter> fColorFilter;
|
||||
sk_sp<SkRasterizer> fRasterizer;
|
||||
sk_sp<SkDrawLooper> fLooper;
|
||||
sk_sp<SkImageFilter> fImageFilter;
|
||||
SkTypeface* fTypeface;
|
||||
SkPathEffect* fPathEffect;
|
||||
SkShader* fShader;
|
||||
SkXfermode* fXfermode;
|
||||
SkMaskFilter* fMaskFilter;
|
||||
SkColorFilter* fColorFilter;
|
||||
SkRasterizer* fRasterizer;
|
||||
SkDrawLooper* fLooper;
|
||||
SkImageFilter* fImageFilter;
|
||||
|
||||
SkScalar fTextSize;
|
||||
SkScalar fTextScaleX;
|
||||
|
@ -44,6 +44,16 @@ static inline uint32_t set_clear_mask(uint32_t bits, bool cond, uint32_t mask) {
|
||||
//#define SK_REPORT_API_RANGE_CHECK
|
||||
|
||||
SkPaint::SkPaint() {
|
||||
fTypeface = nullptr;
|
||||
fPathEffect = nullptr;
|
||||
fShader = nullptr;
|
||||
fXfermode = nullptr;
|
||||
fMaskFilter = nullptr;
|
||||
fColorFilter = nullptr;
|
||||
fRasterizer = nullptr;
|
||||
fLooper = nullptr;
|
||||
fImageFilter = nullptr;
|
||||
|
||||
fTextSize = SkPaintDefaults_TextSize;
|
||||
fTextScaleX = SK_Scalar1;
|
||||
fTextSkewX = 0;
|
||||
@ -62,19 +72,20 @@ SkPaint::SkPaint() {
|
||||
fBitfields.fHinting = SkPaintDefaults_Hinting;
|
||||
}
|
||||
|
||||
SkPaint::SkPaint(const SkPaint& src)
|
||||
#define COPY_CTR(field) field(src.field)
|
||||
: COPY_CTR(fTypeface)
|
||||
, COPY_CTR(fPathEffect)
|
||||
, COPY_CTR(fShader)
|
||||
, COPY_CTR(fXfermode)
|
||||
, COPY_CTR(fMaskFilter)
|
||||
, COPY_CTR(fColorFilter)
|
||||
, COPY_CTR(fRasterizer)
|
||||
, COPY_CTR(fLooper)
|
||||
, COPY_CTR(fImageFilter)
|
||||
{
|
||||
SkPaint::SkPaint(const SkPaint& src) {
|
||||
#define COPY(field) field = src.field
|
||||
#define REF_COPY(field) field = SkSafeRef(src.field)
|
||||
|
||||
REF_COPY(fTypeface);
|
||||
REF_COPY(fPathEffect);
|
||||
REF_COPY(fShader);
|
||||
REF_COPY(fXfermode);
|
||||
REF_COPY(fMaskFilter);
|
||||
REF_COPY(fColorFilter);
|
||||
REF_COPY(fRasterizer);
|
||||
REF_COPY(fLooper);
|
||||
REF_COPY(fImageFilter);
|
||||
|
||||
COPY(fTextSize);
|
||||
COPY(fTextScaleX);
|
||||
COPY(fTextSkewX);
|
||||
@ -84,7 +95,7 @@ SkPaint::SkPaint(const SkPaint& src)
|
||||
COPY(fBitfields);
|
||||
|
||||
#undef COPY
|
||||
#undef COPY_CTR
|
||||
#undef REF_COPY
|
||||
}
|
||||
|
||||
SkPaint::SkPaint(SkPaint&& src) {
|
||||
@ -113,7 +124,17 @@ SkPaint::SkPaint(SkPaint&& src) {
|
||||
#undef REF_MOVE
|
||||
}
|
||||
|
||||
SkPaint::~SkPaint() {}
|
||||
SkPaint::~SkPaint() {
|
||||
SkSafeUnref(fTypeface);
|
||||
SkSafeUnref(fPathEffect);
|
||||
SkSafeUnref(fShader);
|
||||
SkSafeUnref(fXfermode);
|
||||
SkSafeUnref(fMaskFilter);
|
||||
SkSafeUnref(fColorFilter);
|
||||
SkSafeUnref(fRasterizer);
|
||||
SkSafeUnref(fLooper);
|
||||
SkSafeUnref(fImageFilter);
|
||||
}
|
||||
|
||||
SkPaint& SkPaint::operator=(const SkPaint& src) {
|
||||
if (this == &src) {
|
||||
@ -121,16 +142,18 @@ SkPaint& SkPaint::operator=(const SkPaint& src) {
|
||||
}
|
||||
|
||||
#define COPY(field) field = src.field
|
||||
#define REF_COPY(field) SkSafeUnref(field); field = SkSafeRef(src.field)
|
||||
|
||||
REF_COPY(fTypeface);
|
||||
REF_COPY(fPathEffect);
|
||||
REF_COPY(fShader);
|
||||
REF_COPY(fXfermode);
|
||||
REF_COPY(fMaskFilter);
|
||||
REF_COPY(fColorFilter);
|
||||
REF_COPY(fRasterizer);
|
||||
REF_COPY(fLooper);
|
||||
REF_COPY(fImageFilter);
|
||||
|
||||
COPY(fTypeface);
|
||||
COPY(fPathEffect);
|
||||
COPY(fShader);
|
||||
COPY(fXfermode);
|
||||
COPY(fMaskFilter);
|
||||
COPY(fColorFilter);
|
||||
COPY(fRasterizer);
|
||||
COPY(fLooper);
|
||||
COPY(fImageFilter);
|
||||
COPY(fTextSize);
|
||||
COPY(fTextScaleX);
|
||||
COPY(fTextSkewX);
|
||||
@ -142,6 +165,7 @@ SkPaint& SkPaint::operator=(const SkPaint& src) {
|
||||
return *this;
|
||||
|
||||
#undef COPY
|
||||
#undef REF_COPY
|
||||
}
|
||||
|
||||
SkPaint& SkPaint::operator=(SkPaint&& src) {
|
||||
@ -150,16 +174,18 @@ SkPaint& SkPaint::operator=(SkPaint&& src) {
|
||||
}
|
||||
|
||||
#define MOVE(field) field = std::move(src.field)
|
||||
#define REF_MOVE(field) SkSafeUnref(field); field = src.field; src.field = nullptr
|
||||
|
||||
REF_MOVE(fTypeface);
|
||||
REF_MOVE(fPathEffect);
|
||||
REF_MOVE(fShader);
|
||||
REF_MOVE(fXfermode);
|
||||
REF_MOVE(fMaskFilter);
|
||||
REF_MOVE(fColorFilter);
|
||||
REF_MOVE(fRasterizer);
|
||||
REF_MOVE(fLooper);
|
||||
REF_MOVE(fImageFilter);
|
||||
|
||||
MOVE(fTypeface);
|
||||
MOVE(fPathEffect);
|
||||
MOVE(fShader);
|
||||
MOVE(fXfermode);
|
||||
MOVE(fMaskFilter);
|
||||
MOVE(fColorFilter);
|
||||
MOVE(fRasterizer);
|
||||
MOVE(fLooper);
|
||||
MOVE(fImageFilter);
|
||||
MOVE(fTextSize);
|
||||
MOVE(fTextScaleX);
|
||||
MOVE(fTextSkewX);
|
||||
@ -171,6 +197,7 @@ SkPaint& SkPaint::operator=(SkPaint&& src) {
|
||||
return *this;
|
||||
|
||||
#undef MOVE
|
||||
#undef REF_MOVE
|
||||
}
|
||||
|
||||
bool operator==(const SkPaint& a, const SkPaint& b) {
|
||||
@ -365,41 +392,24 @@ void SkPaint::setTextEncoding(TextEncoding encoding) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define MOVE_FIELD(Field) void SkPaint::set##Field(sk_sp<Sk##Field> f) { f##Field = std::move(f); }
|
||||
MOVE_FIELD(Typeface)
|
||||
MOVE_FIELD(Rasterizer)
|
||||
MOVE_FIELD(ImageFilter)
|
||||
MOVE_FIELD(Shader)
|
||||
MOVE_FIELD(ColorFilter)
|
||||
MOVE_FIELD(Xfermode)
|
||||
MOVE_FIELD(PathEffect)
|
||||
MOVE_FIELD(MaskFilter)
|
||||
#undef MOVE_FIELD
|
||||
void SkPaint::setLooper(sk_sp<SkDrawLooper> looper) { fLooper = std::move(looper); }
|
||||
SkTypeface* SkPaint::setTypeface(SkTypeface* font) {
|
||||
SkRefCnt_SafeAssign(fTypeface, font);
|
||||
return font;
|
||||
}
|
||||
|
||||
#define SET_PTR(Field) \
|
||||
Sk##Field* SkPaint::set##Field(Sk##Field* f) { \
|
||||
this->f##Field.reset(SkSafeRef(f)); \
|
||||
return f; \
|
||||
}
|
||||
SET_PTR(Typeface)
|
||||
SET_PTR(Rasterizer)
|
||||
SET_PTR(ImageFilter)
|
||||
SET_PTR(Shader)
|
||||
SET_PTR(ColorFilter)
|
||||
SET_PTR(Xfermode)
|
||||
SET_PTR(PathEffect)
|
||||
SET_PTR(MaskFilter)
|
||||
#undef SET_PTR
|
||||
SkRasterizer* SkPaint::setRasterizer(SkRasterizer* r) {
|
||||
SkRefCnt_SafeAssign(fRasterizer, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) {
|
||||
fLooper.reset(SkSafeRef(looper));
|
||||
SkRefCnt_SafeAssign(fLooper, looper);
|
||||
return looper;
|
||||
}
|
||||
|
||||
SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) {
|
||||
fXfermode.reset(SkXfermode::Create(mode));
|
||||
return fXfermode.get();
|
||||
SkImageFilter* SkPaint::setImageFilter(SkImageFilter* imageFilter) {
|
||||
SkRefCnt_SafeAssign(fImageFilter, imageFilter);
|
||||
return imageFilter;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -1716,7 +1726,7 @@ void SkPaint::descriptorProc(const SkSurfaceProps* surfaceProps,
|
||||
test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize);
|
||||
#endif
|
||||
|
||||
proc(fTypeface.get(), desc, context);
|
||||
proc(fTypeface, desc, context);
|
||||
}
|
||||
|
||||
SkGlyphCache* SkPaint::detachCache(const SkSurfaceProps* surfaceProps,
|
||||
@ -1973,6 +1983,39 @@ void SkPaint::unflatten(SkReadBuffer& buffer) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkShader* SkPaint::setShader(SkShader* shader) {
|
||||
SkRefCnt_SafeAssign(fShader, shader);
|
||||
return shader;
|
||||
}
|
||||
|
||||
SkColorFilter* SkPaint::setColorFilter(SkColorFilter* filter) {
|
||||
SkRefCnt_SafeAssign(fColorFilter, filter);
|
||||
return filter;
|
||||
}
|
||||
|
||||
SkXfermode* SkPaint::setXfermode(SkXfermode* mode) {
|
||||
SkRefCnt_SafeAssign(fXfermode, mode);
|
||||
return mode;
|
||||
}
|
||||
|
||||
SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) {
|
||||
SkSafeUnref(fXfermode);
|
||||
fXfermode = SkXfermode::Create(mode);
|
||||
return fXfermode;
|
||||
}
|
||||
|
||||
SkPathEffect* SkPaint::setPathEffect(SkPathEffect* effect) {
|
||||
SkRefCnt_SafeAssign(fPathEffect, effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
SkMaskFilter* SkPaint::setMaskFilter(SkMaskFilter* filter) {
|
||||
SkRefCnt_SafeAssign(fMaskFilter, filter);
|
||||
return filter;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool SkPaint::getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect,
|
||||
SkScalar resScale) const {
|
||||
SkStrokeRec rec(*this, resScale);
|
||||
@ -2350,7 +2393,7 @@ bool SkPaint::nothingToDraw() const {
|
||||
return false;
|
||||
}
|
||||
SkXfermode::Mode mode;
|
||||
if (SkXfermode::AsMode(fXfermode.get(), &mode)) {
|
||||
if (SkXfermode::AsMode(fXfermode, &mode)) {
|
||||
switch (mode) {
|
||||
case SkXfermode::kSrcOver_Mode:
|
||||
case SkXfermode::kSrcATop_Mode:
|
||||
@ -2358,7 +2401,7 @@ bool SkPaint::nothingToDraw() const {
|
||||
case SkXfermode::kDstOver_Mode:
|
||||
case SkXfermode::kPlus_Mode:
|
||||
if (0 == this->getAlpha()) {
|
||||
return !affects_alpha(fColorFilter.get()) && !affects_alpha(fImageFilter.get());
|
||||
return !affects_alpha(fColorFilter) && !affects_alpha(fImageFilter);
|
||||
}
|
||||
break;
|
||||
case SkXfermode::kDst_Mode:
|
||||
|
Loading…
Reference in New Issue
Block a user