Ensure that we use different glyph entries for regular and df text.

Currently if we switch between regular text and df text while using
the same GrContext, they may use the same entry in the Ganesh font cache,
which is incorrect. This change ensures that they will have different entries.

Committed: https://skia.googlesource.com/skia/+/8dc58edd71c11f232860724dfa3b566895478034

Review URL: https://codereview.chromium.org/1020593003
This commit is contained in:
jvanverth 2015-03-19 06:08:31 -07:00 committed by Commit bot
parent 9b77ddde08
commit a7634619ec
5 changed files with 34 additions and 17 deletions

View File

@ -171,7 +171,8 @@ void GrBitmapTextContext::onDrawText(GrRenderTarget* rt, const GrClip& clip,
if (glyph.fWidth) { if (glyph.fWidth) {
this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(), glyph.getSubXFixed(),
glyph.getSubYFixed()), glyph.getSubYFixed(),
GrGlyph::kCoverage_MaskStyle),
Sk48Dot16FloorToInt(fx), Sk48Dot16FloorToInt(fx),
Sk48Dot16FloorToInt(fy), Sk48Dot16FloorToInt(fy),
fontScaler); fontScaler);
@ -248,7 +249,8 @@ void GrBitmapTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip,
if (glyph.fWidth) { if (glyph.fWidth) {
this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(), glyph.getSubXFixed(),
glyph.getSubYFixed()), glyph.getSubYFixed(),
GrGlyph::kCoverage_MaskStyle),
Sk48Dot16FloorToInt(fx), Sk48Dot16FloorToInt(fx),
Sk48Dot16FloorToInt(fy), Sk48Dot16FloorToInt(fy),
fontScaler); fontScaler);
@ -281,7 +283,8 @@ void GrBitmapTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip,
this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(), glyph.getSubXFixed(),
glyph.getSubYFixed()), glyph.getSubYFixed(),
GrGlyph::kCoverage_MaskStyle),
Sk48Dot16FloorToInt(fx), Sk48Dot16FloorToInt(fx),
Sk48Dot16FloorToInt(fy), Sk48Dot16FloorToInt(fy),
fontScaler); fontScaler);
@ -304,7 +307,8 @@ void GrBitmapTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip,
Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + SK_ScalarHalf); //halfSampleY; Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + SK_ScalarHalf); //halfSampleY;
this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(), glyph.getSubXFixed(),
glyph.getSubYFixed()), glyph.getSubYFixed(),
GrGlyph::kCoverage_MaskStyle),
Sk48Dot16FloorToInt(fx), Sk48Dot16FloorToInt(fx),
Sk48Dot16FloorToInt(fy), Sk48Dot16FloorToInt(fy),
fontScaler); fontScaler);
@ -327,7 +331,8 @@ void GrBitmapTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip,
Sk48Dot16 fy = SkScalarTo48Dot16(alignLoc.fY + SK_ScalarHalf); //halfSampleY; Sk48Dot16 fy = SkScalarTo48Dot16(alignLoc.fY + SK_ScalarHalf); //halfSampleY;
this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(), glyph.getSubXFixed(),
glyph.getSubYFixed()), glyph.getSubYFixed(),
GrGlyph::kCoverage_MaskStyle),
Sk48Dot16FloorToInt(fx), Sk48Dot16FloorToInt(fx),
Sk48Dot16FloorToInt(fy), Sk48Dot16FloorToInt(fy),
fontScaler); fontScaler);
@ -412,7 +417,7 @@ void GrBitmapTextContext::appendGlyph(GrGlyph::PackedID packed,
} }
if (NULL == fStrike) { if (NULL == fStrike) {
fStrike = fContext->getFontCache()->getStrike(scaler, false); fStrike = fContext->getFontCache()->getStrike(scaler);
} }
GrGlyph* glyph = fStrike->getGlyph(packed, scaler); GrGlyph* glyph = fStrike->getGlyph(packed, scaler);

View File

@ -319,7 +319,8 @@ void GrDistanceFieldTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip&
if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(), glyph.getSubXFixed(),
glyph.getSubYFixed()), glyph.getSubYFixed(),
GrGlyph::kDistance_MaskStyle),
x, y, fontScaler)) { x, y, fontScaler)) {
// couldn't append, send to fallback // couldn't append, send to fallback
fallbackTxt.push_back_n(SkToInt(text-lastText), lastText); 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(), if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(), glyph.getSubXFixed(),
glyph.getSubYFixed()), glyph.getSubYFixed(),
GrGlyph::kDistance_MaskStyle),
x - advanceX, y - advanceY, fontScaler)) { x - advanceX, y - advanceY, fontScaler)) {
// couldn't append, send to fallback // couldn't append, send to fallback
fallbackTxt.push_back_n(SkToInt(text-lastText), lastText); fallbackTxt.push_back_n(SkToInt(text-lastText), lastText);
@ -509,7 +511,7 @@ bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed,
} }
if (NULL == fStrike) { if (NULL == fStrike) {
fStrike = fContext->getFontCache()->getStrike(scaler, true); fStrike = fContext->getFontCache()->getStrike(scaler);
} }
GrGlyph* glyph = fStrike->getGlyph(packed, scaler); GrGlyph* glyph = fStrike->getGlyph(packed, scaler);

