diff options
author | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-27 00:09:42 +0000 |
---|---|---|
committer | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-27 00:09:42 +0000 |
commit | ae2c20f398933a9e86c387dcc465ec0f71065ffc (patch) | |
tree | de668b1411e2ee0b4e49b6d8f8b68183134ac990 /skia/gl/SkGLTextCache.h | |
parent | 09911bf300f1a419907a9412154760efd0b7abc3 (diff) | |
download | chromium_src-ae2c20f398933a9e86c387dcc465ec0f71065ffc.zip chromium_src-ae2c20f398933a9e86c387dcc465ec0f71065ffc.tar.gz chromium_src-ae2c20f398933a9e86c387dcc465ec0f71065ffc.tar.bz2 |
Add skia to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/gl/SkGLTextCache.h')
-rw-r--r-- | skia/gl/SkGLTextCache.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/skia/gl/SkGLTextCache.h b/skia/gl/SkGLTextCache.h new file mode 100644 index 0000000..386b274 --- /dev/null +++ b/skia/gl/SkGLTextCache.h @@ -0,0 +1,83 @@ +#ifndef SkGLTextCache_DEFINED +#define SkGLTextCache_DEFINED + +#include "SkGL.h" + +class SkGlyph; + +class SkGLTextCache { +public: + SkGLTextCache(); + ~SkGLTextCache(); + + void* getCtx() const { return fCtx; } + + class Strike { + public: + int width() const { return fStrikeWidth; } + int height() const { return fStrikeHeight; } + GLuint texture() const { return fTexName; } + int widthShift() const { return fStrikeWidthShift; } + int heightShift() const { return fStrikeHeightShift; } + + // call this to force us to ignore the texture name in our destructor + // only call it right before our destructor + void zapTexture() { fTexName = 0; } + + private: + // if next is non-null, its height must match our height + Strike(Strike* next, int width, int height); + ~Strike(); + + Strike* findGlyph(const SkGlyph&, int* offset); + Strike* addGlyphAndBind(const SkGlyph&, const uint8_t*, int* offset); + + enum { + kMinStrikeWidth = 1024, + kMaxGlyphCount = 256 + }; + + Strike* fNext; + GLuint fTexName; + uint32_t fGlyphIDArray[kMaxGlyphCount]; // stores glyphIDs + uint16_t fGlyphOffsetX[kMaxGlyphCount]; // stores x-offsets + uint16_t fGlyphCount; + uint16_t fNextFreeOffsetX; + uint16_t fStrikeWidth; + uint16_t fStrikeHeight; + uint8_t fStrikeWidthShift; // pow2(fStrikeWidth) + uint8_t fStrikeHeightShift; // pow2(fStrikeHeight) + + friend class SkGLTextCache; + }; + + /** If found, returns the exact strike containing it (there may be more than + one with a given height), and sets offset to the offset for that glyph + (if not null). Does NOT bind the texture. + If not found, returns null and ignores offset param. + */ + Strike* findGlyph(const SkGlyph&, int* offset); + + /** Adds the specified glyph to this list of strikes, returning the new + head of the list. If offset is not null, it is set to the offset + for this glyph within the strike. The associated texture is bound + to the gl context. + */ + Strike* addGlyphAndBind(const SkGlyph&, const uint8_t image[], int* offset); + +private: + void* fCtx; + + enum { + // greater than this we won't cache + kMaxGlyphHeightShift = 9, + + kMaxGlyphHeight = 1 << kMaxGlyphHeightShift, + kMaxStrikeListCount = kMaxGlyphHeightShift + 1 + }; + + // heads of the N families, one for each pow2 height + Strike* fStrikeList[kMaxStrikeListCount]; +}; + +#endif |