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