## 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() const;
- GrMaskFormat getPackedGlyphMaskFormat(GrGlyph::PackedID) const;
+ GrMaskFormat getMaskFormat();
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 "GrTypes.h"
-
-#include "SkChecksum.h"
#include "SkPath.h"
+#include "SkChecksum.h"
class GrPlot;
struct GrGlyph {
typedef uint32_t PackedID;
- GrPlot* fPlot;
- SkPath* fPath;
- PackedID fPackedID;
- GrMaskFormat fMaskFormat;
- GrIRect16 fBounds;
- SkIPoint16 fAtlasLocation;
+ GrPlot* fPlot;
+ SkPath* fPath;
+ PackedID fPackedID;
+ GrIRect16 fBounds;
+ SkIPoint16 fAtlasLocation;
- void init(GrGlyph::PackedID packed, const SkIRect& bounds, GrMaskFormat format) {
+ void init(GrGlyph::PackedID packed, const SkIRect& bounds) {
fPlot = NULL;
fPath = NULL;
fPackedID = packed;
fBounds.set(bounds);
- fMaskFormat = format;
fAtlasLocation.set(0, 0);
}
}
// try to clear out an unused plot before we flush
- if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) &&
+ if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
fStrike->addGlyphToAtlas(glyph, scaler)) {
goto HAS_ATLAS;
}
fContext->flush();
// we should have an unused plot now
- if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) &&
+ if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
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 == fCurrMaskFormat;
+ bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat();
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 (fCurrMaskFormat) {
+ switch (fStrike->getMaskFormat()) {
// Color bitmap text
case kARGB_GrMaskFormat:
SkASSERT(!drawState->hasColorVertexAttribute());
drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlendCoeff());
- drawState->setAlpha(fSkPaint.getAlpha());
+ drawState->setColor(0xffffffff);
break;
// LCD text
case kA888_GrMaskFormat:
SkASSERT(drawState->hasColorVertexAttribute());
break;
default:
- SkFAIL("Unexpected mask format.");
+ SkFAIL("Unexepected mask format.");
}
int nGlyphs = fCurrVertex / 4;
fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
GrTextStrike* fStrike;
void* fVertices;
- int fCurrVertex;
- int fMaxVertices;
- SkRect fVertexBounds;
+ int32_t fMaxVertices;
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, glyph) &&
+ if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
fStrike->addGlyphToAtlas(glyph, scaler)) {
goto HAS_ATLAS;
}
fContext->flush();
// we should have an unused plot now
- if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) &&
+ if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
fStrike->addGlyphToAtlas(glyph, scaler)) {
goto HAS_ATLAS;
}
SkSafeUnref(fKey);
}
-GrMaskFormat GrFontScaler::getMaskFormat() const {
+GrMaskFormat GrFontScaler::getMaskFormat() {
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) {
- GrTextStrike* strike = SkNEW_ARGS(GrTextStrike, (this, scaler->getKey()));
+ 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]));
fCache.add(strike);
if (fHead) {
delete strike;
}
-
-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) {
+bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike) {
SkASSERT(preserveStrike);
- int index = mask_format_to_atlas_index(glyph->fMaskFormat);
- GrAtlas* atlas = fAtlases[index];
+ GrAtlas* atlas = preserveStrike->fAtlas;
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) : fPool(64) {
+GrTextStrike::GrTextStrike(GrFontCache* cache, const GrFontDescKey* key,
+ GrMaskFormat format,
+ GrAtlas* atlas) : 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, format);
+ glyph->init(packed, bounds);
fCache.add(glyph);
return glyph;
}
SkAutoUnref ar(SkSafeRef(scaler));
- int bytesPerPixel = GrMaskFormatBytesPerPixel(glyph->fMaskFormat);
+ int bytesPerPixel = GrMaskFormatBytesPerPixel(fMaskFormat);
size_t size = glyph->fBounds.area() * bytesPerPixel;
GrAutoMalloc<1024> storage(size);
}
}
- GrPlot* plot = fFontCache->addToAtlas(glyph->fMaskFormat, &fPlotUsage,
- glyph->width(), glyph->height(),
- storage.get(), &glyph->fAtlasLocation);
+ GrPlot* plot = fAtlas->addToAtlas(&fPlotUsage, glyph->width(),
+ glyph->height(), storage.get(),
+ &glyph->fAtlasLocation);
if (NULL == plot) {
return false;
class GrFontPurgeListener;
/**
- * The textstrike maps a hostfontscaler instance to a dictionary of
+ * The textcache maps a hostfontscaler instance to a dictionary of
* glyphid->strike
*/
class GrTextStrike {
public:
- GrTextStrike(GrFontCache*, const GrFontDescKey* fontScalerKey);
+ GrTextStrike(GrFontCache*, const GrFontDescKey* fontScalerKey, GrMaskFormat, GrAtlas*);
~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 for this glyph
- bool freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* glyph);
+ // make an unused plot available
+ bool freeUnusedPlot(GrTextStrike* preserveStrike);
// testing
int countStrikes() const { return fCache.count(); }