blob: 2bdcc90ebe4c73d53c985519d1b8dec6bb44f738 [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:
reed@google.com98539c62011-03-15 15:40:16 +000038 GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat,
39 GrAtlasMgr*);
reed@google.comac10a2d2010-12-22 21:39:39 +000040 ~GrTextStrike();
41
42 const GrKey* getFontScalerKey() const { return fFontScalerKey; }
43 GrFontCache* getFontCache() const { return fFontCache; }
reed@google.com98539c62011-03-15 15:40:16 +000044 GrMaskFormat getMaskFormat() const { return fMaskFormat; }
reed@google.comac10a2d2010-12-22 21:39:39 +000045
46 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*);
47 bool getGlyphAtlas(GrGlyph*, GrFontScaler*);
48
49 // testing
50 int countGlyphs() const { return fCache.getArray().count(); }
51 const GrGlyph* glyphAt(int index) const {
52 return fCache.getArray()[index];
53 }
54 GrAtlas* getAtlas() const { return fAtlas; }
55
56public:
57 // for LRU
58 GrTextStrike* fPrev;
59 GrTextStrike* fNext;
60
61private:
62 class Key;
63 GrTHashTable<GrGlyph, Key, 7> fCache;
64 const GrKey* fFontScalerKey;
65 GrTAllocPool<GrGlyph> fPool;
66
67 GrFontCache* fFontCache;
68 GrAtlasMgr* fAtlasMgr;
69 GrAtlas* fAtlas; // linklist
70
reed@google.com98539c62011-03-15 15:40:16 +000071 GrMaskFormat fMaskFormat;
72
reed@google.comac10a2d2010-12-22 21:39:39 +000073 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
74 // returns true if after the purge, the strike is empty
75 bool purgeAtlasAtY(GrAtlas* atlas, int yCoord);
76
77 friend class GrFontCache;
78};
79
80class GrFontCache {
81public:
82 GrFontCache(GrGpu*);
83 ~GrFontCache();
84
85 inline GrTextStrike* getStrike(GrFontScaler*);
86
87 void freeAll();
reed@google.comac10a2d2010-12-22 21:39:39 +000088
89 void purgeExceptFor(GrTextStrike*);
90
91 // testing
92 int countStrikes() const { return fCache.getArray().count(); }
93 const GrTextStrike* strikeAt(int index) const {
94 return fCache.getArray()[index];
95 }
96 GrTextStrike* getHeadStrike() const { return fHead; }
97
98#if GR_DEBUG
99 void validate() const;
100#else
101 void validate() const {}
102#endif
103
104private:
105 friend class GrFontPurgeListener;
106
107 class Key;
108 GrTHashTable<GrTextStrike, Key, 8> fCache;
109 // for LRU
110 GrTextStrike* fHead;
111 GrTextStrike* fTail;
112
113 GrGpu* fGpu;
114 GrAtlasMgr* fAtlasMgr;
115
reed@google.com98539c62011-03-15 15:40:16 +0000116
reed@google.comac10a2d2010-12-22 21:39:39 +0000117 GrTextStrike* generateStrike(GrFontScaler*, const Key&);
118 inline void detachStrikeFromList(GrTextStrike*);
119};
120
121#endif
122