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.

Review URL: https://codereview.chromium.org/1020593003
This commit is contained in:
jvanverth 2015-03-18 14:46:38 -07:00 committed by Commit bot
parent 905d01b95a
commit 8dc58edd71
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) {
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);

View File

@ -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);

View File

@ -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())) {

View File

@ -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;
}

View File

@ -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;
}