Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/gpu/GrBatchFontCache.h

Issue 1011403004: BitmapTextBatch and BitmapTextBlob (Closed) Base URL: https://skia.googlesource.com/skia.git@dfpr_take_2
Patch Set: tweak Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef GrBatchFontCache_DEFINED
9 #define GrBatchFontCache_DEFINED
10
11 #include "GrBatchAtlas.h"
12 #include "GrDrawTarget.h"
13 #include "GrFontScaler.h"
14 #include "GrGlyph.h"
15 #include "SkTDynamicHash.h"
16 #include "SkVarAlloc.h"
17
18 class GrBatchFontCache;
19 class GrBatchTarget;
20 class GrGpu;
21
22 /**
23 * The textstrike maps a hostfontscaler instance to a dictionary of
24 * glyphid->strike
25 */
26 class GrBatchTextStrike {
27 public:
28 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrBatchTextStrike);
29 GrBatchTextStrike(GrBatchFontCache*, const GrFontDescKey* fontScalerKey);
30 ~GrBatchTextStrike();
31
32 const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; }
33 GrBatchFontCache* getBatchFontCache() const { return fBatchFontCache; }
34
35 inline GrGlyph* getGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler) {
36 GrGlyph* glyph = fCache.find(packed);
37 if (NULL == glyph) {
38 glyph = this->generateGlyph(packed, scaler);
39 }
40 return glyph;
41 }
42
43 // returns true if glyph (or glyph+padding for distance field)
44 // is too large to ever fit in texture atlas subregions (GrPlots)
45 bool glyphTooLargeForAtlas(GrGlyph*);
46 // returns true if glyph successfully added to texture atlas, false otherwis e
47 bool addGlyphToAtlas(GrBatchTarget*, GrGlyph*, GrFontScaler*);
48
49 // testing
50 int countGlyphs() const { return fCache.count(); }
51
52 // remove any references to this plot
53 void removeID(GrBatchAtlas::AtlasID);
54
55 static const GrFontDescKey& GetKey(const GrBatchTextStrike& ts) {
56 return *(ts.fFontScalerKey);
57 }
58 static uint32_t Hash(const GrFontDescKey& key) {
59 return key.getHash();
60 }
61
62 private:
63 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache;
64 const GrFontDescKey* fFontScalerKey;
65 SkVarAlloc fPool;
66
67 GrBatchFontCache* fBatchFontCache;
68 int fAtlasedGlyphs;
69
70 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
71
72 friend class GrBatchFontCache;
73 };
74
robertphillips 2015/03/23 19:03:12 Can this guy go inside GrBatchFontCache ?
joshualitt 2015/03/23 19:56:08 Acknowledged.
75 typedef SkTInternalLList<GrBatchTextStrike> GrBatchStrikeList;
76
77 class GrBatchFontCache {
78 public:
79 GrBatchFontCache(GrContext*);
80 ~GrBatchFontCache();
81
82 inline GrBatchTextStrike* getStrike(GrFontScaler* scaler) {
83 SkDEBUGCODE(this->validate();)
84
85 GrBatchTextStrike* strike = fCache.find(*(scaler->getKey()));
86 if (NULL == strike) {
87 strike = this->generateStrike(scaler);
88 } else {
89 this->makeMRU(strike);
90 }
91 SkDEBUGCODE(this->validate();)
92 return strike;
93 }
94
95 bool hasGlyph(GrGlyph* glyph);
96 void refGlyph(GrGlyph*, GrBatchAtlas::BatchToken);
97
98 // add to texture atlas that matches this format
99 bool addToAtlas(GrBatchTextStrike*, GrBatchAtlas::AtlasID*, GrBatchTarget*,
100 GrMaskFormat, int width, int height, const void* image,
101 SkIPoint16* loc);
102
103 uint32_t atlasGeneration(GrMaskFormat) const;
104
105 void freeAll();
106
107 inline void makeMRU(GrBatchTextStrike* strike) {
108 if (fStrikeList.head() == strike) {
109 return;
110 }
111
112 fStrikeList.remove(strike);
113 fStrikeList.addToHead(strike);
114 }
115
116 GrTexture* getTexture(GrMaskFormat);
117 GrPixelConfig getPixelConfig(GrMaskFormat) const;
118
119 SkDEBUGCODE(void validate() const;)
120
121 void dump() const;
122
123 private:
124 enum AtlasType {
125 kA8_AtlasType, //!< 1-byte per pixel
126 k565_AtlasType, //!< 2-bytes per pixel
127 k8888_AtlasType, //!< 4-bytes per pixel
128
129 kLast_AtlasType = k8888_AtlasType
130 };
131
132 static const int kAtlasCount = kLast_AtlasType + 1;
133
134 static int MaskFormatToAtlasIndex(GrMaskFormat);
135 static GrMaskFormat AtlasIndexToMaskFormat(int atlasIndex);
136
137 GrBatchTextStrike* generateStrike(GrFontScaler*);
138
139 void purgeStrike(GrBatchTextStrike* strike);
140 inline GrBatchAtlas* getAtlas(GrMaskFormat) const;
141
142 static void HandleEviction(GrBatchAtlas::AtlasID, void*);
143
144 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache;
145 GrBatchStrikeList fStrikeList;
146
147 GrBatchAtlas* fAtlases[kAtlasCount];
148 GrBatchTextStrike* fPreserveStrike;
149 };
150
151 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698