View File

@ -258,7 +258,7 @@ GrTextStrike::~GrTextStrike() {
GrGlyph* GrTextStrike::generateGlyph(GrGlyph::PackedID packed, GrGlyph* GrTextStrike::generateGlyph(GrGlyph::PackedID packed,
GrFontScaler* scaler) { GrFontScaler* scaler) {
SkIRect bounds; SkIRect bounds;
if (fUseDistanceField) { if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(packed)) {
if (!scaler->getPackedGlyphDFBounds(packed, &bounds)) { if (!scaler->getPackedGlyphDFBounds(packed, &bounds)) {
return NULL; return NULL;
} }
@ -290,7 +290,9 @@ void GrTextStrike::removePlot(const GrPlot* plot) {
bool GrTextStrike::glyphTooLargeForAtlas(GrGlyph* glyph) { bool GrTextStrike::glyphTooLargeForAtlas(GrGlyph* glyph) {
int width = glyph->fBounds.width(); int width = glyph->fBounds.width();
int height = glyph->fBounds.height(); 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 int plotWidth = (kA8_GrMaskFormat == glyph->fMaskFormat) ? GR_FONT_ATLAS_A8_PLOT_WIDTH
: GR_FONT_ATLAS_PLOT_WIDTH; : GR_FONT_ATLAS_PLOT_WIDTH;
if (width + pad > plotWidth) { if (width + pad > plotWidth) {
@ -321,7 +323,7 @@ bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) {
size_t size = glyph->fBounds.area() * bytesPerPixel; size_t size = glyph->fBounds.area() * bytesPerPixel;
GrAutoMalloc<1024> storage(size); GrAutoMalloc<1024> storage(size);
if (fUseDistanceField) { if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(glyph->fPackedID)) {
if (!scaler->getPackedGlyphDFImage(glyph->fPackedID, glyph->width(), if (!scaler->getPackedGlyphDFImage(glyph->fPackedID, glyph->width(),
glyph->height(), glyph->height(),
storage.get())) { storage.get())) {

View File

@ -72,7 +72,6 @@ private:
SkVarAlloc fPool; SkVarAlloc fPool;
GrFontCache* fFontCache; GrFontCache* fFontCache;
bool fUseDistanceField;
GrAtlas::ClientPlotUsage fPlotUsage; GrAtlas::ClientPlotUsage fPlotUsage;
@ -86,7 +85,7 @@ public:
GrFontCache(GrGpu*); GrFontCache(GrGpu*);
~GrFontCache(); ~GrFontCache();
inline GrTextStrike* getStrike(GrFontScaler* scaler, bool useDistanceField) { inline GrTextStrike* getStrike(GrFontScaler* scaler) {
this->validate(); this->validate();
GrTextStrike* strike = fCache.find(*(scaler->getKey())); GrTextStrike* strike = fCache.find(*(scaler->getKey()));
@ -102,7 +101,6 @@ public:
strike->fPrev = NULL; strike->fPrev = NULL;
fHead = strike; fHead = strike;
} }
strike->fUseDistanceField = useDistanceField;
this->validate(); this->validate();
return strike; return strike;
} }

View File

@ -23,6 +23,11 @@ class GrPlot;
- failed to get metrics - failed to get metrics
*/ */
struct GrGlyph { struct GrGlyph {
enum MaskStyle {
kCoverage_MaskStyle,
kDistance_MaskStyle
};
typedef uint32_t PackedID; typedef uint32_t PackedID;
GrPlot* fPlot; GrPlot* fPlot;
@ -60,10 +65,11 @@ struct GrGlyph {
return (pos >> 14) & 3; 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); x = ExtractSubPixelBitsFromFixed(x);
y = ExtractSubPixelBitsFromFixed(y); 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) { static inline SkFixed UnpackFixedX(PackedID packed) {
@ -74,6 +80,10 @@ struct GrGlyph {
return ((packed >> 16) & 3) << 14; 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) { static inline uint16_t UnpackID(PackedID packed) {
return (uint16_t)packed; return (uint16_t)packed;
} }