blob: 8b175c8e96042e536b7ea290700012d4246692f3 [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
joshualittddd22d82016-02-16 06:47:52 -080020class GrBlobRegenHelper;
joshualitt2e2202e2015-12-10 11:22:08 -080021struct GrDistanceFieldAdjustTable;
joshualitt92303772016-02-10 11:55:52 -080022class GrMemoryPool;
joshualitt2e2202e2015-12-10 11:22:08 -080023class 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
joshualittddd22d82016-02-16 06:47:52 -0800111 int runCount() const { return fRunCount; }
112
joshualitt323c2eb2016-01-20 06:48:47 -0800113 void push_back_run(int currRun) {
114 SkASSERT(currRun < fRunCount);
115 if (currRun > 0) {
116 Run::SubRunInfo& newRun = fRuns[currRun].fSubRunInfo.back();
117 Run::SubRunInfo& lastRun = fRuns[currRun - 1].fSubRunInfo.back();
118 newRun.setAsSuccessor(lastRun);
119 }
120 }
121
122 // sets the last subrun of runIndex to use distance field text
123 void setSubRunHasDistanceFields(int runIndex, bool hasLCD) {
124 Run& run = fRuns[runIndex];
125 Run::SubRunInfo& subRun = run.fSubRunInfo.back();
126 subRun.setUseLCDText(hasLCD);
127 subRun.setDrawAsDistanceFields();
128 }
129
130 void setRunDrawAsPaths(int runIndex) {
131 fRuns[runIndex].fDrawAsPaths = true;
132 }
133
134 void setMinAndMaxScale(SkScalar scaledMax, SkScalar scaledMin) {
135 // we init fMaxMinScale and fMinMaxScale in the constructor
136 fMaxMinScale = SkMaxScalar(scaledMax, fMaxMinScale);
137 fMinMaxScale = SkMinScalar(scaledMin, fMinMaxScale);
138 }
139
140 // inits the override descriptor on the current run. All following subruns must use this
141 // descriptor
142 void initOverride(int runIndex) {
143 Run& run = fRuns[runIndex];
144 // Push back a new subrun to fill and set the override descriptor
145 run.push_back();
146 run.fOverrideDescriptor.reset(new SkAutoDescriptor);
147 }
148
149 SkGlyphCache* setupCache(int runIndex,
150 const SkSurfaceProps& props,
151 const SkPaint& skPaint,
152 const SkMatrix* viewMatrix,
153 bool noGamma);
154
155 // Appends a glyph to the blob. If the glyph is too large, the glyph will be appended
156 // as a path.
157 void appendGlyph(int runIndex,
158 const SkRect& positions,
159 GrColor color,
160 GrBatchTextStrike* strike,
161 GrGlyph* glyph,
162 GrFontScaler* scaler, const SkGlyph& skGlyph,
163 SkScalar x, SkScalar y, SkScalar scale, bool applyVM);
164
165 static size_t GetVertexStride(GrMaskFormat maskFormat) {
166 switch (maskFormat) {
167 case kA8_GrMaskFormat:
168 return kGrayTextVASize;
169 case kARGB_GrMaskFormat:
170 return kColorTextVASize;
171 default:
172 return kLCDTextVASize;
173 }
174 }
175
176 bool mustRegenerate(SkScalar* outTransX, SkScalar* outTransY, const SkPaint& paint,
177 GrColor color, const SkMaskFilter::BlurRec& blurRec,
178 const SkMatrix& viewMatrix, SkScalar x, SkScalar y);
179
180 // flush a GrAtlasTextBlob associated with a SkTextBlob
181 void flushCached(GrContext* context,
182 GrDrawContext* dc,
183 const SkTextBlob* blob,
184 const SkSurfaceProps& props,
185 const GrDistanceFieldAdjustTable* distanceAdjustTable,
186 const SkPaint& skPaint,
187 const GrPaint& grPaint,
188 SkDrawFilter* drawFilter,
189 const GrClip& clip,
190 const SkMatrix& viewMatrix,
191 const SkIRect& clipBounds,
192 SkScalar x, SkScalar y,
193 SkScalar transX, SkScalar transY);
194
195 // flush a throwaway GrAtlasTextBlob *not* associated with an SkTextBlob
196 void flushThrowaway(GrContext* context,
197 GrDrawContext* dc,
198 const SkSurfaceProps& props,
199 const GrDistanceFieldAdjustTable* distanceAdjustTable,
200 const SkPaint& skPaint,
201 const GrPaint& grPaint,
202 const GrClip& clip,
203 const SkIRect& clipBounds);
204
joshualittbc811112016-02-11 12:42:02 -0800205 void computeSubRunBounds(SkRect* outBounds, int runIndex, int subRunIndex) {
206 // We don't yet position distance field text on the cpu, so we have to map the vertex bounds
207 // into device space.
208 // We handle vertex bounds differently for distance field text and bitmap text because
209 // the vertex bounds of bitmap text are in device space. If we are flushing multiple runs
210 // from one blob then we are going to pay the price here of mapping the rect for each run.
211 const Run& run = fRuns[runIndex];
212 const Run::SubRunInfo& subRun = run.fSubRunInfo[subRunIndex];
213 *outBounds = subRun.vertexBounds();
214 if (subRun.drawAsDistanceFields()) {
215 // Distance field text is positioned with the (X,Y) as part of the glyph position,
216 // and currently the view matrix is applied on the GPU
217 outBounds->offset(fX - fInitialX, fY - fInitialY);
218 fViewMatrix.mapRect(outBounds);
219 } else {
220 // Bitmap text is fully positioned on the CPU, and offset by an (X,Y) translate in
221 // device space.
222 SkMatrix boundsMatrix = fInitialViewMatrixInverse;
223
224 boundsMatrix.postTranslate(-fInitialX, -fInitialY);
225
226 boundsMatrix.postTranslate(fX, fY);
227
228 boundsMatrix.postConcat(fViewMatrix);
229 boundsMatrix.mapRect(outBounds);
230
231 // Due to floating point numerical inaccuracies, we have to round out here
232 outBounds->roundOut(outBounds);
233 }
234 }
235
236 const SkMatrix& viewMatrix() const { return fViewMatrix; }
237
238
joshualitt323c2eb2016-01-20 06:48:47 -0800239 // position + local coord
240 static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16);
241 static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16);
242 static const size_t kLCDTextVASize = kGrayTextVASize;
joshualitt92303772016-02-10 11:55:52 -0800243 static const size_t kMaxVASize = kGrayTextVASize;
joshualitt323c2eb2016-01-20 06:48:47 -0800244 static const int kVerticesPerGlyph = 4;
245
joshualitt323c2eb2016-01-20 06:48:47 -0800246 static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&);
joshualitt323c2eb2016-01-20 06:48:47 -0800247
248 // The color here is the GrPaint color, and it is used to determine whether we
249 // have to regenerate LCD text blobs.
250 // We use this color vs the SkPaint color because it has the colorfilter applied.
251 void initReusableBlob(GrColor color, const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
252 fPaintColor = color;
joshualitt7481e752016-01-22 06:08:48 -0800253 this->setupViewMatrix(viewMatrix, x, y);
joshualitt323c2eb2016-01-20 06:48:47 -0800254 }
255
joshualitt7481e752016-01-22 06:08:48 -0800256 void initThrowawayBlob(const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
257 this->setupViewMatrix(viewMatrix, x, y);
joshualitt323c2eb2016-01-20 06:48:47 -0800258 }
259
joshualittddd22d82016-02-16 06:47:52 -0800260 void regenInBatch(GrDrawBatch::Target* target, GrBatchFontCache* fontCache,
261 GrBlobRegenHelper *helper, int run, int subRun, SkGlyphCache** cache,
262 SkTypeface** typeface, GrFontScaler** scaler,
263 const SkDescriptor** desc, size_t vertexStride,
264 GrColor color, SkScalar transX, SkScalar transY,
265 void** vertices, size_t* byteCount, int* glyphCount);
266
joshualitt92303772016-02-10 11:55:52 -0800267 const Key& key() const { return fKey; }
268
269 ~GrAtlasTextBlob() {
270 for (int i = 0; i < fRunCount; i++) {
271 fRuns[i].~Run();
272 }
273 }
274
joshualittbc811112016-02-11 12:42:02 -0800275 ////////////////////////////////////////////////////////////////////////////////////////////////
276 // Internal test methods
277 GrDrawBatch* test_createBatch(int glyphCount, int run, int subRun,
278 GrColor color, SkScalar transX, SkScalar transY,
279 const SkPaint& skPaint, const SkSurfaceProps& props,
280 const GrDistanceFieldAdjustTable* distanceAdjustTable,
281 GrBatchFontCache* cache);
282
joshualitt323c2eb2016-01-20 06:48:47 -0800283private:
joshualitt92303772016-02-10 11:55:52 -0800284 GrAtlasTextBlob()
285 : fMaxMinScale(-SK_ScalarMax)
286 , fMinMaxScale(SK_ScalarMax)
287 , fTextType(0) {}
288
joshualitt323c2eb2016-01-20 06:48:47 -0800289 void appendLargeGlyph(GrGlyph* glyph, GrFontScaler* scaler, const SkGlyph& skGlyph,
290 SkScalar x, SkScalar y, SkScalar scale, bool applyVM);
291
292 inline void flushRun(GrDrawContext* dc, GrPipelineBuilder* pipelineBuilder,
293 int run, GrColor color,
294 SkScalar transX, SkScalar transY,
295 const SkPaint& skPaint, const SkSurfaceProps& props,
296 const GrDistanceFieldAdjustTable* distanceAdjustTable,
297 GrBatchFontCache* cache);
298
299 void flushBigGlyphs(GrContext* context, GrDrawContext* dc,
300 const GrClip& clip, const SkPaint& skPaint,
301 SkScalar transX, SkScalar transY,
302 const SkIRect& clipBounds);
303
304 void flushRunAsPaths(GrContext* context,
305 GrDrawContext* dc,
306 const SkSurfaceProps& props,
307 const SkTextBlobRunIterator& it,
308 const GrClip& clip, const SkPaint& skPaint,
309 SkDrawFilter* drawFilter, const SkMatrix& viewMatrix,
310 const SkIRect& clipBounds, SkScalar x, SkScalar y);
311
joshualitt7481e752016-01-22 06:08:48 -0800312 // This function will only be called when we are regenerating a blob from scratch. We record the
313 // initial view matrix and initial offsets(x,y), because we record vertex bounds relative to
314 // these numbers. When blobs are reused with new matrices, we need to return to model space so
315 // we can update the vertex bounds appropriately.
316 void setupViewMatrix(const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
317 fViewMatrix = viewMatrix;
318 if (!viewMatrix.invert(&fInitialViewMatrixInverse)) {
319 fInitialViewMatrixInverse = SkMatrix::I();
320 SkDebugf("Could not invert viewmatrix\n");
321 }
322 fX = fInitialX = x;
323 fY = fInitialY = y;
324 }
325
joshualitt374b2f72015-07-21 08:05:03 -0700326 /*
327 * Each Run inside of the blob can have its texture coordinates regenerated if required.
328 * To determine if regeneration is necessary, fAtlasGeneration is used. If there have been
329 * any evictions inside of the atlas, then we will simply regenerate Runs. We could track
330 * this at a more fine grained level, but its not clear if this is worth it, as evictions
331 * should be fairly rare.
332 *
333 * One additional point, each run can contain glyphs with any of the three mask formats.
334 * We call these SubRuns. Because a subrun must be a contiguous range, we have to create
335 * a new subrun each time the mask format changes in a run. In theory, a run can have as
336 * many SubRuns as it has glyphs, ie if a run alternates between color emoji and A8. In
337 * practice, the vast majority of runs have only a single subrun.
338 *
339 * Finally, for runs where the entire thing is too large for the GrAtlasTextContext to
340 * handle, we have a bit to mark the run as flusahable via rendering as paths. It is worth
341 * pointing. It would be a bit expensive to figure out ahead of time whether or not a run
342 * can flush in this manner, so we always allocate vertices for the run, regardless of
343 * whether or not it is too large. The benefit of this strategy is that we can always reuse
344 * a blob allocation regardless of viewmatrix changes. We could store positions for these
345 * glyphs. However, its not clear if this is a win because we'd still have to either go the
346 * glyph cache to get the path at flush time, or hold onto the path in the cache, which
347 * would greatly increase the memory of these cached items.
348 */
349 struct Run {
350 Run()
joshualittf9e658b2015-12-09 09:26:44 -0800351 : fInitialized(false)
joshualitt374b2f72015-07-21 08:05:03 -0700352 , fDrawAsPaths(false) {
joshualitt374b2f72015-07-21 08:05:03 -0700353 // To ensure we always have one subrun, we push back a fresh run here
354 fSubRunInfo.push_back();
355 }
356 struct SubRunInfo {
357 SubRunInfo()
358 : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration)
359 , fVertexStartIndex(0)
360 , fVertexEndIndex(0)
361 , fGlyphStartIndex(0)
362 , fGlyphEndIndex(0)
joshualittf9e658b2015-12-09 09:26:44 -0800363 , fColor(GrColor_ILLEGAL)
jvanverthce79a3a2015-09-10 06:31:38 -0700364 , fMaskFormat(kA8_GrMaskFormat)
365 , fDrawAsDistanceFields(false)
joshualitt7481e752016-01-22 06:08:48 -0800366 , fUseLCDText(false) {
367 fVertexBounds.setLargestInverted();
368 }
joshualitt7e97b0b2015-07-31 15:18:08 -0700369 SubRunInfo(const SubRunInfo& that)
370 : fBulkUseToken(that.fBulkUseToken)
371 , fStrike(SkSafeRef(that.fStrike.get()))
joshualitt7481e752016-01-22 06:08:48 -0800372 , fVertexBounds(that.fVertexBounds)
joshualitt7e97b0b2015-07-31 15:18:08 -0700373 , fAtlasGeneration(that.fAtlasGeneration)
374 , fVertexStartIndex(that.fVertexStartIndex)
375 , fVertexEndIndex(that.fVertexEndIndex)
376 , fGlyphStartIndex(that.fGlyphStartIndex)
377 , fGlyphEndIndex(that.fGlyphEndIndex)
joshualittf9e658b2015-12-09 09:26:44 -0800378 , fColor(that.fColor)
joshualitt7e97b0b2015-07-31 15:18:08 -0700379 , fMaskFormat(that.fMaskFormat)
380 , fDrawAsDistanceFields(that.fDrawAsDistanceFields)
381 , fUseLCDText(that.fUseLCDText) {
382 }
joshualitt3660d532015-12-07 11:32:50 -0800383
joshualitt18b072d2015-12-07 12:26:12 -0800384 // TODO when this object is more internal, drop the privacy
joshualitt3660d532015-12-07 11:32:50 -0800385 void resetBulkUseToken() { fBulkUseToken.reset(); }
386 GrBatchAtlas::BulkUseTokenUpdater* bulkUseToken() { return &fBulkUseToken; }
387 void setStrike(GrBatchTextStrike* strike) { fStrike.reset(SkRef(strike)); }
388 GrBatchTextStrike* strike() const { return fStrike.get(); }
389
390 void setAtlasGeneration(uint64_t atlasGeneration) { fAtlasGeneration = atlasGeneration;}
391 uint64_t atlasGeneration() const { return fAtlasGeneration; }
392
393 size_t byteCount() const { return fVertexEndIndex - fVertexStartIndex; }
joshualitt3660d532015-12-07 11:32:50 -0800394 size_t vertexStartIndex() const { return fVertexStartIndex; }
joshualitt3660d532015-12-07 11:32:50 -0800395 size_t vertexEndIndex() const { return fVertexEndIndex; }
396 void appendVertices(size_t vertexStride) {
397 fVertexEndIndex += vertexStride * kVerticesPerGlyph;
398 }
399
400 uint32_t glyphCount() const { return fGlyphEndIndex - fGlyphStartIndex; }
joshualitt3660d532015-12-07 11:32:50 -0800401 uint32_t glyphStartIndex() const { return fGlyphStartIndex; }
joshualitt3660d532015-12-07 11:32:50 -0800402 uint32_t glyphEndIndex() const { return fGlyphEndIndex; }
403 void glyphAppended() { fGlyphEndIndex++; }
joshualittf9e658b2015-12-09 09:26:44 -0800404 void setColor(GrColor color) { fColor = color; }
405 GrColor color() const { return fColor; }
joshualitt3660d532015-12-07 11:32:50 -0800406 void setMaskFormat(GrMaskFormat format) { fMaskFormat = format; }
407 GrMaskFormat maskFormat() const { return fMaskFormat; }
408
joshualitt18b072d2015-12-07 12:26:12 -0800409 void setAsSuccessor(const SubRunInfo& prev) {
410 fGlyphStartIndex = prev.glyphEndIndex();
411 fGlyphEndIndex = prev.glyphEndIndex();
412
413 fVertexStartIndex = prev.vertexEndIndex();
414 fVertexEndIndex = prev.vertexEndIndex();
415 }
416
joshualitt7481e752016-01-22 06:08:48 -0800417 const SkRect& vertexBounds() const { return fVertexBounds; }
418 void joinGlyphBounds(const SkRect& glyphBounds) {
419 fVertexBounds.joinNonEmptyArg(glyphBounds);
420 }
421
joshualitt3660d532015-12-07 11:32:50 -0800422 // df properties
423 void setUseLCDText(bool useLCDText) { fUseLCDText = useLCDText; }
424 bool hasUseLCDText() const { return fUseLCDText; }
425 void setDrawAsDistanceFields() { fDrawAsDistanceFields = true; }
426 bool drawAsDistanceFields() const { return fDrawAsDistanceFields; }
427
428 private:
joshualitt374b2f72015-07-21 08:05:03 -0700429 GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken;
joshualitt7e97b0b2015-07-31 15:18:08 -0700430 SkAutoTUnref<GrBatchTextStrike> fStrike;
joshualitt7481e752016-01-22 06:08:48 -0800431 SkRect fVertexBounds;
joshualitt374b2f72015-07-21 08:05:03 -0700432 uint64_t fAtlasGeneration;
433 size_t fVertexStartIndex;
434 size_t fVertexEndIndex;
435 uint32_t fGlyphStartIndex;
436 uint32_t fGlyphEndIndex;
joshualittf9e658b2015-12-09 09:26:44 -0800437 GrColor fColor;
joshualitt374b2f72015-07-21 08:05:03 -0700438 GrMaskFormat fMaskFormat;
439 bool fDrawAsDistanceFields; // df property
440 bool fUseLCDText; // df property
441 };
442
443 SubRunInfo& push_back() {
444 // Forward glyph / vertex information to seed the new sub run
joshualitt374b2f72015-07-21 08:05:03 -0700445 SubRunInfo& newSubRun = fSubRunInfo.push_back();
joshualitt18b072d2015-12-07 12:26:12 -0800446 const SubRunInfo& prevSubRun = fSubRunInfo.fromBack(1);
joshualitte43e3bd2015-07-29 11:10:38 -0700447
joshualitt18b072d2015-12-07 12:26:12 -0800448 newSubRun.setAsSuccessor(prevSubRun);
joshualitt374b2f72015-07-21 08:05:03 -0700449 return newSubRun;
450 }
451 static const int kMinSubRuns = 1;
joshualitt374b2f72015-07-21 08:05:03 -0700452 SkAutoTUnref<SkTypeface> fTypeface;
joshualitt374b2f72015-07-21 08:05:03 -0700453 SkSTArray<kMinSubRuns, SubRunInfo> fSubRunInfo;
454 SkAutoDescriptor fDescriptor;
joshualitt3660d532015-12-07 11:32:50 -0800455
456 // Distance field text cannot draw coloremoji, and so has to fall back. However,
457 // though the distance field text and the coloremoji may share the same run, they
458 // will have different descriptors. If fOverrideDescriptor is non-nullptr, then it
459 // will be used in place of the run's descriptor to regen texture coords
joshualitt374b2f72015-07-21 08:05:03 -0700460 SkAutoTDelete<SkAutoDescriptor> fOverrideDescriptor; // df properties
joshualitt374b2f72015-07-21 08:05:03 -0700461 bool fInitialized;
462 bool fDrawAsPaths;
463 };
464
joshualittddd22d82016-02-16 06:47:52 -0800465 template <bool regenPos, bool regenCol, bool regenTexCoords, bool regenGlyphs>
466 void regenInBatch(GrDrawBatch::Target* target,
467 GrBatchFontCache* fontCache,
468 GrBlobRegenHelper* helper,
469 Run* run, Run::SubRunInfo* info, SkGlyphCache** cache,
470 SkTypeface** typeface, GrFontScaler** scaler,
471 const SkDescriptor** desc,
472 int glyphCount, size_t vertexStride,
473 GrColor color, SkScalar transX,
474 SkScalar transY) const;
475
joshualitt323c2eb2016-01-20 06:48:47 -0800476 inline GrDrawBatch* createBatch(const Run::SubRunInfo& info,
477 int glyphCount, int run, int subRun,
478 GrColor color, SkScalar transX, SkScalar transY,
479 const SkPaint& skPaint, const SkSurfaceProps& props,
480 const GrDistanceFieldAdjustTable* distanceAdjustTable,
481 GrBatchFontCache* cache);
482
joshualitt374b2f72015-07-21 08:05:03 -0700483 struct BigGlyph {
joshualitt0fe04a22015-08-25 12:05:50 -0700484 BigGlyph(const SkPath& path, SkScalar vx, SkScalar vy, SkScalar scale, bool applyVM)
joshualitt374b2f72015-07-21 08:05:03 -0700485 : fPath(path)
486 , fVx(vx)
joshualitt0fe04a22015-08-25 12:05:50 -0700487 , fVy(vy)
488 , fScale(scale)
489 , fApplyVM(applyVM) {}
joshualitt374b2f72015-07-21 08:05:03 -0700490 SkPath fPath;
491 SkScalar fVx;
492 SkScalar fVy;
joshualitt0fe04a22015-08-25 12:05:50 -0700493 SkScalar fScale;
494 bool fApplyVM;
joshualitt374b2f72015-07-21 08:05:03 -0700495 };
496
joshualitt374b2f72015-07-21 08:05:03 -0700497 struct StrokeInfo {
498 SkScalar fFrameWidth;
499 SkScalar fMiterLimit;
500 SkPaint::Join fJoin;
501 };
502
503 enum TextType {
504 kHasDistanceField_TextType = 0x1,
505 kHasBitmap_TextType = 0x2,
506 };
507
508 // all glyph / vertex offsets are into these pools.
509 unsigned char* fVertices;
510 GrGlyph** fGlyphs;
511 Run* fRuns;
512 GrMemoryPool* fPool;
513 SkMaskFilter::BlurRec fBlurRec;
514 StrokeInfo fStrokeInfo;
515 SkTArray<BigGlyph> fBigGlyphs;
516 Key fKey;
517 SkMatrix fViewMatrix;
joshualitt7481e752016-01-22 06:08:48 -0800518 SkMatrix fInitialViewMatrixInverse;
joshualitt2f2ee832016-02-10 08:52:24 -0800519 size_t fSize;
jvanverth0628a522015-08-18 07:44:22 -0700520 GrColor fPaintColor;
joshualitt7481e752016-01-22 06:08:48 -0800521 SkScalar fInitialX;
522 SkScalar fInitialY;
joshualitt374b2f72015-07-21 08:05:03 -0700523 SkScalar fX;
524 SkScalar fY;
525
526 // We can reuse distance field text, but only if the new viewmatrix would not result in
527 // a mip change. Because there can be multiple runs in a blob, we track the overall
528 // maximum minimum scale, and minimum maximum scale, we can support before we need to regen
529 SkScalar fMaxMinScale;
530 SkScalar fMinMaxScale;
531 int fRunCount;
532 uint8_t fTextType;
joshualitt374b2f72015-07-21 08:05:03 -0700533};
534
535#endif