blob: 26a36320fa1e099e159b28792a12f79b7ccbadb0 [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"
mtklein@google.com4c2af742013-10-21 21:04:06 +000016#include "GrTHashTable.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000017#include "GrPoint.h"
18#include "GrGlyph.h"
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +000019#include "GrDrawTarget.h"
commit-bot@chromium.org7d330eb2013-09-27 19:39:38 +000020#include "GrAtlas.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000021
reed@google.comac10a2d2010-12-22 21:39:39 +000022class 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:
commit-bot@chromium.orgb2e9fa52013-10-27 20:50:23 +000032 GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, 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*);
commit-bot@chromium.org49e80832013-10-07 18:20:27 +000040 bool getGlyphAtlas(GrGlyph*, GrFontScaler*);
reed@google.comac10a2d2010-12-22 21:39:39 +000041
42 // testing
43 int countGlyphs() const { return fCache.getArray().count(); }
44 const GrGlyph* glyphAt(int index) const {
45 return fCache.getArray()[index];
46 }
reed@google.comac10a2d2010-12-22 21:39:39 +000047
commit-bot@chromium.org7d330eb2013-09-27 19:39:38 +000048 // returns true if a plot was removed
49 bool removeUnusedPlots();
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000050
reed@google.comac10a2d2010-12-22 21:39:39 +000051public:
52 // for LRU
53 GrTextStrike* fPrev;
54 GrTextStrike* fNext;
55
56private:
57 class Key;
58 GrTHashTable<GrGlyph, Key, 7> fCache;
59 const GrKey* fFontScalerKey;
60 GrTAllocPool<GrGlyph> fPool;
61
62 GrFontCache* fFontCache;
63 GrAtlasMgr* fAtlasMgr;
skia.committer@gmail.com50df4d02013-09-28 07:01:33 +000064 GrAtlas fAtlas;
reed@google.comac10a2d2010-12-22 21:39:39 +000065
commit-bot@chromium.org95294412013-09-26 15:28:40 +000066 GrMaskFormat fMaskFormat;
reed@google.com98539c62011-03-15 15:40:16 +000067
reed@google.comac10a2d2010-12-22 21:39:39 +000068 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
reed@google.comac10a2d2010-12-22 21:39:39 +000069
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
commit-bot@chromium.org7d330eb2013-09-27 19:39:38 +000084 // remove an unused plot and its strike (if necessary)
85 void freePlotExceptFor(GrTextStrike*);
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000086
reed@google.comac10a2d2010-12-22 21:39:39 +000087 // testing
88 int countStrikes() const { return fCache.getArray().count(); }
89 const GrTextStrike* strikeAt(int index) const {
90 return fCache.getArray()[index];
91 }
92 GrTextStrike* getHeadStrike() const { return fHead; }
93
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000094#ifdef SK_DEBUG
reed@google.comac10a2d2010-12-22 21:39:39 +000095 void validate() const;
96#else
97 void validate() const {}
98#endif
99
commit-bot@chromium.org03e3e892013-10-02 18:19:17 +0000100#ifdef SK_DEVELOPER
101 void dump() const;
102#endif
103
reed@google.comac10a2d2010-12-22 21:39:39 +0000104private:
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.comac10a2d2010-12-22 21:39:39 +0000116 GrTextStrike* generateStrike(GrFontScaler*, const Key&);
117 inline void detachStrikeFromList(GrTextStrike*);
commit-bot@chromium.orgb2e9fa52013-10-27 20:50:23 +0000118 void purgeStrike(GrTextStrike* strike);
reed@google.comac10a2d2010-12-22 21:39:39 +0000119};
120
121#endif