From f59eab269350f36a0c2bf98d1c2a9757c77fc473 Mon Sep 17 00:00:00 2001 From: reed Date: Mon, 14 Jul 2014 14:39:15 -0700 Subject: [PATCH] patch from issue 383923002 TBR= Author: reed@google.com Review URL: https://codereview.chromium.org/394603003 --- include/core/SkPaint.h | 27 +++++++------- src/core/SkPaint.cpp | 98 ++++++++++++++++++++++++-------------------------- 2 files changed, 61 insertions(+), 64 deletions(-) diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h index e8d85ce..3874d98 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -89,7 +89,7 @@ public: }; Hinting getHinting() const { - return static_cast(fHinting); + return static_cast(fBitfields.fHinting); } void setHinting(Hinting hintingLevel); @@ -121,7 +121,7 @@ public: /** Return the paint's flags. Use the Flag enum to test flag values. @return the paint's flags (see enums ending in _Flag for bit masks) */ - uint32_t getFlags() const { return fFlags; } + uint32_t getFlags() const { return fBitfields.fFlags; } /** Set the paint's flags. Use the Flag enum to specific flag values. @param flags The new flag bits for the paint (see Flags enum) @@ -302,7 +302,9 @@ public: * Return the filter level. This affects the quality (and performance) of * drawing scaled images. */ - FilterLevel getFilterLevel() const { return (FilterLevel)fFilterLevel; } + FilterLevel getFilterLevel() const { + return (FilterLevel)fBitfields.fFilterLevel; + } /** * Set the filter level. This affects the quality (and performance) of @@ -350,7 +352,7 @@ public: kFill_Style). @return the paint's Style */ - Style getStyle() const { return (Style)fStyle; } + Style getStyle() const { return (Style)fBitfields.fStyle; } /** Set the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes @@ -456,7 +458,7 @@ public: @return the line cap style for the paint, used whenever the paint's style is Stroke or StrokeAndFill. */ - Cap getStrokeCap() const { return (Cap)fCapType; } + Cap getStrokeCap() const { return (Cap)fBitfields.fCapType; } /** Set the paint's stroke cap type. @param cap set the paint's line cap style, used whenever the paint's @@ -468,7 +470,7 @@ public: @return the paint's line join style, used whenever the paint's style is Stroke or StrokeAndFill. */ - Join getStrokeJoin() const { return (Join)fJoinType; } + Join getStrokeJoin() const { return (Join)fBitfields.fJoinType; } /** Set the paint's stroke join type. @param join set the paint's line join style, used whenever the paint's @@ -685,7 +687,7 @@ public: /** Return the paint's Align value for drawing text. @return the paint's Align value for drawing text. */ - Align getTextAlign() const { return (Align)fTextAlign; } + Align getTextAlign() const { return (Align)fBitfields.fTextAlign; } /** Set the paint's text alignment. @param align set the paint's Align value for drawing text. @@ -738,7 +740,9 @@ public: kGlyphID_TextEncoding //!< the text parameters are glyph indices }; - TextEncoding getTextEncoding() const { return (TextEncoding)fTextEncoding; } + TextEncoding getTextEncoding() const { + return (TextEncoding)fBitfields.fTextEncoding; + } void setTextEncoding(TextEncoding encoding); @@ -1066,14 +1070,11 @@ private: unsigned fHinting : 2; unsigned fFilterLevel : 2; //unsigned fFreeBits : 2; - }; - uint32_t fBitfields; + } fBitfields; + uint32_t fBitfieldsUInt; }; uint32_t fDirtyBits; - uint32_t getBitfields() const { return fBitfields; } - void setBitfields(uint32_t bitfields); - SkDrawCacheProc getDrawCacheProc() const; SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir, bool needFullMetrics) const; diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 62db714..8fc7c19 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -82,22 +82,22 @@ SkPaint::SkPaint() { fImageFilter = NULL; fAnnotation = NULL; - fTextSize = SkPaintDefaults_TextSize; - fTextScaleX = SK_Scalar1; - fTextSkewX = 0; - fColor = SK_ColorBLACK; - fWidth = 0; - fMiterLimit = SkPaintDefaults_MiterLimit; + fTextSize = SkPaintDefaults_TextSize; + fTextScaleX = SK_Scalar1; + fTextSkewX = 0; + fColor = SK_ColorBLACK; + fWidth = 0; + fMiterLimit = SkPaintDefaults_MiterLimit; // Zero all bitfields, then set some non-zero defaults. - fBitfields = 0; - fFlags = SkPaintDefaults_Flags; - fCapType = kDefault_Cap; - fJoinType = kDefault_Join; - fTextAlign = kLeft_Align; - fStyle = kFill_Style; - fTextEncoding = kUTF8_TextEncoding; - fHinting = SkPaintDefaults_Hinting; + fBitfieldsUInt = 0; + fBitfields.fFlags = SkPaintDefaults_Flags; + fBitfields.fCapType = kDefault_Cap; + fBitfields.fJoinType = kDefault_Join; + fBitfields.fTextAlign = kLeft_Align; + fBitfields.fStyle = kFill_Style; + fBitfields.fTextEncoding = kUTF8_TextEncoding; + fBitfields.fHinting = SkPaintDefaults_Hinting; fDirtyBits = 0; #ifdef SK_BUILD_FOR_ANDROID @@ -213,7 +213,7 @@ bool operator==(const SkPaint& a, const SkPaint& b) { && EQUAL(fColor) && EQUAL(fWidth) && EQUAL(fMiterLimit) - && EQUAL(fBitfields) + && EQUAL(fBitfieldsUInt) #ifdef SK_BUILD_FOR_ANDROID && EQUAL(fPaintOptionsAndroid) #endif @@ -258,76 +258,76 @@ void SkPaint::setPaintOptionsAndroid(const SkPaintOptionsAndroid& options) { #endif void SkPaint::setFilterLevel(FilterLevel level) { - GEN_ID_INC_EVAL((unsigned) level != fFilterLevel); - fFilterLevel = level; + GEN_ID_INC_EVAL((unsigned) level != fBitfields.fFilterLevel); + fBitfields.fFilterLevel = level; } void SkPaint::setHinting(Hinting hintingLevel) { - GEN_ID_INC_EVAL((unsigned) hintingLevel != fHinting); - fHinting = hintingLevel; + GEN_ID_INC_EVAL((unsigned) hintingLevel != fBitfields.fHinting); + fBitfields.fHinting = hintingLevel; } void SkPaint::setFlags(uint32_t flags) { - GEN_ID_INC_EVAL(fFlags != flags); - fFlags = flags; + GEN_ID_INC_EVAL(flags != fBitfields.fFlags); + fBitfields.fFlags = flags; } void SkPaint::setAntiAlias(bool doAA) { - this->setFlags(SkSetClearMask(fFlags, doAA, kAntiAlias_Flag)); + this->setFlags(SkSetClearMask(fBitfields.fFlags, doAA, kAntiAlias_Flag)); } void SkPaint::setDither(bool doDither) { - this->setFlags(SkSetClearMask(fFlags, doDither, kDither_Flag)); + this->setFlags(SkSetClearMask(fBitfields.fFlags, doDither, kDither_Flag)); } void SkPaint::setSubpixelText(bool doSubpixel) { - this->setFlags(SkSetClearMask(fFlags, doSubpixel, kSubpixelText_Flag)); + this->setFlags(SkSetClearMask(fBitfields.fFlags, doSubpixel, kSubpixelText_Flag)); } void SkPaint::setLCDRenderText(bool doLCDRender) { - this->setFlags(SkSetClearMask(fFlags, doLCDRender, kLCDRenderText_Flag)); + this->setFlags(SkSetClearMask(fBitfields.fFlags, doLCDRender, kLCDRenderText_Flag)); } void SkPaint::setEmbeddedBitmapText(bool doEmbeddedBitmapText) { - this->setFlags(SkSetClearMask(fFlags, doEmbeddedBitmapText, kEmbeddedBitmapText_Flag)); + this->setFlags(SkSetClearMask(fBitfields.fFlags, doEmbeddedBitmapText, kEmbeddedBitmapText_Flag)); } void SkPaint::setAutohinted(bool useAutohinter) { - this->setFlags(SkSetClearMask(fFlags, useAutohinter, kAutoHinting_Flag)); + this->setFlags(SkSetClearMask(fBitfields.fFlags, useAutohinter, kAutoHinting_Flag)); } void SkPaint::setLinearText(bool doLinearText) { - this->setFlags(SkSetClearMask(fFlags, doLinearText, kLinearText_Flag)); + this->setFlags(SkSetClearMask(fBitfields.fFlags, doLinearText, kLinearText_Flag)); } void SkPaint::setVerticalText(bool doVertical) { - this->setFlags(SkSetClearMask(fFlags, doVertical, kVerticalText_Flag)); + this->setFlags(SkSetClearMask(fBitfields.fFlags, doVertical, kVerticalText_Flag)); } void SkPaint::setUnderlineText(bool doUnderline) { - this->setFlags(SkSetClearMask(fFlags, doUnderline, kUnderlineText_Flag)); + this->setFlags(SkSetClearMask(fBitfields.fFlags, doUnderline, kUnderlineText_Flag)); } void SkPaint::setStrikeThruText(bool doStrikeThru) { - this->setFlags(SkSetClearMask(fFlags, doStrikeThru, kStrikeThruText_Flag)); + this->setFlags(SkSetClearMask(fBitfields.fFlags, doStrikeThru, kStrikeThruText_Flag)); } void SkPaint::setFakeBoldText(bool doFakeBold) { - this->setFlags(SkSetClearMask(fFlags, doFakeBold, kFakeBoldText_Flag)); + this->setFlags(SkSetClearMask(fBitfields.fFlags, doFakeBold, kFakeBoldText_Flag)); } void SkPaint::setDevKernText(bool doDevKern) { - this->setFlags(SkSetClearMask(fFlags, doDevKern, kDevKernText_Flag)); + this->setFlags(SkSetClearMask(fBitfields.fFlags, doDevKern, kDevKernText_Flag)); } void SkPaint::setDistanceFieldTextTEMP(bool doDistanceFieldText) { - this->setFlags(SkSetClearMask(fFlags, doDistanceFieldText, kDistanceFieldTextTEMP_Flag)); + this->setFlags(SkSetClearMask(fBitfields.fFlags, doDistanceFieldText, kDistanceFieldTextTEMP_Flag)); } void SkPaint::setStyle(Style style) { if ((unsigned)style < kStyleCount) { - GEN_ID_INC_EVAL((unsigned)style != fStyle); - fStyle = style; + GEN_ID_INC_EVAL((unsigned)style != fBitfields.fStyle); + fBitfields.fStyle = style; } else { #ifdef SK_REPORT_API_RANGE_CHECK SkDebugf("SkPaint::setStyle(%d) out of range\n", style); @@ -376,8 +376,8 @@ void SkPaint::setStrokeMiter(SkScalar limit) { void SkPaint::setStrokeCap(Cap ct) { if ((unsigned)ct < kCapCount) { - GEN_ID_INC_EVAL((unsigned)ct != fCapType); - fCapType = SkToU8(ct); + GEN_ID_INC_EVAL((unsigned)ct != fBitfields.fCapType); + fBitfields.fCapType = SkToU8(ct); } else { #ifdef SK_REPORT_API_RANGE_CHECK SkDebugf("SkPaint::setStrokeCap(%d) out of range\n", ct); @@ -387,8 +387,8 @@ void SkPaint::setStrokeCap(Cap ct) { void SkPaint::setStrokeJoin(Join jt) { if ((unsigned)jt < kJoinCount) { - GEN_ID_INC_EVAL((unsigned)jt != fJoinType); - fJoinType = SkToU8(jt); + GEN_ID_INC_EVAL((unsigned)jt != fBitfields.fJoinType); + fBitfields.fJoinType = SkToU8(jt); } else { #ifdef SK_REPORT_API_RANGE_CHECK SkDebugf("SkPaint::setStrokeJoin(%d) out of range\n", jt); @@ -400,8 +400,8 @@ void SkPaint::setStrokeJoin(Join jt) { void SkPaint::setTextAlign(Align align) { if ((unsigned)align < kAlignCount) { - GEN_ID_INC_EVAL((unsigned)align != fTextAlign); - fTextAlign = SkToU8(align); + GEN_ID_INC_EVAL((unsigned)align != fBitfields.fTextAlign); + fBitfields.fTextAlign = SkToU8(align); } else { #ifdef SK_REPORT_API_RANGE_CHECK SkDebugf("SkPaint::setTextAlign(%d) out of range\n", align); @@ -435,8 +435,8 @@ void SkPaint::setTextSkewX(SkScalar skewX) { void SkPaint::setTextEncoding(TextEncoding encoding) { if ((unsigned)encoding <= kGlyphID_TextEncoding) { - GEN_ID_INC_EVAL((unsigned)encoding != fTextEncoding); - fTextEncoding = encoding; + GEN_ID_INC_EVAL((unsigned)encoding != fBitfields.fTextEncoding); + fBitfields.fTextEncoding = encoding; } else { #ifdef SK_REPORT_API_RANGE_CHECK SkDebugf("SkPaint::setTextEncoding(%d) out of range\n", encoding); @@ -953,7 +953,7 @@ SkDrawCacheProc SkPaint::getDrawCacheProc() const { }; unsigned index = this->getTextEncoding(); - if (fFlags & kSubpixelText_Flag) { + if (fBitfields.fFlags & kSubpixelText_Flag) { index += 4; } @@ -2658,10 +2658,6 @@ bool SkPaint::nothingToDraw() const { return false; } -void SkPaint::setBitfields(uint32_t bitfields) { - fBitfields = bitfields; -} - inline static unsigned popcount(uint8_t x) { // As in Hacker's delight, adapted for just 8 bits. x = (x & 0x55) + ((x >> 1) & 0x55); // a b c d w x y z -> a+b c+d w+x y+z @@ -2679,7 +2675,7 @@ void SkPaint::FlatteningTraits::Flatten(SkWriteBuffer& buffer, const SkPaint& pa SkASSERT(flatBytes <= 32); uint32_t* u32 = buffer.reserve(flatBytes); *u32++ = dirty; - *u32++ = paint.getBitfields(); + *u32++ = paint.fBitfieldsUInt; if (0 == dirty) { return; } @@ -2712,7 +2708,7 @@ void SkPaint::FlatteningTraits::Flatten(SkWriteBuffer& buffer, const SkPaint& pa void SkPaint::FlatteningTraits::Unflatten(SkReadBuffer& buffer, SkPaint* paint) { const uint32_t dirty = buffer.readUInt(); - paint->setBitfields(buffer.readUInt()); + paint->fBitfieldsUInt = buffer.readUInt(); if (dirty == 0) { return; } -- 2.7.4