michael@0: michael@0: /* michael@0: * Copyright 2010 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: michael@0: #ifndef GrTextStrike_DEFINED michael@0: #define GrTextStrike_DEFINED michael@0: michael@0: #include "GrAllocPool.h" michael@0: #include "GrFontScaler.h" michael@0: #include "GrTHashTable.h" michael@0: #include "GrPoint.h" michael@0: #include "GrGlyph.h" michael@0: #include "GrDrawTarget.h" michael@0: #include "GrAtlas.h" michael@0: michael@0: class GrFontCache; michael@0: class GrGpu; michael@0: class GrFontPurgeListener; michael@0: michael@0: /** michael@0: * The textcache maps a hostfontscaler instance to a dictionary of michael@0: * glyphid->strike michael@0: */ michael@0: class GrTextStrike { michael@0: public: michael@0: GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, GrAtlasMgr*); michael@0: ~GrTextStrike(); michael@0: michael@0: const GrKey* getFontScalerKey() const { return fFontScalerKey; } michael@0: GrFontCache* getFontCache() const { return fFontCache; } michael@0: GrMaskFormat getMaskFormat() const { return fMaskFormat; } michael@0: michael@0: inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*); michael@0: bool addGlyphToAtlas(GrGlyph*, GrFontScaler*); michael@0: michael@0: SkISize getAtlasSize() const { return fAtlas.getSize(); } michael@0: michael@0: // testing michael@0: int countGlyphs() const { return fCache.getArray().count(); } michael@0: const GrGlyph* glyphAt(int index) const { michael@0: return fCache.getArray()[index]; michael@0: } michael@0: michael@0: // remove any references to this plot michael@0: void removePlot(const GrPlot* plot); michael@0: michael@0: public: michael@0: // for easy removal from list michael@0: GrTextStrike* fPrev; michael@0: GrTextStrike* fNext; michael@0: michael@0: private: michael@0: class Key; michael@0: GrTHashTable fCache; michael@0: const GrKey* fFontScalerKey; michael@0: GrTAllocPool fPool; michael@0: michael@0: GrFontCache* fFontCache; michael@0: GrAtlasMgr* fAtlasMgr; michael@0: GrMaskFormat fMaskFormat; michael@0: bool fUseDistanceField; michael@0: michael@0: GrAtlas fAtlas; michael@0: michael@0: GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); michael@0: michael@0: friend class GrFontCache; michael@0: }; michael@0: michael@0: class GrFontCache { michael@0: public: michael@0: GrFontCache(GrGpu*); michael@0: ~GrFontCache(); michael@0: michael@0: inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField); michael@0: michael@0: void freeAll(); michael@0: michael@0: // make an unused plot available michael@0: bool freeUnusedPlot(GrTextStrike* preserveStrike); michael@0: michael@0: // testing michael@0: int countStrikes() const { return fCache.getArray().count(); } michael@0: const GrTextStrike* strikeAt(int index) const { michael@0: return fCache.getArray()[index]; michael@0: } michael@0: GrTextStrike* getHeadStrike() const { return fHead; } michael@0: michael@0: #ifdef SK_DEBUG michael@0: void validate() const; michael@0: #else michael@0: void validate() const {} michael@0: #endif michael@0: michael@0: #ifdef SK_DEVELOPER michael@0: void dump() const; michael@0: #endif michael@0: michael@0: enum AtlasType { michael@0: kA8_AtlasType, //!< 1-byte per pixel michael@0: k565_AtlasType, //!< 2-bytes per pixel michael@0: k8888_AtlasType, //!< 4-bytes per pixel michael@0: michael@0: kLast_AtlasType = k8888_AtlasType michael@0: }; michael@0: static const int kAtlasCount = kLast_AtlasType + 1; michael@0: michael@0: private: michael@0: friend class GrFontPurgeListener; michael@0: michael@0: class Key; michael@0: GrTHashTable fCache; michael@0: // for LRU michael@0: GrTextStrike* fHead; michael@0: GrTextStrike* fTail; michael@0: michael@0: GrGpu* fGpu; michael@0: GrAtlasMgr* fAtlasMgr[kAtlasCount]; michael@0: michael@0: GrTextStrike* generateStrike(GrFontScaler*, const Key&); michael@0: inline void detachStrikeFromList(GrTextStrike*); michael@0: void purgeStrike(GrTextStrike* strike); michael@0: }; michael@0: michael@0: #endif