gfx/skia/trunk/src/gpu/GrTextStrike.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2010 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10
michael@0 11 #ifndef GrTextStrike_DEFINED
michael@0 12 #define GrTextStrike_DEFINED
michael@0 13
michael@0 14 #include "GrAllocPool.h"
michael@0 15 #include "GrFontScaler.h"
michael@0 16 #include "GrTHashTable.h"
michael@0 17 #include "GrPoint.h"
michael@0 18 #include "GrGlyph.h"
michael@0 19 #include "GrDrawTarget.h"
michael@0 20 #include "GrAtlas.h"
michael@0 21
michael@0 22 class GrFontCache;
michael@0 23 class GrGpu;
michael@0 24 class GrFontPurgeListener;
michael@0 25
michael@0 26 /**
michael@0 27 * The textcache maps a hostfontscaler instance to a dictionary of
michael@0 28 * glyphid->strike
michael@0 29 */
michael@0 30 class GrTextStrike {
michael@0 31 public:
michael@0 32 GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, GrAtlasMgr*);
michael@0 33 ~GrTextStrike();
michael@0 34
michael@0 35 const GrKey* getFontScalerKey() const { return fFontScalerKey; }
michael@0 36 GrFontCache* getFontCache() const { return fFontCache; }
michael@0 37 GrMaskFormat getMaskFormat() const { return fMaskFormat; }
michael@0 38
michael@0 39 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*);
michael@0 40 bool addGlyphToAtlas(GrGlyph*, GrFontScaler*);
michael@0 41
michael@0 42 SkISize getAtlasSize() const { return fAtlas.getSize(); }
michael@0 43
michael@0 44 // testing
michael@0 45 int countGlyphs() const { return fCache.getArray().count(); }
michael@0 46 const GrGlyph* glyphAt(int index) const {
michael@0 47 return fCache.getArray()[index];
michael@0 48 }
michael@0 49
michael@0 50 // remove any references to this plot
michael@0 51 void removePlot(const GrPlot* plot);
michael@0 52
michael@0 53 public:
michael@0 54 // for easy removal from list
michael@0 55 GrTextStrike* fPrev;
michael@0 56 GrTextStrike* fNext;
michael@0 57
michael@0 58 private:
michael@0 59 class Key;
michael@0 60 GrTHashTable<GrGlyph, Key, 7> fCache;
michael@0 61 const GrKey* fFontScalerKey;
michael@0 62 GrTAllocPool<GrGlyph> fPool;
michael@0 63
michael@0 64 GrFontCache* fFontCache;
michael@0 65 GrAtlasMgr* fAtlasMgr;
michael@0 66 GrMaskFormat fMaskFormat;
michael@0 67 bool fUseDistanceField;
michael@0 68
michael@0 69 GrAtlas fAtlas;
michael@0 70
michael@0 71 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
michael@0 72
michael@0 73 friend class GrFontCache;
michael@0 74 };
michael@0 75
michael@0 76 class GrFontCache {
michael@0 77 public:
michael@0 78 GrFontCache(GrGpu*);
michael@0 79 ~GrFontCache();
michael@0 80
michael@0 81 inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField);
michael@0 82
michael@0 83 void freeAll();
michael@0 84
michael@0 85 // make an unused plot available
michael@0 86 bool freeUnusedPlot(GrTextStrike* preserveStrike);
michael@0 87
michael@0 88 // testing
michael@0 89 int countStrikes() const { return fCache.getArray().count(); }
michael@0 90 const GrTextStrike* strikeAt(int index) const {
michael@0 91 return fCache.getArray()[index];
michael@0 92 }
michael@0 93 GrTextStrike* getHeadStrike() const { return fHead; }
michael@0 94
michael@0 95 #ifdef SK_DEBUG
michael@0 96 void validate() const;
michael@0 97 #else
michael@0 98 void validate() const {}
michael@0 99 #endif
michael@0 100
michael@0 101 #ifdef SK_DEVELOPER
michael@0 102 void dump() const;
michael@0 103 #endif
michael@0 104
michael@0 105 enum AtlasType {
michael@0 106 kA8_AtlasType, //!< 1-byte per pixel
michael@0 107 k565_AtlasType, //!< 2-bytes per pixel
michael@0 108 k8888_AtlasType, //!< 4-bytes per pixel
michael@0 109
michael@0 110 kLast_AtlasType = k8888_AtlasType
michael@0 111 };
michael@0 112 static const int kAtlasCount = kLast_AtlasType + 1;
michael@0 113
michael@0 114 private:
michael@0 115 friend class GrFontPurgeListener;
michael@0 116
michael@0 117 class Key;
michael@0 118 GrTHashTable<GrTextStrike, Key, 8> fCache;
michael@0 119 // for LRU
michael@0 120 GrTextStrike* fHead;
michael@0 121 GrTextStrike* fTail;
michael@0 122
michael@0 123 GrGpu* fGpu;
michael@0 124 GrAtlasMgr* fAtlasMgr[kAtlasCount];
michael@0 125
michael@0 126 GrTextStrike* generateStrike(GrFontScaler*, const Key&);
michael@0 127 inline void detachStrikeFromList(GrTextStrike*);
michael@0 128 void purgeStrike(GrTextStrike* strike);
michael@0 129 };
michael@0 130
michael@0 131 #endif

mercurial