Add variants of the setters on SkPaint which take a sk_sp<effect>. At the same time, change the internal storage to be sk_sp<effect>.
Follow-on CL might try to use = default for the constructors and assignment operators.
This reverts commit 992854d62e
.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1770723002
Review URL: https://codereview.chromium.org/1770723002
This commit is contained in:
parent
fcad44bbb1
commit
a5ab9ec295
@ -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; }
|
||||
SkShader* getShader() const { return fShader.get(); }
|
||||
|
||||
/** Set or clear the shader object.
|
||||
* Shaders specify the source color(s) for what is being drawn. If a paint
|
||||
@ -500,12 +500,13 @@ 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; }
|
||||
SkColorFilter* getColorFilter() const { return fColorFilter.get(); }
|
||||
|
||||
/** Set or clear the paint's colorfilter, returning the parameter.
|
||||
<p />
|
||||
@ -515,13 +516,14 @@ 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; }
|
||||
SkXfermode* getXfermode() const { return fXfermode.get(); }
|
||||
|
||||
/** Set or clear the xfermode object.
|
||||
<p />
|
||||
@ -534,6 +536,7 @@ 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
|
||||
@ -546,7 +549,7 @@ public:
|
||||
The patheffect reference count is not affected.
|
||||
@return the paint's patheffect (or NULL)
|
||||
*/
|
||||
SkPathEffect* getPathEffect() const { return fPathEffect; }
|
||||
SkPathEffect* getPathEffect() const { return fPathEffect.get(); }
|
||||
|
||||
/** Set or clear the patheffect object.
|
||||
<p />
|
||||
@ -559,13 +562,14 @@ 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; }
|
||||
SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); }
|
||||
|
||||
/** Set or clear the maskfilter object.
|
||||
<p />
|
||||
@ -578,6 +582,7 @@ public:
|
||||
@return maskfilter
|
||||
*/
|
||||
SkMaskFilter* setMaskFilter(SkMaskFilter* maskfilter);
|
||||
void setMaskFilter(sk_sp<SkMaskFilter>);
|
||||
|
||||
// These attributes are for text/fonts
|
||||
|
||||
@ -587,7 +592,7 @@ public:
|
||||
measuring text. The typeface reference count is not affected.
|
||||
@return the paint's typeface (or NULL)
|
||||
*/
|
||||
SkTypeface* getTypeface() const { return fTypeface; }
|
||||
SkTypeface* getTypeface() const { return fTypeface.get(); }
|
||||
|
||||
/** Set or clear the typeface object.
|
||||
<p />
|
||||
@ -600,13 +605,14 @@ 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; }
|
||||
SkRasterizer* getRasterizer() const { return fRasterizer.get(); }
|
||||
|
||||
/** Set or clear the rasterizer object.
|
||||
<p />
|
||||
@ -620,15 +626,17 @@ public:
|
||||
@return rasterizer
|
||||
*/
|
||||
SkRasterizer* setRasterizer(SkRasterizer* rasterizer);
|
||||
void setRasterizer(sk_sp<SkRasterizer>);
|
||||
|
||||
SkImageFilter* getImageFilter() const { return fImageFilter; }
|
||||
SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
|
||||
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; }
|
||||
SkDrawLooper* getLooper() const { return fLooper.get(); }
|
||||
|
||||
/**
|
||||
* Set or clear the looper object.
|
||||
@ -642,6 +650,7 @@ public:
|
||||
* @return looper
|
||||
*/
|
||||
SkDrawLooper* setLooper(SkDrawLooper* looper);
|
||||
void setLooper(sk_sp<SkDrawLooper>);
|
||||
|
||||
enum Align {
|
||||
kLeft_Align,
|
||||
@ -1026,15 +1035,15 @@ public:
|
||||
SK_TO_STRING_NONVIRT()
|
||||
|
||||
private:
|
||||
SkTypeface* fTypeface;
|
||||
SkPathEffect* fPathEffect;
|
||||
SkShader* fShader;
|
||||
SkXfermode* fXfermode;
|
||||
SkMaskFilter* fMaskFilter;
|
||||
SkColorFilter* fColorFilter;
|
||||
SkRasterizer* fRasterizer;
|
||||
SkDrawLooper* fLooper;
|
||||
SkImageFilter* fImageFilter;
|
||||
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;
|
||||
|
||||
SkScalar fTextSize;
|
||||
SkScalar fTextScaleX;
|
||||
|
@ -44,16 +44,6 @@ 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;
|
||||
@ -72,46 +62,38 @@ SkPaint::SkPaint() {
|
||||
fBitfields.fHinting = SkPaintDefaults_Hinting;
|
||||
}
|
||||
|
||||
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);
|
||||
COPY(fColor);
|
||||
COPY(fWidth);
|
||||
COPY(fMiterLimit);
|
||||
COPY(fBitfields);
|
||||
|
||||
SkPaint::SkPaint(const SkPaint& src)
|
||||
#define COPY(field) field(src.field)
|
||||
: COPY(fTypeface)
|
||||
, COPY(fPathEffect)
|
||||
, COPY(fShader)
|
||||
, COPY(fXfermode)
|
||||
, COPY(fMaskFilter)
|
||||
, COPY(fColorFilter)
|
||||
, COPY(fRasterizer)
|
||||
, COPY(fLooper)
|
||||
, COPY(fImageFilter)
|
||||
, COPY(fTextSize)
|
||||
, COPY(fTextScaleX)
|
||||
, COPY(fTextSkewX)
|
||||
, COPY(fColor)
|
||||
, COPY(fWidth)
|
||||
, COPY(fMiterLimit)
|
||||
, COPY(fBitfields)
|
||||
#undef COPY
|
||||
#undef REF_COPY
|
||||
}
|
||||
{}
|
||||
|
||||
SkPaint::SkPaint(SkPaint&& src) {
|
||||
#define MOVE(field) field = std::move(src.field)
|
||||
#define REF_MOVE(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);
|
||||
@ -119,53 +101,36 @@ SkPaint::SkPaint(SkPaint&& src) {
|
||||
MOVE(fWidth);
|
||||
MOVE(fMiterLimit);
|
||||
MOVE(fBitfields);
|
||||
|
||||
#undef MOVE
|
||||
#undef REF_MOVE
|
||||
}
|
||||
|
||||
SkPaint::~SkPaint() {
|
||||
SkSafeUnref(fTypeface);
|
||||
SkSafeUnref(fPathEffect);
|
||||
SkSafeUnref(fShader);
|
||||
SkSafeUnref(fXfermode);
|
||||
SkSafeUnref(fMaskFilter);
|
||||
SkSafeUnref(fColorFilter);
|
||||
SkSafeUnref(fRasterizer);
|
||||
SkSafeUnref(fLooper);
|
||||
SkSafeUnref(fImageFilter);
|
||||
}
|
||||
SkPaint::~SkPaint() {}
|
||||
|
||||
SkPaint& SkPaint::operator=(const SkPaint& src) {
|
||||
if (this == &src) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
#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(fTextSize);
|
||||
COPY(fTextScaleX);
|
||||
COPY(fTextSkewX);
|
||||
COPY(fColor);
|
||||
COPY(fWidth);
|
||||
COPY(fMiterLimit);
|
||||
COPY(fBitfields);
|
||||
#define ASSIGN(field) field = src.field
|
||||
ASSIGN(fTypeface);
|
||||
ASSIGN(fPathEffect);
|
||||
ASSIGN(fShader);
|
||||
ASSIGN(fXfermode);
|
||||
ASSIGN(fMaskFilter);
|
||||
ASSIGN(fColorFilter);
|
||||
ASSIGN(fRasterizer);
|
||||
ASSIGN(fLooper);
|
||||
ASSIGN(fImageFilter);
|
||||
ASSIGN(fTextSize);
|
||||
ASSIGN(fTextScaleX);
|
||||
ASSIGN(fTextSkewX);
|
||||
ASSIGN(fColor);
|
||||
ASSIGN(fWidth);
|
||||
ASSIGN(fMiterLimit);
|
||||
ASSIGN(fBitfields);
|
||||
#undef ASSIGN
|
||||
|
||||
return *this;
|
||||
|
||||
#undef COPY
|
||||
#undef REF_COPY
|
||||
}
|
||||
|
||||
SkPaint& SkPaint::operator=(SkPaint&& src) {
|
||||
@ -174,18 +139,15 @@ 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);
|
||||
@ -193,11 +155,9 @@ SkPaint& SkPaint::operator=(SkPaint&& src) {
|
||||
MOVE(fWidth);
|
||||
MOVE(fMiterLimit);
|
||||
MOVE(fBitfields);
|
||||
#undef MOVE
|
||||
|
||||
return *this;
|
||||
|
||||
#undef MOVE
|
||||
#undef REF_MOVE
|
||||
}
|
||||
|
||||
bool operator==(const SkPaint& a, const SkPaint& b) {
|
||||
@ -392,24 +352,41 @@ void SkPaint::setTextEncoding(TextEncoding encoding) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkTypeface* SkPaint::setTypeface(SkTypeface* font) {
|
||||
SkRefCnt_SafeAssign(fTypeface, font);
|
||||
return font;
|
||||
}
|
||||
#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); }
|
||||
|
||||
SkRasterizer* SkPaint::setRasterizer(SkRasterizer* r) {
|
||||
SkRefCnt_SafeAssign(fRasterizer, r);
|
||||
return r;
|
||||
}
|
||||
#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
|
||||
|
||||
SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) {
|
||||
SkRefCnt_SafeAssign(fLooper, looper);
|
||||
fLooper.reset(SkSafeRef(looper));
|
||||
return looper;
|
||||
}
|
||||
|
||||
SkImageFilter* SkPaint::setImageFilter(SkImageFilter* imageFilter) {
|
||||
SkRefCnt_SafeAssign(fImageFilter, imageFilter);
|
||||
return imageFilter;
|
||||
SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) {
|
||||
fXfermode.reset(SkXfermode::Create(mode));
|
||||
return fXfermode.get();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -1726,7 +1703,7 @@ void SkPaint::descriptorProc(const SkSurfaceProps* surfaceProps,
|
||||
test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize);
|
||||
#endif
|
||||
|
||||
proc(fTypeface, desc, context);
|
||||
proc(fTypeface.get(), desc, context);
|
||||
}
|
||||
|
||||
SkGlyphCache* SkPaint::detachCache(const SkSurfaceProps* surfaceProps,
|
||||
@ -1983,39 +1960,6 @@ 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);
|
||||
@ -2393,7 +2337,7 @@ bool SkPaint::nothingToDraw() const {
|
||||
return false;
|
||||
}
|
||||
SkXfermode::Mode mode;
|
||||
if (SkXfermode::AsMode(fXfermode, &mode)) {
|
||||
if (SkXfermode::AsMode(fXfermode.get(), &mode)) {
|
||||
switch (mode) {
|
||||
case SkXfermode::kSrcOver_Mode:
|
||||
case SkXfermode::kSrcATop_Mode:
|
||||
@ -2401,7 +2345,7 @@ bool SkPaint::nothingToDraw() const {
|
||||
case SkXfermode::kDstOver_Mode:
|
||||
case SkXfermode::kPlus_Mode:
|
||||
if (0 == this->getAlpha()) {
|
||||
return !affects_alpha(fColorFilter) && !affects_alpha(fImageFilter);
|
||||
return !affects_alpha(fColorFilter.get()) && !affects_alpha(fImageFilter.get());
|
||||
}
|
||||
break;
|
||||
case SkXfermode::kDst_Mode:
|
||||
|
Loading…
Reference in New Issue
Block a user