blob: e359e267cf9816877a1db4d52011a4dc5b59efeb [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
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000049 // returns true if an atlas was removed
50 bool removeUnusedAtlases();
51
reed@google.comac10a2d2010-12-22 21:39:39 +000052public:
53 // for LRU
54 GrTextStrike* fPrev;
55 GrTextStrike* fNext;
56
57private:
58 class Key;
59 GrTHashTable<GrGlyph, Key, 7> fCache;
60 const GrKey* fFontScalerKey;
61 GrTAllocPool<GrGlyph> fPool;
62
63 GrFontCache* fFontCache;
64 GrAtlasMgr* fAtlasMgr;
65 GrAtlas* fAtlas; // linklist
66
reed@google.com98539c62011-03-15 15:40:16 +000067 GrMaskFormat fMaskFormat;
68
reed@google.comac10a2d2010-12-22 21:39:39 +000069 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();
reed@google.comac10a2d2010-12-22 21:39:39 +000084
85 void purgeExceptFor(GrTextStrike*);
86
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000087 // remove an unused atlas and its strike (if necessary)
88 void freeAtlasExceptFor(GrTextStrike*);
89
reed@google.comac10a2d2010-12-22 21:39:39 +000090 // testing
91 int countStrikes() const { return fCache.getArray().count(); }
92 const GrTextStrike* strikeAt(int index) const {
93 return fCache.getArray()[index];
94 }
95 GrTextStrike* getHeadStrike() const { return fHead; }
96
97#if GR_DEBUG
98 void validate() const;
99#else
100 void validate() const {}
101#endif
102
103private:
104 friend class GrFontPurgeListener;
105
106 class Key;
107 GrTHashTable<GrTextStrike, Key, 8> fCache;
108 // for LRU
109 GrTextStrike* fHead;
110 GrTextStrike* fTail;
111
112 GrGpu* fGpu;
113 GrAtlasMgr* fAtlasMgr;
114
reed@google.com98539c62011-03-15 15:40:16 +0000115
reed@google.comac10a2d2010-12-22 21:39:39 +0000116 GrTextStrike* generateStrike(GrFontScaler*, const Key&);
117 inline void detachStrikeFromList(GrTextStrike*);
118};
119
120#endif