Index: src/core/SkPaint.cpp |
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp |
index cdfb1104544eb15690ac5037057a570fcb3b4eb6..6b20629f79e96304a9c5ca317700fdad0dbbab00 100644 |
--- a/src/core/SkPaint.cpp |
+++ b/src/core/SkPaint.cpp |
@@ -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,20 +62,19 @@ SkPaint::SkPaint() { |
fBitfields.fHinting = SkPaintDefaults_Hinting; |
} |
-SkPaint::SkPaint(const SkPaint& src) { |
+SkPaint::SkPaint(const SkPaint& src) |
+#define COPY_CTR(field) field(src.field) |
bungeman-skia
2016/03/06 04:50:05
Note that for simplicity and uniformity, COPY_CTR
reed1
2016/03/06 20:06:17
Agreed about unity. I think CTR is clearer (to me)
|
+ : 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) |
+{ |
#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); |
@@ -95,7 +84,7 @@ SkPaint::SkPaint(const SkPaint& src) { |
COPY(fBitfields); |
#undef COPY |
-#undef REF_COPY |
+#undef COPY_CTR |
} |
SkPaint::SkPaint(SkPaint&& src) { |
@@ -124,17 +113,7 @@ SkPaint::SkPaint(SkPaint&& src) { |
#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) { |
@@ -142,18 +121,16 @@ 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); |
@@ -165,7 +142,6 @@ SkPaint& SkPaint::operator=(const SkPaint& src) { |
return *this; |
#undef COPY |
-#undef REF_COPY |
} |
SkPaint& SkPaint::operator=(SkPaint&& src) { |
@@ -174,18 +150,16 @@ 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); |
@@ -197,7 +171,6 @@ SkPaint& SkPaint::operator=(SkPaint&& src) { |
return *this; |
#undef MOVE |
-#undef REF_MOVE |
} |
bool operator==(const SkPaint& a, const SkPaint& b) { |
@@ -392,24 +365,41 @@ void SkPaint::setTextEncoding(TextEncoding encoding) { |
/////////////////////////////////////////////////////////////////////////////// |
-SkTypeface* SkPaint::setTypeface(SkTypeface* font) { |
- SkRefCnt_SafeAssign(fTypeface, font); |
- return font; |
-} |
- |
-SkRasterizer* SkPaint::setRasterizer(SkRasterizer* r) { |
- SkRefCnt_SafeAssign(fRasterizer, r); |
- return r; |
-} |
+#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); } |
+ |
+#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 +1716,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 +1973,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 +2350,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 +2358,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: |