diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-14 19:13:55 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-14 19:13:55 +0000 |
commit | a9d4e84c435f61be3c02d7f54acab973e8b7761c (patch) | |
tree | 70ff443cb63d1cec81581262df16f66445851bc4 | |
parent | b5e4703b8661a54d6f0bc1a81307dac936644046 (diff) |
To allow forward declarations, move SkScalerContext::Rec to SkScalerContextRec
Review URL: https://codereview.appspot.com/6462059
git-svn-id: http://skia.googlecode.com/svn/trunk@5090 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/core/SkFontHost.h | 5 | ||||
-rw-r--r-- | include/core/SkScalerContext.h | 179 | ||||
-rw-r--r-- | src/core/SkScalerContext.cpp | 6 |
3 files changed, 103 insertions, 87 deletions
diff --git a/include/core/SkFontHost.h b/include/core/SkFontHost.h index 7e89ee3c4e..b815df624a 100644 --- a/include/core/SkFontHost.h +++ b/include/core/SkFontHost.h @@ -10,10 +10,11 @@ #ifndef SkFontHost_DEFINED #define SkFontHost_DEFINED -#include "SkScalerContext.h" #include "SkTypeface.h" class SkDescriptor; +class SkScalerContext; +struct SkScalerContextRec; class SkStream; class SkWStream; @@ -167,7 +168,7 @@ public: A lazy (but valid) fonthost can do nothing in its FilterRec routine. */ - static void FilterRec(SkScalerContext::Rec* rec); + static void FilterRec(SkScalerContextRec* rec); /////////////////////////////////////////////////////////////////////////// diff --git a/include/core/SkScalerContext.h b/include/core/SkScalerContext.h index adbdf8a287..eee52a57e8 100644 --- a/include/core/SkScalerContext.h +++ b/include/core/SkScalerContext.h @@ -24,6 +24,87 @@ class SkMaskFilter; class SkPathEffect; class SkRasterizer; +/* + * To allow this to be forward-declared, it must be its own typename, rather + * than a nested struct inside SkScalerContext (where it started). + */ +struct SkScalerContextRec { + uint32_t fOrigFontID; + uint32_t fFontID; + SkScalar fTextSize, fPreScaleX, fPreSkewX; + SkScalar fPost2x2[2][2]; + SkScalar fFrameWidth, fMiterLimit; + + //These describe the parameters to create (uniquely identify) the pre-blend. + uint32_t fLumBits; + uint8_t fDeviceGamma; //2.6, (0.0, 4.0) gamma, 0.0 for sRGB + uint8_t fPaintGamma; //2.6, (0.0, 4.0) gamma, 0.0 for sRGB + uint8_t fContrast; //0.8+1, [0.0, 1.0] artificial contrast + uint8_t fReservedAlign; + + SkScalar getDeviceGamma() const { + return SkIntToScalar(fDeviceGamma) / (1 << 6); + } + void setDeviceGamma(SkScalar dg) { + SkASSERT(0 <= dg && dg < SkIntToScalar(4)); + fDeviceGamma = SkScalarFloorToInt(dg * (1 << 6)); + } + + SkScalar getPaintGamma() const { + return SkIntToScalar(fPaintGamma) / (1 << 6); + } + void setPaintGamma(SkScalar pg) { + SkASSERT(0 <= pg && pg < SkIntToScalar(4)); + fPaintGamma = SkScalarFloorToInt(pg * (1 << 6)); + } + + SkScalar getContrast() const { + return SkIntToScalar(fContrast) / ((1 << 8) - 1); + } + void setContrast(SkScalar c) { + SkASSERT(0 <= c && c <= SK_Scalar1); + fContrast = SkScalarRoundToInt(c * ((1 << 8) - 1)); + } + + /** + * Causes the luminance color and contrast to be ignored, and the + * paint and device gamma to be effectively 1.0. + */ + void ignorePreBlend() { + setLuminanceColor(0x00000000); + setPaintGamma(SK_Scalar1); + setDeviceGamma(SK_Scalar1); + setContrast(0); + } + + uint8_t fMaskFormat; + uint8_t fStrokeJoin; + uint16_t fFlags; + // Warning: when adding members note that the size of this structure + // must be a multiple of 4. SkDescriptor requires that its arguments be + // multiples of four and this structure is put in an SkDescriptor in + // SkPaint::MakeRec. + + void getMatrixFrom2x2(SkMatrix*) const; + void getLocalMatrix(SkMatrix*) const; + void getSingleMatrix(SkMatrix*) const; + + inline SkPaint::Hinting getHinting() const; + inline void setHinting(SkPaint::Hinting); + + SkMask::Format getFormat() const { + return static_cast<SkMask::Format>(fMaskFormat); + } + + SkColor getLuminanceColor() const { + return fLumBits; + } + + void setLuminanceColor(SkColor c) { + fLumBits = c; + } +}; + //The following typedef hides from the rest of the implementation the number of //most significant bits to consider when creating mask gamma tables. Two bits //per channel was chosen as a balance between fidelity (more bits) and cache @@ -32,6 +113,8 @@ typedef SkTMaskGamma<2, 2, 2> SkMaskGamma; class SkScalerContext { public: + typedef SkScalerContextRec Rec; + enum Flags { kFrameAndFill_Flag = 0x0001, kDevKernText_Flag = 0x0002, @@ -61,88 +144,6 @@ public: kHinting_Mask = kHintingBit1_Flag | kHintingBit2_Flag, }; - struct Rec { - uint32_t fOrigFontID; - uint32_t fFontID; - SkScalar fTextSize, fPreScaleX, fPreSkewX; - SkScalar fPost2x2[2][2]; - SkScalar fFrameWidth, fMiterLimit; - - //These describe the parameters to create (uniquely identify) the pre-blend. - uint32_t fLumBits; - uint8_t fDeviceGamma; //2.6, (0.0, 4.0) gamma, 0.0 for sRGB - uint8_t fPaintGamma; //2.6, (0.0, 4.0) gamma, 0.0 for sRGB - uint8_t fContrast; //0.8+1, [0.0, 1.0] artificial contrast - uint8_t fReservedAlign; - - SkScalar getDeviceGamma() const { - return SkIntToScalar(fDeviceGamma) / (1 << 6); - } - void setDeviceGamma(SkScalar dg) { - SkASSERT(0 <= dg && dg < SkIntToScalar(4)); - fDeviceGamma = SkScalarFloorToInt(dg * (1 << 6)); - } - - SkScalar getPaintGamma() const { - return SkIntToScalar(fPaintGamma) / (1 << 6); - } - void setPaintGamma(SkScalar pg) { - SkASSERT(0 <= pg && pg < SkIntToScalar(4)); - fPaintGamma = SkScalarFloorToInt(pg * (1 << 6)); - } - - SkScalar getContrast() const { - return SkIntToScalar(fContrast) / ((1 << 8) - 1); - } - void setContrast(SkScalar c) { - SkASSERT(0 <= c && c <= SK_Scalar1); - fContrast = SkScalarRoundToInt(c * ((1 << 8) - 1)); - } - - /** - * Causes the luminance color and contrast to be ignored, and the - * paint and device gamma to be effectively 1.0. - */ - void ignorePreBlend() { - setLuminanceColor(0x00000000); - setPaintGamma(SK_Scalar1); - setDeviceGamma(SK_Scalar1); - setContrast(0); - } - - uint8_t fMaskFormat; - uint8_t fStrokeJoin; - uint16_t fFlags; - // Warning: when adding members note that the size of this structure - // must be a multiple of 4. SkDescriptor requires that its arguments be - // multiples of four and this structure is put in an SkDescriptor in - // SkPaint::MakeRec. - - void getMatrixFrom2x2(SkMatrix*) const; - void getLocalMatrix(SkMatrix*) const; - void getSingleMatrix(SkMatrix*) const; - - SkPaint::Hinting getHinting() const { - unsigned hint = (fFlags & kHinting_Mask) >> kHinting_Shift; - return static_cast<SkPaint::Hinting>(hint); - } - - void setHinting(SkPaint::Hinting hinting) { - fFlags = (fFlags & ~kHinting_Mask) | (hinting << kHinting_Shift); - } - - SkMask::Format getFormat() const { - return static_cast<SkMask::Format>(fMaskFormat); - } - - SkColor getLuminanceColor() const { - return fLumBits; - } - - void setLuminanceColor(SkColor c) { - fLumBits = c; - } - }; SkScalerContext(const SkDescriptor* desc); virtual ~SkScalerContext(); @@ -267,5 +268,19 @@ enum SkAxisAlignment { */ SkAxisAlignment SkComputeAxisAlignmentForHText(const SkMatrix& matrix); +/////////////////////////////////////////////////////////////////////////////// + +SkPaint::Hinting SkScalerContextRec::getHinting() const { + unsigned hint = (fFlags & SkScalerContext::kHinting_Mask) >> + SkScalerContext::kHinting_Shift; + return static_cast<SkPaint::Hinting>(hint); +} + +void SkScalerContextRec::setHinting(SkPaint::Hinting hinting) { + fFlags = (fFlags & ~SkScalerContext::kHinting_Mask) | + (hinting << SkScalerContext::kHinting_Shift); +} + + #endif diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp index 9d99713c40..3fbcf3bf5b 100644 --- a/src/core/SkScalerContext.cpp +++ b/src/core/SkScalerContext.cpp @@ -691,7 +691,7 @@ void SkScalerContext::internalGetPath(const SkGlyph& glyph, SkPath* fillPath, } -void SkScalerContext::Rec::getMatrixFrom2x2(SkMatrix* dst) const { +void SkScalerContextRec::getMatrixFrom2x2(SkMatrix* dst) const { dst->reset(); dst->setScaleX(fPost2x2[0][0]); dst->setSkewX( fPost2x2[0][1]); @@ -699,14 +699,14 @@ void SkScalerContext::Rec::getMatrixFrom2x2(SkMatrix* dst) const { dst->setScaleY(fPost2x2[1][1]); } -void SkScalerContext::Rec::getLocalMatrix(SkMatrix* m) const { +void SkScalerContextRec::getLocalMatrix(SkMatrix* m) const { m->setScale(SkScalarMul(fTextSize, fPreScaleX), fTextSize); if (fPreSkewX) { m->postSkew(fPreSkewX, 0); } } -void SkScalerContext::Rec::getSingleMatrix(SkMatrix* m) const { +void SkScalerContextRec::getSingleMatrix(SkMatrix* m) const { this->getLocalMatrix(m); // now concat the device matrix |