blob: abafa571303688ec839885a0362500e5e52a369b [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
2 Copyright 2010 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17
18#ifndef GrTextStrike_DEFINED
19#define GrTextStrike_DEFINED
20
21#include "GrAllocPool.h"
22#include "GrFontScaler.h"
23#include "GrTHashCache.h"
24#include "GrPoint.h"
25#include "GrGlyph.h"
26
27class GrAtlasMgr;
28class GrFontCache;
29class GrGpu;
30class GrFontPurgeListener;
31
32/**
33 * The textcache maps a hostfontscaler instance to a dictionary of
34 * glyphid->strike
35 */
36class GrTextStrike {
37public:
38 GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrAtlasMgr*);
39 ~GrTextStrike();
40
41 const GrKey* getFontScalerKey() const { return fFontScalerKey; }
42 GrFontCache* getFontCache() const { return fFontCache; }
43
44 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*);
45 bool getGlyphAtlas(GrGlyph*, GrFontScaler*);
46
47 // testing
48 int countGlyphs() const { return fCache.getArray().count(); }
49 const GrGlyph* glyphAt(int index) const {
50 return fCache.getArray()[index];
51 }
52 GrAtlas* getAtlas() const { return fAtlas; }
53
54public:
55 // for LRU
56 GrTextStrike* fPrev;
57 GrTextStrike* fNext;
58
59private:
60 class Key;
61 GrTHashTable<GrGlyph, Key, 7> fCache;
62 const GrKey* fFontScalerKey;
63 GrTAllocPool<GrGlyph> fPool;
64
65 GrFontCache* fFontCache;
66 GrAtlasMgr* fAtlasMgr;
67 GrAtlas* fAtlas; // linklist
68
69 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
70 // returns true if after the purge, the strike is empty
71 bool purgeAtlasAtY(GrAtlas* atlas, int yCoord);
72
73 friend class GrFontCache;
74};
75
76class GrFontCache {
77public:
78 GrFontCache(GrGpu*);
79 ~GrFontCache();
80
81 inline GrTextStrike* getStrike(GrFontScaler*);
82
83 void freeAll();
84 void abandonAll();
85
86 void purgeExceptFor(GrTextStrike*);
87
88 // testing
89 int countStrikes() const { return fCache.getArray().count(); }
90 const GrTextStrike* strikeAt(int index) const {
91 return fCache.getArray()[index];
92 }
93 GrTextStrike* getHeadStrike() const { return fHead; }
94
95#if GR_DEBUG
96 void validate() const;
97#else
98 void validate() const {}
99#endif
100
101private:
102 friend class GrFontPurgeListener;
103
104 class Key;
105 GrTHashTable<GrTextStrike, Key, 8> fCache;
106 // for LRU
107 GrTextStrike* fHead;
108 GrTextStrike* fTail;
109
110 GrGpu* fGpu;
111 GrAtlasMgr* fAtlasMgr;
112
113
114 GrTextStrike* generateStrike(GrFontScaler*, const Key&);
115 inline void detachStrikeFromList(GrTextStrike*);
116};
117
118#endif
119