blob: 3917d3775dbe1a39b6a5da0d3629273723b6c063 [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:
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.org49e80832013-10-07 18:20:27 +000041 bool getGlyphAtlas(GrGlyph*, GrFontScaler*);
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 }
reed@google.comac10a2d2010-12-22 21:39:39 +000048
commit-bot@chromium.org7d330eb2013-09-27 19:39:38 +000049 // returns true if a plot was removed
50 bool removeUnusedPlots();
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000051
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;
skia.committer@gmail.com50df4d02013-09-28 07:01:33 +000065 GrAtlas fAtlas;
reed@google.comac10a2d2010-12-22 21:39:39 +000066
commit-bot@chromium.org95294412013-09-26 15:28:40 +000067 GrMaskFormat fMaskFormat;
reed@google.com98539c62011-03-15 15:40:16 +000068
reed@google.comac10a2d2010-12-22 21:39:39 +000069 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
reed@google.comac10a2d2010-12-22 21:39:39 +000070
71 friend class GrFontCache;
72};
73
74class GrFontCache {
75public:
76 GrFontCache(GrGpu*);
77 ~GrFontCache();
78
79 inline GrTextStrike* getStrike(GrFontScaler*);
80
81 void freeAll();
reed@google.comac10a2d2010-12-22 21:39:39 +000082
83 void purgeExceptFor(GrTextStrike*);
84
commit-bot@chromium.org7d330eb2013-09-27 19:39:38 +000085 // remove an unused plot and its strike (if necessary)
86 void freePlotExceptFor(GrTextStrike*);
commit-bot@chromium.org67ed64e2013-08-05 19:42:56 +000087
reed@google.comac10a2d2010-12-22 21:39:39 +000088 // testing
89 int countStrikes() const { return fCache.getArray().count(); }
90 const GrTextStrike* strikeAt(int index) const {
91 return fCache.getArray()[index];
92 }
93 GrTextStrike* getHeadStrike() const { return fHead; }
94
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000095#ifdef SK_DEBUG
reed@google.comac10a2d2010-12-22 21:39:39 +000096 void validate() const;
97#else
98 void validate() const {}
99#endif
100
commit-bot@chromium.org03e3e892013-10-02 18:19:17 +0000101#ifdef SK_DEVELOPER
102 void dump() const;
103#endif
104
reed@google.comac10a2d2010-12-22 21:39:39 +0000105private:
106 friend class GrFontPurgeListener;
107
108 class Key;
109 GrTHashTable<GrTextStrike, Key, 8> fCache;
110 // for LRU
111 GrTextStrike* fHead;
112 GrTextStrike* fTail;
113
114 GrGpu* fGpu;
commit-bot@chromium.org3fddf0e2013-09-26 12:57:19 +0000115 GrAtlasMgr* fAtlasMgr[kMaskFormatCount];
reed@google.comac10a2d2010-12-22 21:39:39 +0000116
reed@google.comac10a2d2010-12-22 21:39:39 +0000117 GrTextStrike* generateStrike(GrFontScaler*, const Key&);
118 inline void detachStrikeFromList(GrTextStrike*);
119};
120
121#endif