diff options
-rwxr-xr-x | src/gpu/GrBitmapTextContext.cpp | 17 | ||||
-rwxr-xr-x | src/gpu/GrDistanceFieldTextContext.cpp | 8 | ||||
-rw-r--r-- | src/gpu/GrFontCache.cpp | 8 | ||||
-rw-r--r-- | src/gpu/GrFontCache.h | 4 | ||||
-rw-r--r-- | src/gpu/GrGlyph.h | 14 |
5 files changed, 34 insertions, 17 deletions
diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp index 3031f985ed..ed3ed09642 100755 --- a/src/gpu/GrBitmapTextContext.cpp +++ b/src/gpu/GrBitmapTextContext.cpp @@ -171,7 +171,8 @@ void GrBitmapTextContext::onDrawText(GrRenderTarget* rt, const GrClip& clip, if (glyph.fWidth) { this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), glyph.getSubXFixed(), - glyph.getSubYFixed()), + glyph.getSubYFixed(), + GrGlyph::kCoverage_MaskStyle), Sk48Dot16FloorToInt(fx), Sk48Dot16FloorToInt(fy), fontScaler); @@ -248,7 +249,8 @@ void GrBitmapTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip, if (glyph.fWidth) { this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), glyph.getSubXFixed(), - glyph.getSubYFixed()), + glyph.getSubYFixed(), + GrGlyph::kCoverage_MaskStyle), Sk48Dot16FloorToInt(fx), Sk48Dot16FloorToInt(fy), fontScaler); @@ -281,7 +283,8 @@ void GrBitmapTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip, this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), glyph.getSubXFixed(), - glyph.getSubYFixed()), + glyph.getSubYFixed(), + GrGlyph::kCoverage_MaskStyle), Sk48Dot16FloorToInt(fx), Sk48Dot16FloorToInt(fy), fontScaler); @@ -304,7 +307,8 @@ void GrBitmapTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip, Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + SK_ScalarHalf); //halfSampleY; this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), glyph.getSubXFixed(), - glyph.getSubYFixed()), + glyph.getSubYFixed(), + GrGlyph::kCoverage_MaskStyle), Sk48Dot16FloorToInt(fx), Sk48Dot16FloorToInt(fy), fontScaler); @@ -327,7 +331,8 @@ void GrBitmapTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip, Sk48Dot16 fy = SkScalarTo48Dot16(alignLoc.fY + SK_ScalarHalf); //halfSampleY; this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), glyph.getSubXFixed(), - glyph.getSubYFixed()), + glyph.getSubYFixed(), + GrGlyph::kCoverage_MaskStyle), Sk48Dot16FloorToInt(fx), Sk48Dot16FloorToInt(fy), fontScaler); @@ -412,7 +417,7 @@ void GrBitmapTextContext::appendGlyph(GrGlyph::PackedID packed, } if (NULL == fStrike) { - fStrike = fContext->getFontCache()->getStrike(scaler, false); + fStrike = fContext->getFontCache()->getStrike(scaler); } GrGlyph* glyph = fStrike->getGlyph(packed, scaler); diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp index 2a439da4f2..180c506e33 100755 --- a/src/gpu/GrDistanceFieldTextContext.cpp +++ b/src/gpu/GrDistanceFieldTextContext.cpp @@ -319,7 +319,8 @@ void GrDistanceFieldTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), glyph.getSubXFixed(), - glyph.getSubYFixed()), + glyph.getSubYFixed(), + GrGlyph::kDistance_MaskStyle), x, y, fontScaler)) { // couldn't append, send to fallback fallbackTxt.push_back_n(SkToInt(text-lastText), lastText); @@ -348,7 +349,8 @@ void GrDistanceFieldTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), glyph.getSubXFixed(), - glyph.getSubYFixed()), + glyph.getSubYFixed(), + GrGlyph::kDistance_MaskStyle), x - advanceX, y - advanceY, fontScaler)) { // couldn't append, send to fallback fallbackTxt.push_back_n(SkToInt(text-lastText), lastText); @@ -509,7 +511,7 @@ bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed, } if (NULL == fStrike) { - fStrike = fContext->getFontCache()->getStrike(scaler, true); + fStrike = fContext->getFontCache()->getStrike(scaler); } GrGlyph* glyph = fStrike->getGlyph(packed, scaler); diff --git a/src/gpu/GrFontCache.cpp b/src/gpu/GrFontCache.cpp index f5c1c22a3d..5952366406 100644 --- a/src/gpu/GrFontCache.cpp +++ b/src/gpu/GrFontCache.cpp @@ -258,7 +258,7 @@ GrTextStrike::~GrTextStrike() { GrGlyph* GrTextStrike::generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler) { SkIRect bounds; - if (fUseDistanceField) { + if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(packed)) { if (!scaler->getPackedGlyphDFBounds(packed, &bounds)) { return NULL; } @@ -290,7 +290,9 @@ void GrTextStrike::removePlot(const GrPlot* plot) { bool GrTextStrike::glyphTooLargeForAtlas(GrGlyph* glyph) { int width = glyph->fBounds.width(); int height = glyph->fBounds.height(); - int pad = fUseDistanceField ? 2 * SK_DistanceFieldPad : 0; + bool useDistanceField = + (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(glyph->fPackedID)); + int pad = useDistanceField ? 2 * SK_DistanceFieldPad : 0; int plotWidth = (kA8_GrMaskFormat == glyph->fMaskFormat) ? GR_FONT_ATLAS_A8_PLOT_WIDTH : GR_FONT_ATLAS_PLOT_WIDTH; if (width + pad > plotWidth) { @@ -321,7 +323,7 @@ bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) { size_t size = glyph->fBounds.area() * bytesPerPixel; GrAutoMalloc<1024> storage(size); - if (fUseDistanceField) { + if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(glyph->fPackedID)) { if (!scaler->getPackedGlyphDFImage(glyph->fPackedID, glyph->width(), glyph->height(), storage.get())) { diff --git a/src/gpu/GrFontCache.h b/src/gpu/GrFontCache.h index 6ee39d0c47..31e56016db 100644 --- a/src/gpu/GrFontCache.h +++ b/src/gpu/GrFontCache.h @@ -72,7 +72,6 @@ private: SkVarAlloc fPool; GrFontCache* fFontCache; - bool fUseDistanceField; GrAtlas::ClientPlotUsage fPlotUsage; @@ -86,7 +85,7 @@ public: GrFontCache(GrGpu*); ~GrFontCache(); - inline GrTextStrike* getStrike(GrFontScaler* scaler, bool useDistanceField) { + inline GrTextStrike* getStrike(GrFontScaler* scaler) { this->validate(); GrTextStrike* strike = fCache.find(*(scaler->getKey())); @@ -102,7 +101,6 @@ public: strike->fPrev = NULL; fHead = strike; } - strike->fUseDistanceField = useDistanceField; this->validate(); return strike; } diff --git a/src/gpu/GrGlyph.h b/src/gpu/GrGlyph.h index 0e534d694a..108f2f0fe7 100644 --- a/src/gpu/GrGlyph.h +++ b/src/gpu/GrGlyph.h @@ -23,6 +23,11 @@ class GrPlot; - failed to get metrics */ struct GrGlyph { + enum MaskStyle { + kCoverage_MaskStyle, + kDistance_MaskStyle + }; + typedef uint32_t PackedID; GrPlot* fPlot; @@ -60,10 +65,11 @@ struct GrGlyph { return (pos >> 14) & 3; } - static inline PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y) { + static inline PackedID Pack(uint16_t glyphID, SkFixed x, SkFixed y, MaskStyle ms) { x = ExtractSubPixelBitsFromFixed(x); y = ExtractSubPixelBitsFromFixed(y); - return (x << 18) | (y << 16) | glyphID; + int dfFlag = (ms == kDistance_MaskStyle) ? 0x1 : 0x0; + return (dfFlag << 20) | (x << 18) | (y << 16) | glyphID; } static inline SkFixed UnpackFixedX(PackedID packed) { @@ -74,6 +80,10 @@ struct GrGlyph { return ((packed >> 16) & 3) << 14; } + static inline MaskStyle UnpackMaskStyle(PackedID packed) { + return ((packed >> 20) & 1) ? kDistance_MaskStyle : kCoverage_MaskStyle; + } + static inline uint16_t UnpackID(PackedID packed) { return (uint16_t)packed; } |