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

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

Issue 1041953002: Switch to one single bitmap text blob cache allocation (Closed) Base URL: https://skia.googlesource.com/skia.git@bmptext2
Patch Set: more tidying 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
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 GrBitmapTextContext_DEFINED 8 #ifndef GrBitmapTextContext_DEFINED
9 #define GrBitmapTextContext_DEFINED 9 #define GrBitmapTextContext_DEFINED
10 10
11 #include "GrTextContext.h" 11 #include "GrTextContext.h"
12 12
13 #include "GrGeometryProcessor.h" 13 #include "GrGeometryProcessor.h"
14 #include "GrMemoryPool.h"
15 #include "SkDescriptor.h"
14 #include "SkTHash.h" 16 #include "SkTHash.h"
15 17
16 class GrBatchTextStrike; 18 class GrBatchTextStrike;
17 class GrPipelineBuilder; 19 class GrPipelineBuilder;
18 20
19 /* 21 /*
20 * This class implements GrTextContext using standard bitmap fonts, and can also process textblobs. 22 * This class implements GrTextContext using standard bitmap fonts, and can also process textblobs.
21 * TODO replace GrBitmapTextContext 23 * TODO replace GrBitmapTextContext
22 */ 24 */
23 class GrBitmapTextContextB : public GrTextContext { 25 class GrBitmapTextContextB : public GrTextContext {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 * The only thing(aside from a memcopy) required to flush a BitmapTextBlob i s to ensure that 59 * The only thing(aside from a memcopy) required to flush a BitmapTextBlob i s to ensure that
58 * the GrAtlas will not evict anything the Blob needs. 60 * the GrAtlas will not evict anything the Blob needs.
59 * TODO this is currently a bug 61 * TODO this is currently a bug
60 */ 62 */
61 struct BitmapTextBlob : public SkRefCnt { 63 struct BitmapTextBlob : public SkRefCnt {
62 // Each Run inside of the blob can have its texture coordinates regenera ted if required. 64 // Each Run inside of the blob can have its texture coordinates regenera ted if required.
63 // To determine if regeneration is necessary, fAtlasGeneration is used. If there have been 65 // To determine if regeneration is necessary, fAtlasGeneration is used. If there have been
64 // any evictions inside of the atlas, then we will simply regenerate Run s. We could track 66 // any evictions inside of the atlas, then we will simply regenerate Run s. We could track
65 // this at a more fine grained level, but its not clear if this is worth it, as evictions 67 // this at a more fine grained level, but its not clear if this is worth it, as evictions
66 // should be fairly rare. 68 // should be fairly rare.
67 // One additional point, each run can contain glyphs with any of the thr ee mask formats. 69 // One additional point, each run can contain glyphs with any of the thr ee mask formats.
bsalomon 2015/03/31 21:19:10 specify in comments that these are "subruns" to ma
joshualitt 2015/04/01 13:21:18 Acknowledged.
68 // We maintain separate arrays for each format type, and flush them sepa rately. In practice 70 // We maintain separate arrays for each format type, and flush them sepa rately. In practice
69 // most of the time a run will have the same format type 71 // most of the time a run will have the same format type
70 struct Run { 72 struct Run {
71 Run() : fColor(GrColor_ILLEGAL) { fVertexBounds.setLargestInverted() ; } 73 Run() : fColor(GrColor_ILLEGAL), fInitialized(false) {
72 struct PerFormatInfo { 74 fVertexBounds.setLargestInverted();
73 PerFormatInfo() : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGe neration) {} 75 fSubRunInfo.push_back();
74 SkTDArray<unsigned char> fVertices; 76 }
75 SkTDArray<GrGlyph::PackedID> fGlyphIDs; 77 struct PerSubRunInfo {
bsalomon 2015/03/31 21:19:11 SubRunInfo?
joshualitt 2015/04/01 13:21:18 Acknowledged.
78 PerSubRunInfo()
79 : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration)
80 , fGlyphStartIndex(0)
81 , fGlyphEndIndex(0)
82 , fVertexStartIndex(0)
83 , fVertexEndIndex(0) {}
84 GrMaskFormat fMaskFormat;
76 uint64_t fAtlasGeneration; 85 uint64_t fAtlasGeneration;
86 uint32_t fGlyphStartIndex;
87 uint32_t fGlyphEndIndex;
88 uint32_t fVertexStartIndex;
89 uint32_t fVertexEndIndex;
77 }; 90 };
78 SkAutoTUnref<const SkData> fDescriptor; 91 SkSTArray<1, PerSubRunInfo, true> fSubRunInfo;
bsalomon 2015/03/31 21:19:11 Does this max out at 3? Maybe just always have an
joshualitt 2015/04/01 13:21:18 No, we can have as many subruns as there are glyph
92 SkAutoDescriptor fDescriptor;
79 SkAutoTUnref<SkTypeface> fTypeface; 93 SkAutoTUnref<SkTypeface> fTypeface;
80 PerFormatInfo fInfos[kMaskFormatCount];
81 SkRect fVertexBounds; 94 SkRect fVertexBounds;
82 GrColor fColor; 95 GrColor fColor;
96 bool fInitialized;
bsalomon 2015/03/31 21:19:11 can you use another param for this rather than add
joshualitt 2015/04/01 13:21:18 Unfortunately I can't just use the descriptor beca
bsalomon 2015/04/01 15:41:45 I'm not sure I totally follow... but maybe this ma
83 }; 97 };
84 SkSTArray<1, Run, true> fRuns; 98
85 struct BigGlyph { 99 struct BigGlyph {
86 BigGlyph(const SkPath& path, int vx, int vy) : fPath(path), fVx(vx), fVy(vy) {} 100 BigGlyph(const SkPath& path, int vx, int vy) : fPath(path), fVx(vx), fVy(vy) {}
87 SkPath fPath; 101 SkPath fPath;
88 int fVx; 102 int fVx;
89 int fVy; 103 int fVy;
90 }; 104 };
105
91 SkTArray<BigGlyph> fBigGlyphs; 106 SkTArray<BigGlyph> fBigGlyphs;
92 SkTextBlob* fBlob;
93 SkMatrix fViewMatrix; 107 SkMatrix fViewMatrix;
94 SkScalar fX; 108 SkScalar fX;
95 SkScalar fY; 109 SkScalar fY;
96 SkPaint::Style fStyle; 110 SkPaint::Style fStyle;
111 uint32_t fRunCount;
112
113 // all glyph / vertex offsets are into these pools.
114 unsigned char* fVertices;
115 GrGlyph::PackedID* fGlyphIDs;
116 Run* fRuns;
97 117
98 static uint32_t Hash(const uint32_t& key) { 118 static uint32_t Hash(const uint32_t& key) {
99 return SkChecksum::Mix(key); 119 return SkChecksum::Mix(key);
100 } 120 }
121
122 void operator delete(void* p) { sk_free(p); }
123 void* operator new(size_t) {
124 SkFAIL("All blobs are created by placement new.");
125 return sk_malloc_throw(0);
126 }
127 void* operator new(size_t, void* p) { return p; }
bsalomon 2015/03/31 21:19:11 some compilers will yell at you for not overriding
joshualitt 2015/04/01 13:21:18 Acknowledged. I'm not sure if I did the delete ri
bsalomon 2015/04/01 15:41:45 Now that I look more closely, why did you need to
joshualitt 2015/04/01 16:54:23 Just to put the throw in new. I guess its not rea
101 }; 128 };
102 129
130 typedef BitmapTextBlob::Run Run;
131 typedef Run::PerSubRunInfo PerSubRunInfo;
132
133 inline BitmapTextBlob* CreateBlob(int glyphCount, int runCount);
134
103 void appendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left, int top, 135 void appendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left, int top,
104 GrFontScaler*, const SkIRect& clipRect); 136 GrFontScaler*, const SkIRect& clipRect);
105 void flushSubRun(GrDrawTarget*, BitmapTextBlob*, int i, GrPipelineBuilder*, GrMaskFormat,
106 GrColor color, int paintAlpha);
107 void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const GrPaint&, const GrClip&, 137 void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const GrPaint&, const GrClip&,
108 const SkMatrix& viewMatrix, int paintAlpha); 138 const SkMatrix& viewMatrix, int paintAlpha);
109 139
110 void internalDrawText(BitmapTextBlob*, int runIndex, const SkPaint&, 140 void internalDrawText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const Sk Paint&,
111 const SkMatrix& viewMatrix, const char text[], size_t byteLength, 141 const SkMatrix& viewMatrix, const char text[], size_t byteLength,
112 SkScalar x, SkScalar y, const SkIRect& clipRect); 142 SkScalar x, SkScalar y, const SkIRect& clipRect);
113 void internalDrawPosText(BitmapTextBlob*, int runIndex, const SkPaint&, 143 void internalDrawPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&,
114 const SkMatrix& viewMatrix, 144 const SkMatrix& viewMatrix,
115 const char text[], size_t byteLength, 145 const char text[], size_t byteLength,
116 const SkScalar pos[], int scalarsPerPosition, 146 const SkScalar pos[], int scalarsPerPosition,
117 const SkPoint& offset, const SkIRect& clipRect); 147 const SkPoint& offset, const SkIRect& clipRect);
118 148
149 // sets up the descriptor on the blob and returns a detached cache. Client must attach
150 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix& viewMa trix);
119 static inline bool MustRegenerateBlob(const BitmapTextBlob&, const SkPaint&, 151 static inline bool MustRegenerateBlob(const BitmapTextBlob&, const SkPaint&,
120 const SkMatrix& viewMatrix, SkScalar x , SkScalar y); 152 const SkMatrix& viewMatrix, SkScalar x , SkScalar y);
121 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, const S kMatrix& viewMatrix, 153 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, const S kMatrix& viewMatrix,
122 const SkTextBlob* blob, SkScalar x, SkScalar y, 154 const SkTextBlob* blob, SkScalar x, SkScalar y,
123 SkDrawFilter* drawFilter, const SkIRect& clipRect); 155 SkDrawFilter* drawFilter, const SkIRect& clipRect);
156 static inline void BlobGlyphCount(int* glyphCount, int* runCount, const SkTe xtBlob*);
124 157
125 GrBatchTextStrike* fCurrStrike; 158 GrBatchTextStrike* fCurrStrike;
126 159
127 // TODO use real cache 160 // TODO use real cache
128 static void ClearCacheEntry(uint32_t key, BitmapTextBlob**); 161 static void ClearCacheEntry(uint32_t key, BitmapTextBlob**);
129 SkTHashMap<uint32_t, BitmapTextBlob*, BitmapTextBlob::Hash> fCache; 162 SkTHashMap<uint32_t, BitmapTextBlob*, BitmapTextBlob::Hash> fCache;
130 163
131 friend class BitmapTextBatch; 164 friend class BitmapTextBatch;
132 165
133 typedef GrTextContext INHERITED; 166 typedef GrTextContext INHERITED;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 207
175 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, 208 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
176 const SkIRect& regionClipBounds); 209 const SkIRect& regionClipBounds);
177 void appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler* ); 210 void appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler* );
178 bool uploadGlyph(GrGlyph*, GrFontScaler*); 211 bool uploadGlyph(GrGlyph*, GrFontScaler*);
179 void flush(); // automatically called by destructor 212 void flush(); // automatically called by destructor
180 void finish(); 213 void finish();
181 }; 214 };
182 215
183 #endif 216 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698