if (glyph.fWidth) {
this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(),
- glyph.getSubYFixed()),
+ glyph.getSubYFixed(),
+ GrGlyph::kCoverage_MaskStyle),
Sk48Dot16FloorToInt(fx),
Sk48Dot16FloorToInt(fy),
fontScaler);
if (glyph.fWidth) {
this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(),
- glyph.getSubYFixed()),
+ glyph.getSubYFixed(),
+ GrGlyph::kCoverage_MaskStyle),
Sk48Dot16FloorToInt(fx),
Sk48Dot16FloorToInt(fy),
fontScaler);
this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(),
- glyph.getSubYFixed()),
+ glyph.getSubYFixed(),
+ GrGlyph::kCoverage_MaskStyle),
Sk48Dot16FloorToInt(fx),
Sk48Dot16FloorToInt(fy),
fontScaler);
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);
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);
}
if (NULL == fStrike) {
- fStrike = fContext->getFontCache()->getStrike(scaler, false);
+ fStrike = fContext->getFontCache()->getStrike(scaler);
}
GrGlyph* glyph = fStrike->getGlyph(packed, scaler);
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);
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);
}
if (NULL == fStrike) {
- fStrike = fContext->getFontCache()->getStrike(scaler, true);
+ fStrike = fContext->getFontCache()->getStrike(scaler);
}
GrGlyph* glyph = fStrike->getGlyph(packed, scaler);
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;
}
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) {
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())) {
SkVarAlloc fPool;
GrFontCache* fFontCache;
- bool fUseDistanceField;
GrAtlas::ClientPlotUsage fPlotUsage;
GrFontCache(GrGpu*);
~GrFontCache();
- inline GrTextStrike* getStrike(GrFontScaler* scaler, bool useDistanceField) {
+ inline GrTextStrike* getStrike(GrFontScaler* scaler) {
this->validate();
GrTextStrike* strike = fCache.find(*(scaler->getKey()));
strike->fPrev = NULL;
fHead = strike;
}
- strike->fUseDistanceField = useDistanceField;
this->validate();
return strike;
}
- failed to get metrics
*/
struct GrGlyph {
+ enum MaskStyle {
+ kCoverage_MaskStyle,
+ kDistance_MaskStyle
+ };
+
typedef uint32_t PackedID;
GrPlot* fPlot;
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) {
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;
}