| Index: src/gpu/GrBatchFontCache.h
|
| diff --git a/src/gpu/GrBatchFontCache.h b/src/gpu/GrBatchFontCache.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7c9e68e3ffb9e3bfa4986839e0e9546c65d926d1
|
| --- /dev/null
|
| +++ b/src/gpu/GrBatchFontCache.h
|
| @@ -0,0 +1,151 @@
|
| +/*
|
| + * Copyright 2015 Google Inc.
|
| + *
|
| + * Use of this source code is governed by a BSD-style license that can be
|
| + * found in the LICENSE file.
|
| + */
|
| +
|
| +#ifndef GrBatchFontCache_DEFINED
|
| +#define GrBatchFontCache_DEFINED
|
| +
|
| +#include "GrBatchAtlas.h"
|
| +#include "GrDrawTarget.h"
|
| +#include "GrFontScaler.h"
|
| +#include "GrGlyph.h"
|
| +#include "SkTDynamicHash.h"
|
| +#include "SkVarAlloc.h"
|
| +
|
| +class GrBatchFontCache;
|
| +class GrBatchTarget;
|
| +class GrGpu;
|
| +
|
| +/**
|
| + * The textstrike maps a hostfontscaler instance to a dictionary of
|
| + * glyphid->strike
|
| + */
|
| +class GrBatchTextStrike {
|
| +public:
|
| + SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrBatchTextStrike);
|
| + GrBatchTextStrike(GrBatchFontCache*, const GrFontDescKey* fontScalerKey);
|
| + ~GrBatchTextStrike();
|
| +
|
| + const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; }
|
| + GrBatchFontCache* getBatchFontCache() const { return fBatchFontCache; }
|
| +
|
| + inline GrGlyph* getGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler) {
|
| + GrGlyph* glyph = fCache.find(packed);
|
| + if (NULL == glyph) {
|
| + glyph = this->generateGlyph(packed, scaler);
|
| + }
|
| + return glyph;
|
| + }
|
| +
|
| + // returns true if glyph (or glyph+padding for distance field)
|
| + // is too large to ever fit in texture atlas subregions (GrPlots)
|
| + bool glyphTooLargeForAtlas(GrGlyph*);
|
| + // returns true if glyph successfully added to texture atlas, false otherwise
|
| + bool addGlyphToAtlas(GrBatchTarget*, GrGlyph*, GrFontScaler*);
|
| +
|
| + // testing
|
| + int countGlyphs() const { return fCache.count(); }
|
| +
|
| + // remove any references to this plot
|
| + void removeID(GrBatchAtlas::AtlasID);
|
| +
|
| + static const GrFontDescKey& GetKey(const GrBatchTextStrike& ts) {
|
| + return *(ts.fFontScalerKey);
|
| + }
|
| + static uint32_t Hash(const GrFontDescKey& key) {
|
| + return key.getHash();
|
| + }
|
| +
|
| +private:
|
| + SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache;
|
| + SkAutoTUnref<const GrFontDescKey> fFontScalerKey;
|
| + SkVarAlloc fPool;
|
| +
|
| + GrBatchFontCache* fBatchFontCache;
|
| + int fAtlasedGlyphs;
|
| +
|
| + GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
|
| +
|
| + friend class GrBatchFontCache;
|
| +};
|
| +
|
| +class GrBatchFontCache {
|
| +public:
|
| + GrBatchFontCache(GrContext*);
|
| + ~GrBatchFontCache();
|
| +
|
| + inline GrBatchTextStrike* getStrike(GrFontScaler* scaler) {
|
| + SkDEBUGCODE(this->validate();)
|
| +
|
| + GrBatchTextStrike* strike = fCache.find(*(scaler->getKey()));
|
| + if (NULL == strike) {
|
| + strike = this->generateStrike(scaler);
|
| + } else {
|
| + this->makeMRU(strike);
|
| + }
|
| + SkDEBUGCODE(this->validate();)
|
| + return strike;
|
| + }
|
| +
|
| + bool hasGlyph(GrGlyph* glyph);
|
| + void refGlyph(GrGlyph*, GrBatchAtlas::BatchToken);
|
| +
|
| + // add to texture atlas that matches this format
|
| + bool addToAtlas(GrBatchTextStrike*, GrBatchAtlas::AtlasID*, GrBatchTarget*,
|
| + GrMaskFormat, int width, int height, const void* image,
|
| + SkIPoint16* loc);
|
| +
|
| + uint32_t atlasGeneration(GrMaskFormat) const;
|
| +
|
| + void freeAll();
|
| +
|
| + inline void makeMRU(GrBatchTextStrike* strike) {
|
| + if (fStrikeList.head() == strike) {
|
| + return;
|
| + }
|
| +
|
| + fStrikeList.remove(strike);
|
| + fStrikeList.addToHead(strike);
|
| + }
|
| +
|
| + GrTexture* getTexture(GrMaskFormat);
|
| + GrPixelConfig getPixelConfig(GrMaskFormat) const;
|
| +
|
| + SkDEBUGCODE(void validate() const;)
|
| +
|
| + void dump() const;
|
| +
|
| +private:
|
| + enum AtlasType {
|
| + kA8_AtlasType, //!< 1-byte per pixel
|
| + k565_AtlasType, //!< 2-bytes per pixel
|
| + k8888_AtlasType, //!< 4-bytes per pixel
|
| +
|
| + kLast_AtlasType = k8888_AtlasType
|
| + };
|
| +
|
| + static const int kAtlasCount = kLast_AtlasType + 1;
|
| +
|
| + static int MaskFormatToAtlasIndex(GrMaskFormat);
|
| + static GrMaskFormat AtlasIndexToMaskFormat(int atlasIndex);
|
| +
|
| + GrBatchTextStrike* generateStrike(GrFontScaler*);
|
| +
|
| + void purgeStrike(GrBatchTextStrike* strike);
|
| + inline GrBatchAtlas* getAtlas(GrMaskFormat) const;
|
| +
|
| + static void HandleEviction(GrBatchAtlas::AtlasID, void*);
|
| +
|
| + typedef SkTInternalLList<GrBatchTextStrike> GrBatchStrikeList;
|
| +
|
| + SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache;
|
| + GrBatchStrikeList fStrikeList;
|
| +
|
| + GrBatchAtlas* fAtlases[kAtlasCount];
|
| + GrBatchTextStrike* fPreserveStrike;
|
| +};
|
| +
|
| +#endif
|
|
|