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

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

Issue 1257603005: Minimize retrieving SkGlyph in GrTextContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cleanup Created 5 years, 5 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/GrAtlasTextContext.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
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrBatchFontCache_DEFINED 8 #ifndef GrBatchFontCache_DEFINED
9 #define GrBatchFontCache_DEFINED 9 #define GrBatchFontCache_DEFINED
10 10
11 #include "GrBatchAtlas.h" 11 #include "GrBatchAtlas.h"
12 #include "GrFontScaler.h" 12 #include "GrFontScaler.h"
13 #include "GrGlyph.h" 13 #include "GrGlyph.h"
14 #include "SkGlyph.h"
14 #include "SkTDynamicHash.h" 15 #include "SkTDynamicHash.h"
15 #include "SkVarAlloc.h" 16 #include "SkVarAlloc.h"
16 17
17 class GrBatchFontCache; 18 class GrBatchFontCache;
18 class GrBatchTarget; 19 class GrBatchTarget;
19 class GrGpu; 20 class GrGpu;
20 21
21 /** 22 /**
22 * The GrBatchTextStrike manages a pool of CPU backing memory for GrGlyphs. Th is backing memory 23 * The GrBatchTextStrike manages a pool of CPU backing memory for GrGlyphs. Th is backing memory
23 * is indexed by a PackedID and GrFontScaler. The GrFontScaler is what actuall y creates the mask. 24 * is indexed by a PackedID and GrFontScaler. The GrFontScaler is what actuall y creates the mask.
24 */ 25 */
25 class GrBatchTextStrike : public SkNVRefCnt<GrBatchTextStrike> { 26 class GrBatchTextStrike : public SkNVRefCnt<GrBatchTextStrike> {
26 public: 27 public:
27 GrBatchTextStrike(GrBatchFontCache*, const GrFontDescKey* fontScalerKey); 28 GrBatchTextStrike(GrBatchFontCache*, const GrFontDescKey* fontScalerKey);
28 ~GrBatchTextStrike(); 29 ~GrBatchTextStrike();
29 30
30 const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; } 31 const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; }
31 GrBatchFontCache* getBatchFontCache() const { return fBatchFontCache; } 32 GrBatchFontCache* getBatchFontCache() const { return fBatchFontCache; }
32 33
33 inline GrGlyph* getGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler) { 34 inline GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed,
35 GrFontScaler* scaler) {
34 GrGlyph* glyph = fCache.find(packed); 36 GrGlyph* glyph = fCache.find(packed);
35 if (NULL == glyph) { 37 if (NULL == glyph) {
36 glyph = this->generateGlyph(packed, scaler); 38 glyph = this->generateGlyph(skGlyph, packed, scaler);
37 } 39 }
38 return glyph; 40 return glyph;
39 } 41 }
40 42
41 // returns true if glyph successfully added to texture atlas, false otherwis e 43 // returns true if glyph successfully added to texture atlas, false otherwis e
42 bool addGlyphToAtlas(GrBatchTarget*, GrGlyph*, GrFontScaler*); 44 bool addGlyphToAtlas(GrBatchTarget*, GrGlyph*, GrFontScaler*, const SkGlyph& );
43 45
44 // testing 46 // testing
45 int countGlyphs() const { return fCache.count(); } 47 int countGlyphs() const { return fCache.count(); }
46 48
47 // remove any references to this plot 49 // remove any references to this plot
48 void removeID(GrBatchAtlas::AtlasID); 50 void removeID(GrBatchAtlas::AtlasID);
49 51
50 // If a TextStrike is abandoned by the cache, then the caller must get a new strike 52 // If a TextStrike is abandoned by the cache, then the caller must get a new strike
51 bool isAbandoned() const { return fIsAbandoned; } 53 bool isAbandoned() const { return fIsAbandoned; }
52 54
53 static const GrFontDescKey& GetKey(const GrBatchTextStrike& ts) { 55 static const GrFontDescKey& GetKey(const GrBatchTextStrike& ts) {
54 return *(ts.fFontScalerKey); 56 return *(ts.fFontScalerKey);
55 } 57 }
56 static uint32_t Hash(const GrFontDescKey& key) { 58 static uint32_t Hash(const GrFontDescKey& key) {
57 return key.getHash(); 59 return key.getHash();
58 } 60 }
59 61
60 private: 62 private:
61 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache; 63 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache;
62 SkAutoTUnref<const GrFontDescKey> fFontScalerKey; 64 SkAutoTUnref<const GrFontDescKey> fFontScalerKey;
63 SkVarAlloc fPool; 65 SkVarAlloc fPool;
64 66
65 GrBatchFontCache* fBatchFontCache; 67 GrBatchFontCache* fBatchFontCache;
66 int fAtlasedGlyphs; 68 int fAtlasedGlyphs;
67 bool fIsAbandoned; 69 bool fIsAbandoned;
68 70
69 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); 71 GrGlyph* generateGlyph(const SkGlyph&, GrGlyph::PackedID, GrFontScaler*);
70 72
71 friend class GrBatchFontCache; 73 friend class GrBatchFontCache;
72 }; 74 };
73 75
74 /* 76 /*
75 * GrBatchFontCache manages strikes which are indexed by a GrFontScaler. These strikes can then be 77 * GrBatchFontCache manages strikes which are indexed by a GrFontScaler. These strikes can then be
76 * used to individual Glyph Masks. The GrBatchFontCache also manages GrBatchAtl ases, though this is 78 * used to individual Glyph Masks. The GrBatchFontCache also manages GrBatchAtl ases, though this is
77 * more or less transparent to the client(aside from atlasGeneration, described below). 79 * more or less transparent to the client(aside from atlasGeneration, described below).
78 * Note - we used to initialize the backing atlas for the GrBatchFontCache at in itialization time. 80 * Note - we used to initialize the backing atlas for the GrBatchFontCache at in itialization time.
79 * However, this caused a regression, even when the GrBatchFontCache was unused. We now initialize 81 * However, this caused a regression, even when the GrBatchFontCache was unused. We now initialize
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 191
190 static void HandleEviction(GrBatchAtlas::AtlasID, void*); 192 static void HandleEviction(GrBatchAtlas::AtlasID, void*);
191 193
192 GrContext* fContext; 194 GrContext* fContext;
193 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache; 195 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache;
194 GrBatchAtlas* fAtlases[kMaskFormatCount]; 196 GrBatchAtlas* fAtlases[kMaskFormatCount];
195 GrBatchTextStrike* fPreserveStrike; 197 GrBatchTextStrike* fPreserveStrike;
196 }; 198 };
197 199
198 #endif 200 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAtlasTextContext.cpp ('k') | src/gpu/GrBatchFontCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698