blob: b4168e921ebf98ae691c7e991f850f8b06c805be [file] [log] [blame]
joshualitt374b2f72015-07-21 08:05:03 -07001/*
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 GrAtlasTextBlob_DEFINED
9#define GrAtlasTextBlob_DEFINED
10
11#include "GrBatchAtlas.h"
12#include "GrBatchFontCache.h"
joshualitt259fbf12015-07-21 11:39:34 -070013#include "GrColor.h"
joshualitt2e2202e2015-12-10 11:22:08 -080014#include "GrMemoryPool.h"
joshualitt374b2f72015-07-21 08:05:03 -070015#include "SkDescriptor.h"
16#include "SkMaskFilter.h"
joshualitt259fbf12015-07-21 11:39:34 -070017#include "SkSurfaceProps.h"
joshualitt374b2f72015-07-21 08:05:03 -070018#include "SkTInternalLList.h"
19
joshualitt2e2202e2015-12-10 11:22:08 -080020struct GrDistanceFieldAdjustTable;
joshualitt92303772016-02-10 11:55:52 -080021class GrMemoryPool;
joshualitt2e2202e2015-12-10 11:22:08 -080022class GrTextContext;
23class SkDrawFilter;
24class SkTextBlob;
25class SkTextBlobRunIterator;
26
joshualitt259fbf12015-07-21 11:39:34 -070027// With this flag enabled, the GrAtlasTextContext will, as a sanity check, regenerate every blob
28// that comes in to verify the integrity of its cache
joshualitt2f2ee832016-02-10 08:52:24 -080029#define CACHE_SANITY_CHECK 0
joshualitt259fbf12015-07-21 11:39:34 -070030
joshualitt374b2f72015-07-21 08:05:03 -070031/*
32 * A GrAtlasTextBlob contains a fully processed SkTextBlob, suitable for nearly immediate drawing
33 * on the GPU. These are initially created with valid positions and colors, but invalid
34 * texture coordinates. The GrAtlasTextBlob itself has a few Blob-wide properties, and also
35 * consists of a number of runs. Runs inside a blob are flushed individually so they can be
36 * reordered.
37 *
38 * The only thing(aside from a memcopy) required to flush a GrAtlasTextBlob is to ensure that
39 * the GrAtlas will not evict anything the Blob needs.
40 *
41 * Note: This struct should really be named GrCachedAtasTextBlob, but that is too verbose.
joshualitt259fbf12015-07-21 11:39:34 -070042 *
43 * *WARNING* If you add new fields to this struct, then you may need to to update AssertEqual
joshualitt374b2f72015-07-21 08:05:03 -070044 */
joshualitt2e2202e2015-12-10 11:22:08 -080045class GrAtlasTextBlob : public SkNVRefCnt<GrAtlasTextBlob> {
46public:
joshualitt374b2f72015-07-21 08:05:03 -070047 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrAtlasTextBlob);
48
joshualitt92303772016-02-10 11:55:52 -080049 static GrAtlasTextBlob* Create(GrMemoryPool* pool, int glyphCount, int runCount);
joshualitt323c2eb2016-01-20 06:48:47 -080050
51 struct Key {
52 Key() {
53 sk_bzero(this, sizeof(Key));
54 }
55 uint32_t fUniqueID;
56 // Color may affect the gamma of the mask we generate, but in a fairly limited way.
57 // Each color is assigned to on of a fixed number of buckets based on its
58 // luminance. For each luminance bucket there is a "canonical color" that
59 // represents the bucket. This functionality is currently only supported for A8
60 SkColor fCanonicalColor;
61 SkPaint::Style fStyle;
62 SkPixelGeometry fPixelGeometry;
63 bool fHasBlur;
64
65 bool operator==(const Key& other) const {
66 return 0 == memcmp(this, &other, sizeof(Key));
67 }
68 };
69
joshualitt92303772016-02-10 11:55:52 -080070 void setupKey(const GrAtlasTextBlob::Key& key,
71 const SkMaskFilter::BlurRec& blurRec,
72 const SkPaint& paint) {
73 fKey = key;
74 if (key.fHasBlur) {
75 fBlurRec = blurRec;
76 }
77 if (key.fStyle != SkPaint::kFill_Style) {
78 fStrokeInfo.fFrameWidth = paint.getStrokeWidth();
79 fStrokeInfo.fMiterLimit = paint.getStrokeMiter();
80 fStrokeInfo.fJoin = paint.getStrokeJoin();
81 }
82 }
83
joshualitt323c2eb2016-01-20 06:48:47 -080084 static const Key& GetKey(const GrAtlasTextBlob& blob) {
85 return blob.fKey;
86 }
87
88 static uint32_t Hash(const Key& key) {
89 return SkChecksum::Murmur3(&key, sizeof(Key));
90 }
91
92 void operator delete(void* p) {
93 GrAtlasTextBlob* blob = reinterpret_cast<GrAtlasTextBlob*>(p);
94 blob->fPool->release(p);
95 }
96 void* operator new(size_t) {
97 SkFAIL("All blobs are created by placement new.");
98 return sk_malloc_throw(0);
99 }
100
101 void* operator new(size_t, void* p) { return p; }
102 void operator delete(void* target, void* placement) {
103 ::operator delete(target, placement);
104 }
105
106 bool hasDistanceField() const { return SkToBool(fTextType & kHasDistanceField_TextType); }
107 bool hasBitmap() const { return SkToBool(fTextType & kHasBitmap_TextType); }
108 void setHasDistanceField() { fTextType |= kHasDistanceField_TextType; }
109 void setHasBitmap() { fTextType |= kHasBitmap_TextType; }
110
111 void push_back_run(int currRun) {
112 SkASSERT(currRun < fRunCount);
113 if (currRun > 0) {
114 Run::SubRunInfo& newRun = fRuns[currRun].fSubRunInfo.back();
115 Run::SubRunInfo& lastRun = fRuns[currRun - 1].fSubRunInfo.back();
116 newRun.setAsSuccessor(lastRun);
117 }
118 }
119
120 // sets the last subrun of runIndex to use distance field text
121 void setSubRunHasDistanceFields(int runIndex, bool hasLCD) {
122 Run& run = fRuns[runIndex];
123 Run::SubRunInfo& subRun = run.fSubRunInfo.back();
124 subRun.setUseLCDText(hasLCD);
125 subRun.setDrawAsDistanceFields();
126 }
127
128 void setRunDrawAsPaths(int runIndex) {
129 fRuns[runIndex].fDrawAsPaths = true;
130 }
131
132 void setMinAndMaxScale(SkScalar scaledMax, SkScalar scaledMin) {
133 // we init fMaxMinScale and fMinMaxScale in the constructor
134 fMaxMinScale = SkMaxScalar(scaledMax, fMaxMinScale);
135 fMinMaxScale = SkMinScalar(scaledMin, fMinMaxScale);
136 }
137
138 // inits the override descriptor on the current run. All following subruns must use this
139 // descriptor
140 void initOverride(int runIndex) {
141 Run& run = fRuns[runIndex];
142 // Push back a new subrun to fill and set the override descriptor
143 run.push_back();
144 run.fOverrideDescriptor.reset(new SkAutoDescriptor);
145 }
146
147 SkGlyphCache* setupCache(int runIndex,
148 const SkSurfaceProps& props,
149 const SkPaint& skPaint,
150 const SkMatrix* viewMatrix,
151 bool noGamma);
152
153 // Appends a glyph to the blob. If the glyph is too large, the glyph will be appended
154 // as a path.
155 void appendGlyph(int runIndex,
156 const SkRect& positions,
157 GrColor color,
158 GrBatchTextStrike* strike,
159 GrGlyph* glyph,
160 GrFontScaler* scaler, const SkGlyph& skGlyph,
161 SkScalar x, SkScalar y, SkScalar scale, bool applyVM);
162
163 static size_t GetVertexStride(GrMaskFormat maskFormat) {
164 switch (maskFormat) {
165 case kA8_GrMaskFormat:
166 return kGrayTextVASize;
167 case kARGB_GrMaskFormat:
168 return kColorTextVASize;
169 default:
170 return kLCDTextVASize;
171 }
172 }
173
174 bool mustRegenerate(SkScalar* outTransX, SkScalar* outTransY, const SkPaint& paint,
175 GrColor color, const SkMaskFilter::BlurRec& blurRec,
176 const SkMatrix& viewMatrix, SkScalar x, SkScalar y);
177
178 // flush a GrAtlasTextBlob associated with a SkTextBlob
179 void flushCached(GrContext* context,
180 GrDrawContext* dc,
181 const SkTextBlob* blob,
182 const SkSurfaceProps& props,
183 const GrDistanceFieldAdjustTable* distanceAdjustTable,
184 const SkPaint& skPaint,
185 const GrPaint& grPaint,
186 SkDrawFilter* drawFilter,
187 const GrClip& clip,
188 const SkMatrix& viewMatrix,
189 const SkIRect& clipBounds,
190 SkScalar x, SkScalar y,
191 SkScalar transX, SkScalar transY);
192
193 // flush a throwaway GrAtlasTextBlob *not* associated with an SkTextBlob
194 void flushThrowaway(GrContext* context,
195 GrDrawContext* dc,
196 const SkSurfaceProps& props,
197 const GrDistanceFieldAdjustTable* distanceAdjustTable,
198 const SkPaint& skPaint,
199 const GrPaint& grPaint,
200 const GrClip& clip,
201 const SkIRect& clipBounds);
202
joshualittbc811112016-02-11 12:42:02 -0800203 void computeSubRunBounds(SkRect* outBounds, int runIndex, int subRunIndex) {
204 // We don't yet position distance field text on the cpu, so we have to map the vertex bounds
205 // into device space.
206 // We handle vertex bounds differently for distance field text and bitmap text because
207 // the vertex bounds of bitmap text are in device space. If we are flushing multiple runs
208 // from one blob then we are going to pay the price here of mapping the rect for each run.
209 const Run& run = fRuns[runIndex];
210 const Run::SubRunInfo& subRun = run.fSubRunInfo[subRunIndex];
211 *outBounds = subRun.vertexBounds();
212 if (subRun.drawAsDistanceFields()) {
213 // Distance field text is positioned with the (X,Y) as part of the glyph position,
214 // and currently the view matrix is applied on the GPU
215 outBounds->offset(fX - fInitialX, fY - fInitialY);
216 fViewMatrix.mapRect(outBounds);
217 } else {
218 // Bitmap text is fully positioned on the CPU, and offset by an (X,Y) translate in
219 // device space.
220 SkMatrix boundsMatrix = fInitialViewMatrixInverse;
221
222 boundsMatrix.postTranslate(-fInitialX, -fInitialY);
223
224 boundsMatrix.postTranslate(fX, fY);
225
226 boundsMatrix.postConcat(fViewMatrix);
227 boundsMatrix.mapRect(outBounds);
228
229 // Due to floating point numerical inaccuracies, we have to round out here
230 outBounds->roundOut(outBounds);
231 }
232 }
233
234 const SkMatrix& viewMatrix() const { return fViewMatrix; }
235
236
joshualitt323c2eb2016-01-20 06:48:47 -0800237 // position + local coord
238 static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16);
239 static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16);
240 static const size_t kLCDTextVASize = kGrayTextVASize;
joshualitt92303772016-02-10 11:55:52 -0800241 static const size_t kMaxVASize = kGrayTextVASize;
joshualitt323c2eb2016-01-20 06:48:47 -0800242 static const int kVerticesPerGlyph = 4;
243
joshualitt323c2eb2016-01-20 06:48:47 -0800244 static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&);
joshualitt323c2eb2016-01-20 06:48:47 -0800245
246 // The color here is the GrPaint color, and it is used to determine whether we
247 // have to regenerate LCD text blobs.
248 // We use this color vs the SkPaint color because it has the colorfilter applied.
249 void initReusableBlob(GrColor color, const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
250 fPaintColor = color;
joshualitt7481e752016-01-22 06:08:48 -0800251 this->setupViewMatrix(viewMatrix, x, y);
joshualitt323c2eb2016-01-20 06:48:47 -0800252 }
253
joshualitt7481e752016-01-22 06:08:48 -0800254 void initThrowawayBlob(const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
255 this->setupViewMatrix(viewMatrix, x, y);
joshualitt323c2eb2016-01-20 06:48:47 -0800256 }
257
joshualitt92303772016-02-10 11:55:52 -0800258 const Key& key() const { return fKey; }
259
260 ~GrAtlasTextBlob() {
261 for (int i = 0; i < fRunCount; i++) {
262 fRuns[i].~Run();
263 }
264 }
265
joshualittbc811112016-02-11 12:42:02 -0800266 ////////////////////////////////////////////////////////////////////////////////////////////////
267 // Internal test methods
268 GrDrawBatch* test_createBatch(int glyphCount, int run, int subRun,
269 GrColor color, SkScalar transX, SkScalar transY,
270 const SkPaint& skPaint, const SkSurfaceProps& props,
271 const GrDistanceFieldAdjustTable* distanceAdjustTable,
272 GrBatchFontCache* cache);
273
joshualitt323c2eb2016-01-20 06:48:47 -0800274private:
joshualitt92303772016-02-10 11:55:52 -0800275 GrAtlasTextBlob()
276 : fMaxMinScale(-SK_ScalarMax)
277 , fMinMaxScale(SK_ScalarMax)
278 , fTextType(0) {}
279
joshualitt323c2eb2016-01-20 06:48:47 -0800280 void appendLargeGlyph(GrGlyph* glyph, GrFontScaler* scaler, const SkGlyph& skGlyph,
281 SkScalar x, SkScalar y, SkScalar scale, bool applyVM);
282
283 inline void flushRun(GrDrawContext* dc, GrPipelineBuilder* pipelineBuilder,
284 int run, GrColor color,
285 SkScalar transX, SkScalar transY,
286 const SkPaint& skPaint, const SkSurfaceProps& props,
287 const GrDistanceFieldAdjustTable* distanceAdjustTable,
288 GrBatchFontCache* cache);
289
290 void flushBigGlyphs(GrContext* context, GrDrawContext* dc,
291 const GrClip& clip, const SkPaint& skPaint,
292 SkScalar transX, SkScalar transY,
293 const SkIRect& clipBounds);
294
295 void flushRunAsPaths(GrContext* context,
296 GrDrawContext* dc,
297 const SkSurfaceProps& props,
298 const SkTextBlobRunIterator& it,
299 const GrClip& clip, const SkPaint& skPaint,
300 SkDrawFilter* drawFilter, const SkMatrix& viewMatrix,
301 const SkIRect& clipBounds, SkScalar x, SkScalar y);
302
joshualitt7481e752016-01-22 06:08:48 -0800303 // This function will only be called when we are regenerating a blob from scratch. We record the
304 // initial view matrix and initial offsets(x,y), because we record vertex bounds relative to
305 // these numbers. When blobs are reused with new matrices, we need to return to model space so
306 // we can update the vertex bounds appropriately.
307 void setupViewMatrix(const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
308 fViewMatrix = viewMatrix;
309 if (!viewMatrix.invert(&fInitialViewMatrixInverse)) {
310 fInitialViewMatrixInverse = SkMatrix::I();
311 SkDebugf("Could not invert viewmatrix\n");
312 }
313 fX = fInitialX = x;
314 fY = fInitialY = y;
315 }
316
joshualitt374b2f72015-07-21 08:05:03 -0700317 /*
318 * Each Run inside of the blob can have its texture coordinates regenerated if required.
319 * To determine if regeneration is necessary, fAtlasGeneration is used. If there have been
320 * any evictions inside of the atlas, then we will simply regenerate Runs. We could track
321 * this at a more fine grained level, but its not clear if this is worth it, as evictions
322 * should be fairly rare.
323 *
324 * One additional point, each run can contain glyphs with any of the three mask formats.
325 * We call these SubRuns. Because a subrun must be a contiguous range, we have to create
326 * a new subrun each time the mask format changes in a run. In theory, a run can have as
327 * many SubRuns as it has glyphs, ie if a run alternates between color emoji and A8. In
328 * practice, the vast majority of runs have only a single subrun.
329 *
330 * Finally, for runs where the entire thing is too large for the GrAtlasTextContext to
331 * handle, we have a bit to mark the run as flusahable via rendering as paths. It is worth
332 * pointing. It would be a bit expensive to figure out ahead of time whether or not a run
333 * can flush in this manner, so we always allocate vertices for the run, regardless of
334 * whether or not it is too large. The benefit of this strategy is that we can always reuse
335 * a blob allocation regardless of viewmatrix changes. We could store positions for these
336 * glyphs. However, its not clear if this is a win because we'd still have to either go the
337 * glyph cache to get the path at flush time, or hold onto the path in the cache, which
338 * would greatly increase the memory of these cached items.
339 */
340 struct Run {
341 Run()
joshualittf9e658b2015-12-09 09:26:44 -0800342 : fInitialized(false)
joshualitt374b2f72015-07-21 08:05:03 -0700343 , fDrawAsPaths(false) {
joshualitt374b2f72015-07-21 08:05:03 -0700344 // To ensure we always have one subrun, we push back a fresh run here
345 fSubRunInfo.push_back();
346 }
347 struct SubRunInfo {
348 SubRunInfo()
349 : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration)
350 , fVertexStartIndex(0)
351 , fVertexEndIndex(0)
352 , fGlyphStartIndex(0)
353 , fGlyphEndIndex(0)
joshualittf9e658b2015-12-09 09:26:44 -0800354 , fColor(GrColor_ILLEGAL)
jvanverthce79a3a2015-09-10 06:31:38 -0700355 , fMaskFormat(kA8_GrMaskFormat)
356 , fDrawAsDistanceFields(false)
joshualitt7481e752016-01-22 06:08:48 -0800357 , fUseLCDText(false) {
358 fVertexBounds.setLargestInverted();
359 }
joshualitt7e97b0b2015-07-31 15:18:08 -0700360 SubRunInfo(const SubRunInfo& that)
361 : fBulkUseToken(that.fBulkUseToken)
362 , fStrike(SkSafeRef(that.fStrike.get()))
joshualitt7481e752016-01-22 06:08:48 -0800363 , fVertexBounds(that.fVertexBounds)
joshualitt7e97b0b2015-07-31 15:18:08 -0700364 , fAtlasGeneration(that.fAtlasGeneration)
365 , fVertexStartIndex(that.fVertexStartIndex)
366 , fVertexEndIndex(that.fVertexEndIndex)
367 , fGlyphStartIndex(that.fGlyphStartIndex)
368 , fGlyphEndIndex(that.fGlyphEndIndex)
joshualittf9e658b2015-12-09 09:26:44 -0800369 , fColor(that.fColor)
joshualitt7e97b0b2015-07-31 15:18:08 -0700370 , fMaskFormat(that.fMaskFormat)
371 , fDrawAsDistanceFields(that.fDrawAsDistanceFields)
372 , fUseLCDText(that.fUseLCDText) {
373 }
joshualitt3660d532015-12-07 11:32:50 -0800374
joshualitt18b072d2015-12-07 12:26:12 -0800375 // TODO when this object is more internal, drop the privacy
joshualitt3660d532015-12-07 11:32:50 -0800376 void resetBulkUseToken() { fBulkUseToken.reset(); }
377 GrBatchAtlas::BulkUseTokenUpdater* bulkUseToken() { return &fBulkUseToken; }
378 void setStrike(GrBatchTextStrike* strike) { fStrike.reset(SkRef(strike)); }
379 GrBatchTextStrike* strike() const { return fStrike.get(); }
380
381 void setAtlasGeneration(uint64_t atlasGeneration) { fAtlasGeneration = atlasGeneration;}
382 uint64_t atlasGeneration() const { return fAtlasGeneration; }
383
384 size_t byteCount() const { return fVertexEndIndex - fVertexStartIndex; }
joshualitt3660d532015-12-07 11:32:50 -0800385 size_t vertexStartIndex() const { return fVertexStartIndex; }
joshualitt3660d532015-12-07 11:32:50 -0800386 size_t vertexEndIndex() const { return fVertexEndIndex; }
387 void appendVertices(size_t vertexStride) {
388 fVertexEndIndex += vertexStride * kVerticesPerGlyph;
389 }
390
391 uint32_t glyphCount() const { return fGlyphEndIndex - fGlyphStartIndex; }
joshualitt3660d532015-12-07 11:32:50 -0800392 uint32_t glyphStartIndex() const { return fGlyphStartIndex; }
joshualitt3660d532015-12-07 11:32:50 -0800393 uint32_t glyphEndIndex() const { return fGlyphEndIndex; }
394 void glyphAppended() { fGlyphEndIndex++; }
joshualittf9e658b2015-12-09 09:26:44 -0800395 void setColor(GrColor color) { fColor = color; }
396 GrColor color() const { return fColor; }
joshualitt3660d532015-12-07 11:32:50 -0800397 void setMaskFormat(GrMaskFormat format) { fMaskFormat = format; }
398 GrMaskFormat maskFormat() const { return fMaskFormat; }
399
joshualitt18b072d2015-12-07 12:26:12 -0800400 void setAsSuccessor(const SubRunInfo& prev) {
401 fGlyphStartIndex = prev.glyphEndIndex();
402 fGlyphEndIndex = prev.glyphEndIndex();
403
404 fVertexStartIndex = prev.vertexEndIndex();
405 fVertexEndIndex = prev.vertexEndIndex();
406 }
407
joshualitt7481e752016-01-22 06:08:48 -0800408 const SkRect& vertexBounds() const { return fVertexBounds; }
409 void joinGlyphBounds(const SkRect& glyphBounds) {
410 fVertexBounds.joinNonEmptyArg(glyphBounds);
411 }
412
joshualitt3660d532015-12-07 11:32:50 -0800413 // df properties
414 void setUseLCDText(bool useLCDText) { fUseLCDText = useLCDText; }
415 bool hasUseLCDText() const { return fUseLCDText; }
416 void setDrawAsDistanceFields() { fDrawAsDistanceFields = true; }
417 bool drawAsDistanceFields() const { return fDrawAsDistanceFields; }
418
419 private:
joshualitt374b2f72015-07-21 08:05:03 -0700420 GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken;
joshualitt7e97b0b2015-07-31 15:18:08 -0700421 SkAutoTUnref<GrBatchTextStrike> fStrike;
joshualitt7481e752016-01-22 06:08:48 -0800422 SkRect fVertexBounds;
joshualitt374b2f72015-07-21 08:05:03 -0700423 uint64_t fAtlasGeneration;
424 size_t fVertexStartIndex;
425 size_t fVertexEndIndex;
426 uint32_t fGlyphStartIndex;
427 uint32_t fGlyphEndIndex;
joshualittf9e658b2015-12-09 09:26:44 -0800428 GrColor fColor;
joshualitt374b2f72015-07-21 08:05:03 -0700429 GrMaskFormat fMaskFormat;
430 bool fDrawAsDistanceFields; // df property
431 bool fUseLCDText; // df property
432 };
433
434 SubRunInfo& push_back() {
435 // Forward glyph / vertex information to seed the new sub run
joshualitt374b2f72015-07-21 08:05:03 -0700436 SubRunInfo& newSubRun = fSubRunInfo.push_back();
joshualitt18b072d2015-12-07 12:26:12 -0800437 const SubRunInfo& prevSubRun = fSubRunInfo.fromBack(1);
joshualitte43e3bd2015-07-29 11:10:38 -0700438
joshualitt18b072d2015-12-07 12:26:12 -0800439 newSubRun.setAsSuccessor(prevSubRun);
joshualitt374b2f72015-07-21 08:05:03 -0700440 return newSubRun;
441 }
442 static const int kMinSubRuns = 1;
joshualitt374b2f72015-07-21 08:05:03 -0700443 SkAutoTUnref<SkTypeface> fTypeface;
joshualitt374b2f72015-07-21 08:05:03 -0700444 SkSTArray<kMinSubRuns, SubRunInfo> fSubRunInfo;
445 SkAutoDescriptor fDescriptor;
joshualitt3660d532015-12-07 11:32:50 -0800446
447 // Distance field text cannot draw coloremoji, and so has to fall back. However,
448 // though the distance field text and the coloremoji may share the same run, they
449 // will have different descriptors. If fOverrideDescriptor is non-nullptr, then it
450 // will be used in place of the run's descriptor to regen texture coords
joshualitt374b2f72015-07-21 08:05:03 -0700451 SkAutoTDelete<SkAutoDescriptor> fOverrideDescriptor; // df properties
joshualitt374b2f72015-07-21 08:05:03 -0700452 bool fInitialized;
453 bool fDrawAsPaths;
454 };
455
joshualitt323c2eb2016-01-20 06:48:47 -0800456 inline GrDrawBatch* createBatch(const Run::SubRunInfo& info,
457 int glyphCount, int run, int subRun,
458 GrColor color, SkScalar transX, SkScalar transY,
459 const SkPaint& skPaint, const SkSurfaceProps& props,
460 const GrDistanceFieldAdjustTable* distanceAdjustTable,
461 GrBatchFontCache* cache);
462
joshualitt374b2f72015-07-21 08:05:03 -0700463 struct BigGlyph {
joshualitt0fe04a22015-08-25 12:05:50 -0700464 BigGlyph(const SkPath& path, SkScalar vx, SkScalar vy, SkScalar scale, bool applyVM)
joshualitt374b2f72015-07-21 08:05:03 -0700465 : fPath(path)
466 , fVx(vx)
joshualitt0fe04a22015-08-25 12:05:50 -0700467 , fVy(vy)
468 , fScale(scale)
469 , fApplyVM(applyVM) {}
joshualitt374b2f72015-07-21 08:05:03 -0700470 SkPath fPath;
471 SkScalar fVx;
472 SkScalar fVy;
joshualitt0fe04a22015-08-25 12:05:50 -0700473 SkScalar fScale;
474 bool fApplyVM;
joshualitt374b2f72015-07-21 08:05:03 -0700475 };
476
joshualitt374b2f72015-07-21 08:05:03 -0700477 struct StrokeInfo {
478 SkScalar fFrameWidth;
479 SkScalar fMiterLimit;
480 SkPaint::Join fJoin;
481 };
482
483 enum TextType {
484 kHasDistanceField_TextType = 0x1,
485 kHasBitmap_TextType = 0x2,
486 };
487
488 // all glyph / vertex offsets are into these pools.
489 unsigned char* fVertices;
490 GrGlyph** fGlyphs;
491 Run* fRuns;
492 GrMemoryPool* fPool;
493 SkMaskFilter::BlurRec fBlurRec;
494 StrokeInfo fStrokeInfo;
495 SkTArray<BigGlyph> fBigGlyphs;
496 Key fKey;
497 SkMatrix fViewMatrix;
joshualitt7481e752016-01-22 06:08:48 -0800498 SkMatrix fInitialViewMatrixInverse;
joshualitt2f2ee832016-02-10 08:52:24 -0800499 size_t fSize;
jvanverth0628a522015-08-18 07:44:22 -0700500 GrColor fPaintColor;
joshualitt7481e752016-01-22 06:08:48 -0800501 SkScalar fInitialX;
502 SkScalar fInitialY;
joshualitt374b2f72015-07-21 08:05:03 -0700503 SkScalar fX;
504 SkScalar fY;
505
506 // We can reuse distance field text, but only if the new viewmatrix would not result in
507 // a mip change. Because there can be multiple runs in a blob, we track the overall
508 // maximum minimum scale, and minimum maximum scale, we can support before we need to regen
509 SkScalar fMaxMinScale;
510 SkScalar fMinMaxScale;
511 int fRunCount;
512 uint8_t fTextType;
513
joshualitt323c2eb2016-01-20 06:48:47 -0800514 friend class GrAtlasTextBatch; // We might be able to get rid of this friending
joshualitt374b2f72015-07-21 08:05:03 -0700515};
516
517#endif