Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Unified Diff: src/core/SkPaint.cpp

Issue 1770723002: Add variants of the setters on SkPaint which take a sk_sp<effect> (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkPaint.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPaint.cpp
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index cdfb1104544eb15690ac5037057a570fcb3b4eb6..3d768074cad262bc64fe4c34569f8bdcd67666a9 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,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;
-}
-
-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 +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:
« no previous file with comments | « include/core/SkPaint.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698