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

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

Issue 1275393003: Fix for 510931, merge to m44 (Closed) Base URL: https://skia.googlesource.com/skia.git@m44
Patch Set: Created 5 years, 4 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
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 "GrDrawTarget.h" 12 #include "GrDrawTarget.h"
13 #include "GrFontScaler.h" 13 #include "GrFontScaler.h"
14 #include "GrGlyph.h" 14 #include "GrGlyph.h"
15 #include "SkGlyph.h"
15 #include "SkTDynamicHash.h" 16 #include "SkTDynamicHash.h"
16 #include "SkVarAlloc.h" 17 #include "SkVarAlloc.h"
17 18
18 class GrBatchFontCache; 19 class GrBatchFontCache;
19 class GrBatchTarget; 20 class GrBatchTarget;
20 class GrGpu; 21 class GrGpu;
21 22
22 /** 23 /**
23 * The GrBatchTextStrike manages a pool of CPU backing memory for Glyph Masks. This backing memory 24 * 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 * is abstracted by GrGlyph, and indexed by a PackedID and GrFontScaler. The G rFontScaler is what
25 * actually creates the mask. 26 * actually creates the mask.
26 */ 27 */
27 class GrBatchTextStrike : public SkNVRefCnt<GrBatchTextStrike> { 28 class GrBatchTextStrike : public SkNVRefCnt<GrBatchTextStrike> {
28 public: 29 public:
29 GrBatchTextStrike(GrBatchFontCache*, const GrFontDescKey* fontScalerKey); 30 GrBatchTextStrike(GrBatchFontCache*, const GrFontDescKey* fontScalerKey);
30 ~GrBatchTextStrike(); 31 ~GrBatchTextStrike();
31 32
32 const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; } 33 const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; }
33 GrBatchFontCache* getBatchFontCache() const { return fBatchFontCache; } 34 GrBatchFontCache* getBatchFontCache() const { return fBatchFontCache; }
34 35
35 inline GrGlyph* getGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler) { 36 inline GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed,
37 GrFontScaler* scaler) {
36 GrGlyph* glyph = fCache.find(packed); 38 GrGlyph* glyph = fCache.find(packed);
37 if (NULL == glyph) { 39 if (NULL == glyph) {
38 glyph = this->generateGlyph(packed, scaler); 40 glyph = this->generateGlyph(skGlyph, packed, scaler);
39 } 41 }
40 return glyph; 42 return glyph;
41 } 43 }
42 44
43 // returns true if glyph successfully added to texture atlas, false otherwis e 45 // This variant of the above function is called by TextBatch. At this point , it is possible
44 bool addGlyphToAtlas(GrBatchTarget*, GrGlyph*, GrFontScaler*); 46 // that the maskformat of the glyph differs from what we expect. In these c ases we will just
47 // draw a clear square.
48 // skbug:4143 crbug:510931
49 inline GrGlyph* getGlyph(const SkGlyph& skGlyph, GrGlyph::PackedID packed,
50 GrMaskFormat expectedMaskFormat, GrFontScaler* scal er) {
51 GrGlyph* glyph = fCache.find(packed);
52 if (NULL == glyph) {
53 glyph = this->generateGlyph(skGlyph, packed, scaler);
54 glyph->fMaskFormat = expectedMaskFormat;
55 }
56 return glyph;
57 }
58
59 // returns true if glyph successfully added to texture atlas, false otherwis e. If the glyph's
60 // mask format has changed, then addGlyphToAtlas will draw a clear box. Thi s will almost never
61 // happen.
62 // TODO we can handle some of these cases if we really want to, but the long term solution is to
63 // get the actual glyph image itself when we get the glyph metrics.
64 bool addGlyphToAtlas(GrBatchTarget*, GrGlyph*, GrFontScaler*, const SkGlyph& ,
65 GrMaskFormat expectedMaskFormat);
45 66
46 // testing 67 // testing
47 int countGlyphs() const { return fCache.count(); } 68 int countGlyphs() const { return fCache.count(); }
48 69
49 // remove any references to this plot 70 // remove any references to this plot
50 void removeID(GrBatchAtlas::AtlasID); 71 void removeID(GrBatchAtlas::AtlasID);
51 72
52 // If a TextStrike is abandoned by the cache, then the caller must get a new strike 73 // If a TextStrike is abandoned by the cache, then the caller must get a new strike
53 bool isAbandoned() const { return fIsAbandoned; } 74 bool isAbandoned() const { return fIsAbandoned; }
54 75
55 static const GrFontDescKey& GetKey(const GrBatchTextStrike& ts) { 76 static const GrFontDescKey& GetKey(const GrBatchTextStrike& ts) {
56 return *(ts.fFontScalerKey); 77 return *(ts.fFontScalerKey);
57 } 78 }
58 static uint32_t Hash(const GrFontDescKey& key) { 79 static uint32_t Hash(const GrFontDescKey& key) {
59 return key.getHash(); 80 return key.getHash();
60 } 81 }
61 82
62 private: 83 private:
63 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache; 84 SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache;
64 SkAutoTUnref<const GrFontDescKey> fFontScalerKey; 85 SkAutoTUnref<const GrFontDescKey> fFontScalerKey;
65 SkVarAlloc fPool; 86 SkVarAlloc fPool;
66 87
67 GrBatchFontCache* fBatchFontCache; 88 GrBatchFontCache* fBatchFontCache;
68 int fAtlasedGlyphs; 89 int fAtlasedGlyphs;
69 bool fIsAbandoned; 90 bool fIsAbandoned;
70 91
71 GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler); 92 GrGlyph* generateGlyph(const SkGlyph&, GrGlyph::PackedID, GrFontScaler*);
72 93
73 friend class GrBatchFontCache; 94 friend class GrBatchFontCache;
74 }; 95 };
75 96
76 /* 97 /*
77 * GrBatchFontCache manages strikes which are indexed by a GrFontScaler. These strikes can then be 98 * GrBatchFontCache manages strikes which are indexed by a GrFontScaler. These strikes can then be
78 * used to individual Glyph Masks. The GrBatchFontCache also manages GrBatchAtl ases, though this is 99 * used to individual Glyph Masks. The GrBatchFontCache also manages GrBatchAtl ases, though this is
79 * more or less transparent to the client(aside from atlasGeneration, described below). 100 * more or less transparent to the client(aside from atlasGeneration, described below).
80 * Note - we used to initialize the backing atlas for the GrBatchFontCache at in itialization time. 101 * Note - we used to initialize the backing atlas for the GrBatchFontCache at in itialization time.
81 * However, this caused a regression, even when the GrBatchFontCache was unused. We now initialize 102 * However, this caused a regression, even when the GrBatchFontCache was unused. We now initialize
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 203
183 static void HandleEviction(GrBatchAtlas::AtlasID, void*); 204 static void HandleEviction(GrBatchAtlas::AtlasID, void*);
184 205
185 GrContext* fContext; 206 GrContext* fContext;
186 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache; 207 SkTDynamicHash<GrBatchTextStrike, GrFontDescKey> fCache;
187 GrBatchAtlas* fAtlases[kMaskFormatCount]; 208 GrBatchAtlas* fAtlases[kMaskFormatCount];
188 GrBatchTextStrike* fPreserveStrike; 209 GrBatchTextStrike* fPreserveStrike;
189 }; 210 };
190 211
191 #endif 212 #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