diff options
Diffstat (limited to 'src/core/SkPaint.cpp')
-rw-r--r-- | src/core/SkPaint.cpp | 96 |
1 files changed, 39 insertions, 57 deletions
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 1c5065e8c9..9d76a169b3 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -52,7 +52,6 @@ SkPaint::SkPaint() { fColor = SK_ColorBLACK; fWidth = 0; fMiterLimit = SkPaintDefaults_MiterLimit; - fBlendMode = (unsigned)SkBlendMode::kSrcOver; // Zero all bitfields, then set some non-zero defaults. fBitfieldsUInt = 0; @@ -70,6 +69,7 @@ SkPaint::SkPaint(const SkPaint& src) : COPY(fTypeface) , COPY(fPathEffect) , COPY(fShader) + , COPY(fXfermode) , COPY(fMaskFilter) , COPY(fColorFilter) , COPY(fRasterizer) @@ -81,7 +81,6 @@ SkPaint::SkPaint(const SkPaint& src) , COPY(fColor) , COPY(fWidth) , COPY(fMiterLimit) - , COPY(fBlendMode) , COPY(fBitfields) #undef COPY {} @@ -91,6 +90,7 @@ SkPaint::SkPaint(SkPaint&& src) { MOVE(fTypeface); MOVE(fPathEffect); MOVE(fShader); + MOVE(fXfermode); MOVE(fMaskFilter); MOVE(fColorFilter); MOVE(fRasterizer); @@ -102,7 +102,6 @@ SkPaint::SkPaint(SkPaint&& src) { MOVE(fColor); MOVE(fWidth); MOVE(fMiterLimit); - MOVE(fBlendMode); MOVE(fBitfields); #undef MOVE } @@ -118,6 +117,7 @@ SkPaint& SkPaint::operator=(const SkPaint& src) { ASSIGN(fTypeface); ASSIGN(fPathEffect); ASSIGN(fShader); + ASSIGN(fXfermode); ASSIGN(fMaskFilter); ASSIGN(fColorFilter); ASSIGN(fRasterizer); @@ -129,7 +129,6 @@ SkPaint& SkPaint::operator=(const SkPaint& src) { ASSIGN(fColor); ASSIGN(fWidth); ASSIGN(fMiterLimit); - ASSIGN(fBlendMode); ASSIGN(fBitfields); #undef ASSIGN @@ -145,6 +144,7 @@ SkPaint& SkPaint::operator=(SkPaint&& src) { MOVE(fTypeface); MOVE(fPathEffect); MOVE(fShader); + MOVE(fXfermode); MOVE(fMaskFilter); MOVE(fColorFilter); MOVE(fRasterizer); @@ -156,7 +156,6 @@ SkPaint& SkPaint::operator=(SkPaint&& src) { MOVE(fColor); MOVE(fWidth); MOVE(fMiterLimit); - MOVE(fBlendMode); MOVE(fBitfields); #undef MOVE @@ -168,6 +167,7 @@ bool operator==(const SkPaint& a, const SkPaint& b) { return EQUAL(fTypeface) && EQUAL(fPathEffect) && EQUAL(fShader) + && EQUAL(fXfermode) && EQUAL(fMaskFilter) && EQUAL(fColorFilter) && EQUAL(fRasterizer) @@ -179,7 +179,6 @@ bool operator==(const SkPaint& a, const SkPaint& b) { && EQUAL(fColor) && EQUAL(fWidth) && EQUAL(fMiterLimit) - && EQUAL(fBlendMode) && EQUAL(fBitfieldsUInt) ; #undef EQUAL @@ -361,6 +360,7 @@ MOVE_FIELD(Rasterizer) MOVE_FIELD(ImageFilter) MOVE_FIELD(Shader) MOVE_FIELD(ColorFilter) +MOVE_FIELD(Xfermode) MOVE_FIELD(PathEffect) MOVE_FIELD(MaskFilter) MOVE_FIELD(DrawLooper) @@ -386,10 +386,7 @@ SET_PTR(Shader) SET_PTR(ColorFilter) #endif #ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR -SkXfermode* SkPaint::setXfermode(SkXfermode* xfer) { - this->setBlendMode(xfer ? xfer->blend() : SkBlendMode::kSrcOver); - return this->getXfermode(); -} +SET_PTR(Xfermode) #endif #ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR SET_PTR(PathEffect) @@ -406,18 +403,10 @@ SkDrawLooper* SkPaint::setLooper(SkDrawLooper* looper) { } #endif -#ifdef SK_SUPPORT_LEGACY_XFERMODE_OBJECT -void SkPaint::setXfermode(sk_sp<SkXfermode> mode) { - this->setBlendMode(mode ? mode->blend() : SkBlendMode::kSrcOver); -} -SkXfermode* SkPaint::getXfermode() const { - return SkXfermode::Peek((SkBlendMode)fBlendMode); -} SkXfermode* SkPaint::setXfermodeMode(SkXfermode::Mode mode) { - this->setBlendMode((SkBlendMode)mode); - return SkXfermode::Peek((SkBlendMode)mode); + fXfermode = SkXfermode::Make(mode); + return fXfermode.get(); // can/should we change this API to be void, like the other setters? } -#endif /////////////////////////////////////////////////////////////////////////////// @@ -1915,6 +1904,7 @@ void SkPaint::flatten(SkWriteBuffer& buffer) const { } if (asint(this->getPathEffect()) | asint(this->getShader()) | + asint(this->getXfermode()) | asint(this->getMaskFilter()) | asint(this->getColorFilter()) | asint(this->getRasterizer()) | @@ -1933,8 +1923,7 @@ void SkPaint::flatten(SkWriteBuffer& buffer) const { buffer.writeUInt(pack_paint_flags(this->getFlags(), this->getHinting(), this->getTextAlign(), this->getFilterQuality(), flatFlags)); buffer.writeUInt(pack_4(this->getStrokeCap(), this->getStrokeJoin(), - (this->getStyle() << 4) | this->getTextEncoding(), - fBlendMode)); + this->getStyle(), this->getTextEncoding())); // now we're done with ptr and the (pre)reserved space. If we need to write // additional fields, use the buffer directly @@ -1944,6 +1933,7 @@ void SkPaint::flatten(SkWriteBuffer& buffer) const { if (flatFlags & kHasEffects_FlatFlag) { buffer.writeFlattenable(this->getPathEffect()); buffer.writeFlattenable(this->getShader()); + buffer.writeFlattenable(this->getXfermode()); buffer.writeFlattenable(this->getMaskFilter()); buffer.writeFlattenable(this->getColorFilter()); buffer.writeFlattenable(this->getRasterizer()); @@ -1965,14 +1955,8 @@ void SkPaint::unflatten(SkReadBuffer& buffer) { uint32_t tmp = buffer.readUInt(); this->setStrokeCap(static_cast<Cap>((tmp >> 24) & 0xFF)); this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF)); - if (buffer.isVersionLT(SkReadBuffer::kXfermodeToBlendMode_Version)) { - this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF)); - this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF)); - } else { - this->setStyle(static_cast<Style>((tmp >> 12) & 0xF)); - this->setTextEncoding(static_cast<TextEncoding>((tmp >> 8) & 0xF)); - this->setBlendMode((SkBlendMode)(tmp & 0xFF)); - } + this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF)); + this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF)); if (flatFlags & kHasTypeface_FlatFlag) { this->setTypeface(buffer.readTypeface()); @@ -1983,16 +1967,7 @@ void SkPaint::unflatten(SkReadBuffer& buffer) { if (flatFlags & kHasEffects_FlatFlag) { this->setPathEffect(buffer.readPathEffect()); this->setShader(buffer.readShader()); - if (buffer.isVersionLT(SkReadBuffer::kXfermodeToBlendMode_Version)) { - sk_sp<SkXfermode> xfer = buffer.readXfermode(); - if (xfer) { - SkXfermode::Mode mode; - if (!xfer->asMode(&mode)) { - mode = SkXfermode::kSrcOver_Mode; - } - this->setBlendMode((SkBlendMode)mode); - } - } + this->setXfermode(buffer.readXfermode()); this->setMaskFilter(buffer.readMaskFilter()); this->setColorFilter(buffer.readColorFilter()); this->setRasterizer(buffer.readRasterizer()); @@ -2011,6 +1986,7 @@ void SkPaint::unflatten(SkReadBuffer& buffer) { } else { this->setPathEffect(nullptr); this->setShader(nullptr); + this->setXfermode(nullptr); this->setMaskFilter(nullptr); this->setColorFilter(nullptr); this->setRasterizer(nullptr); @@ -2140,8 +2116,11 @@ void SkPaint::toString(SkString* str) const { str->append("</dd>"); } - if (!this->isSrcOver()) { - str->appendf("<dt>Xfermode:</dt><dd>%d</dd>", fBlendMode); + SkXfermode* xfer = this->getXfermode(); + if (xfer) { + str->append("<dt>Xfermode:</dt><dd>"); + xfer->toString(str); + str->append("</dd>"); } SkMaskFilter* maskFilter = this->getMaskFilter(); @@ -2384,20 +2363,23 @@ bool SkPaint::nothingToDraw() const { if (fDrawLooper) { return false; } - switch ((SkBlendMode)fBlendMode) { - case SkBlendMode::kSrcOver: - case SkBlendMode::kSrcATop: - case SkBlendMode::kDstOut: - case SkBlendMode::kDstOver: - case SkBlendMode::kPlus: - if (0 == this->getAlpha()) { - return !affects_alpha(fColorFilter.get()) && !affects_alpha(fImageFilter.get()); - } - break; - case SkBlendMode::kDst: - return true; - default: - break; + SkXfermode::Mode mode; + if (SkXfermode::AsMode(fXfermode.get(), &mode)) { + switch (mode) { + case SkXfermode::kSrcOver_Mode: + case SkXfermode::kSrcATop_Mode: + case SkXfermode::kDstOut_Mode: + case SkXfermode::kDstOver_Mode: + case SkXfermode::kPlus_Mode: + if (0 == this->getAlpha()) { + return !affects_alpha(fColorFilter.get()) && !affects_alpha(fImageFilter.get()); + } + break; + case SkXfermode::kDst_Mode: + return true; + default: + break; + } } return false; } @@ -2405,7 +2387,7 @@ bool SkPaint::nothingToDraw() const { uint32_t SkPaint::getHash() const { // We're going to hash 10 pointers and 7 32-bit values, finishing up with fBitfields, // so fBitfields should be 10 pointers and 6 32-bit values from the start. - static_assert(offsetof(SkPaint, fBitfields) == 8 * sizeof(void*) + 7 * sizeof(uint32_t), + static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeof(uint32_t), "SkPaint_notPackedTightly"); return SkOpts::hash(reinterpret_cast<const uint32_t*>(this), offsetof(SkPaint, fBitfields) + sizeof(fBitfields)); |