blob: 7771e4a07c997937f8e6b2b5f47d8db9a8ece1cb [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"
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +000019#include "GrDrawTarget.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000020
21class GrAtlasMgr;
22class GrFontCache;
23class GrGpu;
24class GrFontPurgeListener;
25
26/**
27 * The textcache maps a hostfontscaler instance to a dictionary of
28 * glyphid->strike
29 */
30class GrTextStrike {
31public:
reed@google.com98539c62011-03-15 15:40:16 +000032 GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat,
33 GrAtlasMgr*);
reed@google.comac10a2d2010-12-22 21:39:39 +000034 ~GrTextStrike();
35
36 const GrKey* getFontScalerKey() const { return fFontScalerKey; }
37 GrFontCache* getFontCache() const { return fFontCache; }
reed@google.com98539c62011-03-15 15:40:16 +000038 GrMaskFormat getMaskFormat() const { return fMaskFormat; }
reed@google.comac10a2d2010-12-22 21:39:39 +000039
40 inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*);
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +000041 bool getGlyphAtlas(GrGlyph*, GrFontScaler*, GrDrawTarget::DrawToken currentDrawToken);
reed@google.comac10a2d2010-12-22 21:39:39 +000042
43 // testing
44 int countGlyphs() const { return fCache.getArray().count(); }
45 const GrGlyph* glyphAt(int index) const {
46 return fCache.getArray()[index];
47 }
48 GrAtlas* getAtlas() const { return fAtlas; }
49
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000050 // returns true if an atlas was removed
51 bool removeUnusedAtlases();
52
reed@google.comac10a2d2010-12-22 21:39:39 +000053public:
54 // for LRU
55 GrTextStrike* fPrev;
56 GrTextStrike* fNext;
57
58private:
59 class Key;
60 GrTHashTable<GrGlyph, Key, 7> fCache;
61 const GrKey* fFontScalerKey;
62 GrTAllocPool<GrGlyph> fPool;
63
64 GrFontCache* fFontCache;
65 GrAtlasMgr* fAtlasMgr;
66 GrAtlas* fAtlas; // linklist
67
reed@google.com98539c62011-03-15 15:40:16 +000068 GrMaskFormat fMaskFormat;
69
reed@google.comac10a2d2010-12-22 21:39:39 +000070 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
71 // returns true if after the purge, the strike is empty
72 bool purgeAtlasAtY(GrAtlas* atlas, int yCoord);
73
74 friend class GrFontCache;
75};
76
77class GrFontCache {
78public:
79 GrFontCache(GrGpu*);
80 ~GrFontCache();
81
82 inline GrTextStrike* getStrike(GrFontScaler*);
83
84 void freeAll();
reed@google.comac10a2d2010-12-22 21:39:39 +000085
86 void purgeExceptFor(GrTextStrike*);
87
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000088 // remove an unused atlas and its strike (if necessary)
89 void freeAtlasExceptFor(GrTextStrike*);
90
reed@google.comac10a2d2010-12-22 21:39:39 +000091 // 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
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000098#ifdef SK_DEBUG
reed@google.comac10a2d2010-12-22 21:39:39 +000099 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;
commit-bot@chromium.org3fddf0e2013-09-26 12:57:19 +0000114 GrAtlasMgr* fAtlasMgr[kMaskFormatCount];
reed@google.comac10a2d2010-12-22 21:39:39 +0000115
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