blob: 701acea7abc17025938073d3d03a530d56905d29 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#ifndef GrTextStrike_DEFINED
12#define GrTextStrike_DEFINED
13
14#include "GrAllocPool.h"
15#include "GrFontScaler.h"
16#include "GrTHashCache.h"
17#include "GrPoint.h"
18#include "GrGlyph.h"
19
20class GrAtlasMgr;
21class GrFontCache;
22class GrGpu;
23class GrFontPurgeListener;
24
25/**
26 * The textcache maps a hostfontscaler instance to a dictionary of
27 * glyphid->strike
28 */
29class GrTextStrike {
30public:
reed@google.com98539c62011-03-15 15:40:16 +000031 GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat,
32 GrAtlasMgr*);
reed@google.comac10a2d2010-12-22 21:39:39 +000033 ~GrTextStrike();
34
35 const GrKey* getFontScalerKey() const { return fFontScalerKey; }
36 GrFontCache* getFontCache() const { return fFontCache; }
reed@google.com98539c62011-03-15 15:40:16 +000037 GrMaskFormat getMaskFormat() const { return fMaskFormat; }
reed@google.comac10a2d2010-12-22 21:39:39 +000038
39 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*);
40 bool getGlyphAtlas(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 GrAtlas* getAtlas() const { return fAtlas; }
48
49public:
50 // for LRU
51 GrTextStrike* fPrev;
52 GrTextStrike* fNext;
53
54private:
55 class Key;
56 GrTHashTable<GrGlyph, Key, 7> fCache;
57 const GrKey* fFontScalerKey;
58 GrTAllocPool<GrGlyph> fPool;
59
60 GrFontCache* fFontCache;
61 GrAtlasMgr* fAtlasMgr;
62 GrAtlas* fAtlas; // linklist
63
reed@google.com98539c62011-03-15 15:40:16 +000064 GrMaskFormat fMaskFormat;
65
reed@google.comac10a2d2010-12-22 21:39:39 +000066 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
67 // returns true if after the purge, the strike is empty
68 bool purgeAtlasAtY(GrAtlas* atlas, int yCoord);
69
70 friend class GrFontCache;
71};
72
73class GrFontCache {
74public:
75 GrFontCache(GrGpu*);
76 ~GrFontCache();
77
78 inline GrTextStrike* getStrike(GrFontScaler*);
79
80 void freeAll();
reed@google.comac10a2d2010-12-22 21:39:39 +000081
82 void purgeExceptFor(GrTextStrike*);
83
84 // testing
85 int countStrikes() const { return fCache.getArray().count(); }
86 const GrTextStrike* strikeAt(int index) const {
87 return fCache.getArray()[index];
88 }
89 GrTextStrike* getHeadStrike() const { return fHead; }
90
91#if GR_DEBUG
92 void validate() const;
93#else
94 void validate() const {}
95#endif
96
97private:
98 friend class GrFontPurgeListener;
99
100 class Key;
101 GrTHashTable<GrTextStrike, Key, 8> fCache;
102 // for LRU
103 GrTextStrike* fHead;
104 GrTextStrike* fTail;
105
106 GrGpu* fGpu;
107 GrAtlasMgr* fAtlasMgr;
108
reed@google.com98539c62011-03-15 15:40:16 +0000109
reed@google.comac10a2d2010-12-22 21:39:39 +0000110 GrTextStrike* generateStrike(GrFontScaler*, const Key&);
111 inline void detachStrikeFromList(GrTextStrike*);
112};
113
114#endif
115