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

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: fix for segfault Created 5 years, 8 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
« no previous file with comments | « src/gpu/GrBatchAtlas.cpp ('k') | src/gpu/GrBatchFontCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 GrBatchTextStrike manages a pool of CPU backing memory for Glyph Masks. This backing memory
24 * is abstracted by GrGlyph, and indexed by a PackedID and GrFontScaler. The G rFontScaler is what
25 * actually creates the mask.
26 */
27 class GrBatchTextStrike {
28 public:
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 SkAutoTUnref<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
75 /*
76 * GrBatchFontCache manages strikes which are indexed by a GrFontScaler. These strikes can then be
77 * used to individual Glyph Masks. The GrBatchFontCache also manages GrBatchAtl ases, though this is
78 * more or less transparent to the client(aside from atlasGeneration, described below)
79 */
80 class GrBatchFontCache {
81 public:
82 GrBatchFontCache();
83 ~GrBatchFontCache();
84
85 // Initializes the GrBatchFontCache on the owning GrContext
86 void init(GrContext*);
87
88 inline GrBatchTextStrike* getStrike(GrFontScaler* scaler) {
89
90 GrBatchTextStrike* strike = fCache.find(*(scaler->getKey()));
91 if (NULL == strike) {
92 strike = this->generateStrike(scaler);
93 }
94 return strike;
95 }
96
97 bool hasGlyph(GrGlyph* glyph);
98
99 // To ensure the GrBatchAtlas does not evict the Glyph Mask from its texture backing store,
100 // the client must pass in the currentToken from the GrBatchTarget along wit h the GrGlyph
101 void setGlyphRefToken(GrGlyph*, GrBatchAtlas::BatchToken);
102
103 // add to texture atlas that matches this format
104 bool addToAtlas(GrBatchTextStrike*, GrBatchAtlas::AtlasID*, GrBatchTarget*,
105 GrMaskFormat, int width, int height, const void* image,
106 SkIPoint16* loc);
107
108 // Some clients may wish to verify the integrity of the texture backing stor e of the
109 // GrBatchAtlas. The atlasGeneration returned below is a monitonically incr easing number which
110 // changes everytime something is removed from the texture backing store.
111 uint64_t atlasGeneration(GrMaskFormat) const;
112
113 void freeAll();
114
115 GrTexture* getTexture(GrMaskFormat);
116 GrPixelConfig getPixelConfig(GrMaskFormat) const;
117
118 void dump() const;
119
120 private:
121 // There is a 1:1 mapping between GrMaskFormats and atlas indices
122 static int MaskFormatToAtlasIndex(GrMaskFormat);
123 static GrMaskFormat AtlasIndexToMaskFormat(int atlasIndex);
124
125 GrBatchTextStrike* generateStrike(GrFontScaler*);
126
127 inline GrBatchAtlas* getAtlas(GrMaskFormat) const;
128
129 static void HandleEviction(GrBatchAtlas::AtlasID, void*);
130
131 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache;
132
133 GrBatchAtlas* fAtlases[kMaskFormatCount];
134 GrBatchTextStrike* fPreserveStrike;
135 };
136
137 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrBatchAtlas.cpp ('k') | src/gpu/GrBatchFontCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698