## epoger will rebaseline by 25 Dec 2013
#gradtext
+# jvanverth
+# color emoji fix
+coloremoji
+
# rileya - https://codereview.chromium.org/516463005/ will rebaseline after bots cycle
yuv_to_rgb_effect
virtual ~GrFontScaler();
const GrFontDescKey* getKey();
- GrMaskFormat getMaskFormat();
+ GrMaskFormat getMaskFormat() const;
+ GrMaskFormat getPackedGlyphMaskFormat(GrGlyph::PackedID) const;
bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds);
bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height,
int rowBytes, void* image);
#define GrGlyph_DEFINED
#include "GrRect.h"
-#include "SkPath.h"
+#include "GrTypes.h"
+
#include "SkChecksum.h"
+#include "SkPath.h"
class GrPlot;
struct GrGlyph {
typedef uint32_t PackedID;
- GrPlot* fPlot;
- SkPath* fPath;
- PackedID fPackedID;
- GrIRect16 fBounds;
- SkIPoint16 fAtlasLocation;
+ GrPlot* fPlot;
+ SkPath* fPath;
+ PackedID fPackedID;
+ GrMaskFormat fMaskFormat;
+ GrIRect16 fBounds;
+ SkIPoint16 fAtlasLocation;
- void init(GrGlyph::PackedID packed, const SkIRect& bounds) {
+ void init(GrGlyph::PackedID packed, const SkIRect& bounds, GrMaskFormat format) {
fPlot = NULL;
fPath = NULL;
fPackedID = packed;
fBounds.set(bounds);
+ fMaskFormat = format;
fAtlasLocation.set(0, 0);
}
// last one was most recently added and probably most empty
for (int i = usage->fPlots.count()-1; i >= 0; --i) {
GrPlot* plot = usage->fPlots[i];
- if (plot->addSubImage(width, height, image, loc)) {
+ // client may have plots from more than one atlas, must check for ours before adding
+ if (this == plot->fAtlas && plot->addSubImage(width, height, image, loc)) {
this->makeMRU(plot);
return plot;
}
}
// try to clear out an unused plot before we flush
- if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
+ if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) &&
fStrike->addGlyphToAtlas(glyph, scaler)) {
goto HAS_ATLAS;
}
fContext->flush();
// we should have an unused plot now
- if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
+ if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) &&
fStrike->addGlyphToAtlas(glyph, scaler)) {
goto HAS_ATLAS;
}
width = SkIntToFixed(width);
height = SkIntToFixed(height);
+ // the current texture/maskformat must match what the glyph needs
GrTexture* texture = glyph->fPlot->texture();
SkASSERT(texture);
this->flush();
fCurrTexture = texture;
fCurrTexture->ref();
+ fCurrMaskFormat = glyph->fMaskFormat;
}
- bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat();
+ bool useColorVerts = kA8_GrMaskFormat == fCurrMaskFormat;
if (NULL == fVertices) {
// If we need to reserve vertices allow the draw target to suggest
// This effect could be stored with one of the cache objects (atlas?)
drawState->setGeometryProcessor(fCachedGeometryProcessor.get());
SkASSERT(fStrike);
- switch (fStrike->getMaskFormat()) {
+ switch (fCurrMaskFormat) {
// Color bitmap text
case kARGB_GrMaskFormat:
SkASSERT(!drawState->hasColorVertexAttribute());
drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlendCoeff());
- drawState->setColor(0xffffffff);
+ drawState->setAlpha(fSkPaint.getAlpha());
break;
// LCD text
case kA888_GrMaskFormat:
SkASSERT(drawState->hasColorVertexAttribute());
break;
default:
- SkFAIL("Unexepected mask format.");
+ SkFAIL("Unexpected mask format.");
}
int nGlyphs = fCurrVertex / 4;
fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
GrTextStrike* fStrike;
void* fVertices;
- int32_t fMaxVertices;
+ int fCurrVertex;
+ int fMaxVertices;
+ SkRect fVertexBounds;
GrTexture* fCurrTexture;
+ GrMaskFormat fCurrMaskFormat;
SkAutoTUnref<GrGeometryProcessor> fCachedGeometryProcessor;
// Used to check whether fCachedEffect is still valid.
uint32_t fEffectTextureUniqueID;
- int fCurrVertex;
- SkRect fVertexBounds;
void init(const GrPaint&, const SkPaint&);
void appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*);
return;
}
+ // TODO: support color glyphs
+ if (kA8_GrMaskFormat != glyph->fMaskFormat) {
+ return;
+ }
+
SkScalar sx = SkFixedToScalar(vx);
SkScalar sy = SkFixedToScalar(vy);
/*
}
// try to clear out an unused plot before we flush
- if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
+ if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) &&
fStrike->addGlyphToAtlas(glyph, scaler)) {
goto HAS_ATLAS;
}
fContext->flush();
// we should have an unused plot now
- if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
+ if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) &&
fStrike->addGlyphToAtlas(glyph, scaler)) {
goto HAS_ATLAS;
}
SkSafeUnref(fKey);
}
-GrMaskFormat GrFontScaler::getMaskFormat() {
+GrMaskFormat GrFontScaler::getMaskFormat() const {
SkMask::Format format = fStrike->getMaskFormat();
switch (format) {
case SkMask::kBW_Format:
return fKey;
}
+GrMaskFormat GrFontScaler::getPackedGlyphMaskFormat(GrGlyph::PackedID packed) const {
+ const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
+ GrGlyph::UnpackFixedX(packed),
+ GrGlyph::UnpackFixedY(packed));
+ SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat);
+ switch (format) {
+ case SkMask::kBW_Format:
+ // fall through to kA8 -- we store BW glyphs in our 8-bit cache
+ case SkMask::kA8_Format:
+ return kA8_GrMaskFormat;
+ case SkMask::kLCD16_Format:
+ return kA565_GrMaskFormat;
+ case SkMask::kLCD32_Format:
+ return kA888_GrMaskFormat;
+ case SkMask::kARGB32_Format:
+ return kARGB_GrMaskFormat;
+ default:
+ SkDEBUGFAIL("unsupported SkMask::Format");
+ return kA8_GrMaskFormat;
+ }
+}
+
bool GrFontScaler::getPackedGlyphBounds(GrGlyph::PackedID packed, SkIRect* bounds) {
const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
GrGlyph::UnpackFixedX(packed),
}
GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler) {
- GrMaskFormat format = scaler->getMaskFormat();
- GrPixelConfig config = mask_format_to_pixel_config(format);
- int atlasIndex = mask_format_to_atlas_index(format);
- if (NULL == fAtlases[atlasIndex]) {
- SkISize textureSize = SkISize::Make(GR_ATLAS_TEXTURE_WIDTH,
- GR_ATLAS_TEXTURE_HEIGHT);
- fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config, kNone_GrTextureFlags,
- textureSize,
- GR_NUM_PLOTS_X,
- GR_NUM_PLOTS_Y,
- true));
- }
- GrTextStrike* strike = SkNEW_ARGS(GrTextStrike,
- (this, scaler->getKey(), format, fAtlases[atlasIndex]));
+ GrTextStrike* strike = SkNEW_ARGS(GrTextStrike, (this, scaler->getKey()));
fCache.add(strike);
if (fHead) {
delete strike;
}
-bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike) {
+
+GrPlot* GrFontCache::addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* usage,
+ int width, int height, const void* image,
+ SkIPoint16* loc) {
+ GrPixelConfig config = mask_format_to_pixel_config(format);
+ int atlasIndex = mask_format_to_atlas_index(format);
+ if (NULL == fAtlases[atlasIndex]) {
+ SkISize textureSize = SkISize::Make(GR_ATLAS_TEXTURE_WIDTH,
+ GR_ATLAS_TEXTURE_HEIGHT);
+ fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config, kNone_GrTextureFlags,
+ textureSize,
+ GR_NUM_PLOTS_X,
+ GR_NUM_PLOTS_Y,
+ true));
+ }
+ return fAtlases[atlasIndex]->addToAtlas(usage, width, height, image, loc);
+}
+
+
+bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* glyph) {
SkASSERT(preserveStrike);
- GrAtlas* atlas = preserveStrike->fAtlas;
+ int index = mask_format_to_atlas_index(glyph->fMaskFormat);
+ GrAtlas* atlas = fAtlases[index];
GrPlot* plot = atlas->getUnusedPlot();
if (NULL == plot) {
return false;
plot->resetRects();
GrTextStrike* strike = fHead;
- GrMaskFormat maskFormat = preserveStrike->fMaskFormat;
while (strike) {
- if (maskFormat != strike->fMaskFormat) {
- strike = strike->fNext;
- continue;
- }
-
GrTextStrike* strikeToPurge = strike;
strike = strikeToPurge->fNext;
strikeToPurge->removePlot(plot);
atlas and a position within that texture.
*/
-GrTextStrike::GrTextStrike(GrFontCache* cache, const GrFontDescKey* key,
- GrMaskFormat format,
- GrAtlas* atlas) : fPool(64) {
+GrTextStrike::GrTextStrike(GrFontCache* cache, const GrFontDescKey* key) : fPool(64) {
fFontScalerKey = key;
fFontScalerKey->ref();
fFontCache = cache; // no need to ref, it won't go away before we do
- fAtlas = atlas; // no need to ref, it won't go away before we do
-
- fMaskFormat = format;
#ifdef SK_DEBUG
// GrPrintf(" GrTextStrike %p %d\n", this, gCounter);
return NULL;
}
}
-
+ GrMaskFormat format = scaler->getPackedGlyphMaskFormat(packed);
+
GrGlyph* glyph = fPool.alloc();
- glyph->init(packed, bounds);
+ glyph->init(packed, bounds, format);
fCache.add(glyph);
return glyph;
}
SkAutoUnref ar(SkSafeRef(scaler));
- int bytesPerPixel = GrMaskFormatBytesPerPixel(fMaskFormat);
+ int bytesPerPixel = GrMaskFormatBytesPerPixel(glyph->fMaskFormat);
size_t size = glyph->fBounds.area() * bytesPerPixel;
GrAutoMalloc<1024> storage(size);
}
}
- GrPlot* plot = fAtlas->addToAtlas(&fPlotUsage, glyph->width(),
- glyph->height(), storage.get(),
- &glyph->fAtlasLocation);
+ GrPlot* plot = fFontCache->addToAtlas(glyph->fMaskFormat, &fPlotUsage,
+ glyph->width(), glyph->height(),
+ storage.get(), &glyph->fAtlasLocation);
if (NULL == plot) {
return false;
class GrFontPurgeListener;
/**
- * The textcache maps a hostfontscaler instance to a dictionary of
+ * The textstrike maps a hostfontscaler instance to a dictionary of
* glyphid->strike
*/
class GrTextStrike {
public:
- GrTextStrike(GrFontCache*, const GrFontDescKey* fontScalerKey, GrMaskFormat, GrAtlas*);
+ GrTextStrike(GrFontCache*, const GrFontDescKey* fontScalerKey);
~GrTextStrike();
const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; }
GrFontCache* getFontCache() const { return fFontCache; }
- GrMaskFormat getMaskFormat() const { return fMaskFormat; }
- GrTexture* getTexture() const { return fAtlas->getTexture(); }
inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*);
// returns true if glyph (or glyph+padding for distance field)
GrTAllocPool<GrGlyph> fPool;
GrFontCache* fFontCache;
- GrAtlas* fAtlas;
- GrMaskFormat fMaskFormat;
bool fUseDistanceField;
GrAtlas::ClientPlotUsage fPlotUsage;
inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField);
+ // add to texture atlas that matches this format
+ GrPlot* addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* usage,
+ int width, int height, const void* image,
+ SkIPoint16* loc);
+
void freeAll();
- // make an unused plot available
- bool freeUnusedPlot(GrTextStrike* preserveStrike);
+ // make an unused plot available for this glyph
+ bool freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* glyph);
// testing
int countStrikes() const { return fCache.count(); }