blob: 9a4ef6a928c037c5eaf38951722ca3a87368ca6b [file] [log] [blame]
joshualitt1d89e8d2015-04-01 12:40:54 -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 GrAtlasTextContext_DEFINED
9#define GrAtlasTextContext_DEFINED
10
11#include "GrTextContext.h"
12
joshualittb4c507e2015-04-08 08:07:59 -070013#include "GrBatchAtlas.h"
joshualittae32c102015-04-21 09:37:57 -070014#include "GrBatchFontCache.h"
joshualitt1d89e8d2015-04-01 12:40:54 -070015#include "GrGeometryProcessor.h"
16#include "SkDescriptor.h"
joshualittb7133be2015-04-08 09:08:31 -070017#include "GrMemoryPool.h"
joshualitt53b5f442015-04-13 06:33:59 -070018#include "SkMaskFilter.h"
joshualitt9a27e632015-04-06 10:53:36 -070019#include "SkTextBlob.h"
joshualittb7133be2015-04-08 09:08:31 -070020#include "SkTInternalLList.h"
joshualitt1d89e8d2015-04-01 12:40:54 -070021
joshualitt79dfb2b2015-05-11 08:58:08 -070022#ifdef GR_TEST_UTILS
23#include "GrBatchTest.h"
24#endif
25
26class BitmapTextBatch;
robertphillipsea461502015-05-26 11:38:03 -070027class GrDrawContext;
joshualitt1d89e8d2015-04-01 12:40:54 -070028class GrPipelineBuilder;
joshualittb7133be2015-04-08 09:08:31 -070029class GrTextBlobCache;
joshualitt1d89e8d2015-04-01 12:40:54 -070030
31/*
32 * This class implements GrTextContext using standard bitmap fonts, and can also process textblobs.
33 * TODO replace GrBitmapTextContext
34 */
joshualittdbd35932015-04-02 09:19:04 -070035class GrAtlasTextContext : public GrTextContext {
joshualitt1d89e8d2015-04-01 12:40:54 -070036public:
robertphillipsccb1b572015-05-27 11:02:55 -070037 static GrAtlasTextContext* Create(GrContext*, const SkDeviceProperties&,
joshualitt9bd2daf2015-04-17 09:30:06 -070038 bool enableDistanceFields);
joshualitt1d89e8d2015-04-01 12:40:54 -070039
joshualitt1d89e8d2015-04-01 12:40:54 -070040private:
robertphillipsccb1b572015-05-27 11:02:55 -070041 GrAtlasTextContext(GrContext*, const SkDeviceProperties&, bool enableDistanceFields);
joshualitt9bd2daf2015-04-17 09:30:06 -070042 ~GrAtlasTextContext() override {}
joshualitt1d89e8d2015-04-01 12:40:54 -070043
44 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&,
45 const SkPaint&, const SkMatrix& viewMatrix) override;
46
robertphillipsccb1b572015-05-27 11:02:55 -070047 void onDrawText(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
joshualitt1d89e8d2015-04-01 12:40:54 -070048 const SkMatrix& viewMatrix, const char text[], size_t byteLength,
49 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override;
robertphillipsccb1b572015-05-27 11:02:55 -070050 void onDrawPosText(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPaint&,
51 const SkPaint&, const SkMatrix& viewMatrix,
joshualitt1d89e8d2015-04-01 12:40:54 -070052 const char text[], size_t byteLength,
53 const SkScalar pos[], int scalarsPerPosition,
54 const SkPoint& offset, const SkIRect& regionClipBounds) override;
robertphillips9c240a12015-05-28 07:45:59 -070055 void drawTextBlob(GrRenderTarget*, const GrClip&, const SkPaint&,
joshualitt1d89e8d2015-04-01 12:40:54 -070056 const SkMatrix& viewMatrix, const SkTextBlob*, SkScalar x, SkScalar y,
57 SkDrawFilter*, const SkIRect& clipBounds) override;
58
joshualitt1d89e8d2015-04-01 12:40:54 -070059 /*
60 * A BitmapTextBlob contains a fully processed SkTextBlob, suitable for nearly immediate drawing
61 * on the GPU. These are initially created with valid positions and colors, but invalid
62 * texture coordinates. The BitmapTextBlob itself has a few Blob-wide properties, and also
63 * consists of a number of runs. Runs inside a blob are flushed individually so they can be
64 * reordered.
65 *
66 * The only thing(aside from a memcopy) required to flush a BitmapTextBlob is to ensure that
67 * the GrAtlas will not evict anything the Blob needs.
joshualitt1d89e8d2015-04-01 12:40:54 -070068 */
69 struct BitmapTextBlob : public SkRefCnt {
joshualittb7133be2015-04-08 09:08:31 -070070 SK_DECLARE_INTERNAL_LLIST_INTERFACE(BitmapTextBlob);
71
joshualitt9a27e632015-04-06 10:53:36 -070072 /*
73 * Each Run inside of the blob can have its texture coordinates regenerated if required.
74 * To determine if regeneration is necessary, fAtlasGeneration is used. If there have been
75 * any evictions inside of the atlas, then we will simply regenerate Runs. We could track
76 * this at a more fine grained level, but its not clear if this is worth it, as evictions
77 * should be fairly rare.
78 *
79 * One additional point, each run can contain glyphs with any of the three mask formats.
80 * We call these SubRuns. Because a subrun must be a contiguous range, we have to create
81 * a new subrun each time the mask format changes in a run. In theory, a run can have as
82 * many SubRuns as it has glyphs, ie if a run alternates between color emoji and A8. In
83 * practice, the vast majority of runs have only a single subrun.
84 *
85 * Finally, for runs where the entire thing is too large for the GrAtlasTextContext to
86 * handle, we have a bit to mark the run as flusahable via rendering as paths. It is worth
87 * pointing. It would be a bit expensive to figure out ahead of time whether or not a run
88 * can flush in this manner, so we always allocate vertices for the run, regardless of
89 * whether or not it is too large. The benefit of this strategy is that we can always reuse
90 * a blob allocation regardless of viewmatrix changes. We could store positions for these
91 * glyphs. However, its not clear if this is a win because we'd still have to either go the
92 * glyph cache to get the path at flush time, or hold onto the path in the cache, which
93 * would greatly increase the memory of these cached items.
94 */
joshualitt1d89e8d2015-04-01 12:40:54 -070095 struct Run {
joshualittc3c59902015-04-14 14:33:37 -070096 Run()
97 : fColor(GrColor_ILLEGAL)
98 , fInitialized(false)
99 , fDrawAsPaths(false) {
joshualitt1d89e8d2015-04-01 12:40:54 -0700100 fVertexBounds.setLargestInverted();
joshualitt97202d22015-04-22 13:47:02 -0700101 // To ensure we always have one subrun, we push back a fresh run here
102 fSubRunInfo.push_back();
joshualitt1d89e8d2015-04-01 12:40:54 -0700103 }
104 struct SubRunInfo {
105 SubRunInfo()
106 : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration)
joshualitt1d89e8d2015-04-01 12:40:54 -0700107 , fVertexStartIndex(0)
joshualitt9bd2daf2015-04-17 09:30:06 -0700108 , fVertexEndIndex(0)
joshualitt8672f4d2015-04-21 08:03:04 -0700109 , fGlyphStartIndex(0)
110 , fGlyphEndIndex(0)
joshualitt9bd2daf2015-04-17 09:30:06 -0700111 , fDrawAsDistanceFields(false) {}
joshualittfec19e12015-04-17 10:32:32 -0700112 // Distance field text cannot draw coloremoji, and so has to fall back. However,
113 // though the distance field text and the coloremoji may share the same run, they
114 // will have different descriptors. If fOverrideDescriptor is non-NULL, then it
115 // will be used in place of the run's descriptor to regen texture coords
116 // TODO we could have a descriptor cache, it would reduce the size of these blobs
117 // significantly, and then the subrun could just have a refed pointer to the
118 // correct descriptor.
joshualitt8672f4d2015-04-21 08:03:04 -0700119 GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken;
120 uint64_t fAtlasGeneration;
121 size_t fVertexStartIndex;
122 size_t fVertexEndIndex;
123 uint32_t fGlyphStartIndex;
124 uint32_t fGlyphEndIndex;
125 SkScalar fTextRatio; // df property
126 GrMaskFormat fMaskFormat;
127 bool fDrawAsDistanceFields; // df property
128 bool fUseLCDText; // df property
joshualitt1d89e8d2015-04-01 12:40:54 -0700129 };
joshualittc3c59902015-04-14 14:33:37 -0700130
joshualitt97202d22015-04-22 13:47:02 -0700131 SubRunInfo& push_back() {
132 // Forward glyph / vertex information to seed the new sub run
133 SubRunInfo& prevSubRun = fSubRunInfo.back();
134 SubRunInfo& newSubRun = fSubRunInfo.push_back();
135 newSubRun.fGlyphStartIndex = prevSubRun.fGlyphEndIndex;
136 newSubRun.fGlyphEndIndex = prevSubRun.fGlyphEndIndex;
joshualittc3c59902015-04-14 14:33:37 -0700137
joshualitt97202d22015-04-22 13:47:02 -0700138 newSubRun.fVertexStartIndex = prevSubRun.fVertexEndIndex;
139 newSubRun.fVertexEndIndex = prevSubRun.fVertexEndIndex;
140 return newSubRun;
141 }
142 static const int kMinSubRuns = 1;
joshualittae32c102015-04-21 09:37:57 -0700143 SkAutoTUnref<GrBatchTextStrike> fStrike;
joshualitt1d89e8d2015-04-01 12:40:54 -0700144 SkAutoTUnref<SkTypeface> fTypeface;
145 SkRect fVertexBounds;
joshualitt97202d22015-04-22 13:47:02 -0700146 SkSTArray<kMinSubRuns, SubRunInfo> fSubRunInfo;
joshualitt8672f4d2015-04-21 08:03:04 -0700147 SkAutoDescriptor fDescriptor;
joshualitt97202d22015-04-22 13:47:02 -0700148 SkAutoTDelete<SkAutoDescriptor> fOverrideDescriptor; // df properties
joshualitt1d89e8d2015-04-01 12:40:54 -0700149 GrColor fColor;
150 bool fInitialized;
joshualitt9a27e632015-04-06 10:53:36 -0700151 bool fDrawAsPaths;
joshualitt1d89e8d2015-04-01 12:40:54 -0700152 };
153
154 struct BigGlyph {
joshualitt19e4c022015-05-13 11:23:03 -0700155 BigGlyph(const SkPath& path, SkScalar vx, SkScalar vy)
156 : fPath(path)
157 , fVx(vx)
158 , fVy(vy) {}
joshualitt1d89e8d2015-04-01 12:40:54 -0700159 SkPath fPath;
joshualitt19e4c022015-05-13 11:23:03 -0700160 SkScalar fVx;
161 SkScalar fVy;
joshualitt1d89e8d2015-04-01 12:40:54 -0700162 };
joshualitt1d89e8d2015-04-01 12:40:54 -0700163
joshualitt53b5f442015-04-13 06:33:59 -0700164 struct Key {
165 Key() {
joshualitt9e36c1a2015-04-14 12:17:27 -0700166 sk_bzero(this, sizeof(Key));
joshualitt53b5f442015-04-13 06:33:59 -0700167 }
168 uint32_t fUniqueID;
joshualitt9e36c1a2015-04-14 12:17:27 -0700169 // Color may affect the gamma of the mask we generate, but in a fairly limited way.
170 // Each color is assigned to on of a fixed number of buckets based on its
171 // luminance. For each luminance bucket there is a "canonical color" that
172 // represents the bucket. This functionality is currently only supported for A8
173 SkColor fCanonicalColor;
joshualitte4cee1f2015-05-11 13:04:28 -0700174 SkPaint::Style fStyle;
175 SkPixelGeometry fPixelGeometry;
joshualitt53b5f442015-04-13 06:33:59 -0700176 bool fHasBlur;
177
178 bool operator==(const Key& other) const {
179 return 0 == memcmp(this, &other, sizeof(Key));
180 }
181 };
joshualitt8672f4d2015-04-21 08:03:04 -0700182
183 struct StrokeInfo {
184 SkScalar fFrameWidth;
185 SkScalar fMiterLimit;
186 SkPaint::Join fJoin;
187 };
188
189 enum TextType {
190 kHasDistanceField_TextType = 0x1,
191 kHasBitmap_TextType = 0x2,
192 };
193
194 // all glyph / vertex offsets are into these pools.
195 unsigned char* fVertices;
joshualittae32c102015-04-21 09:37:57 -0700196 GrGlyph** fGlyphs;
joshualitt8672f4d2015-04-21 08:03:04 -0700197 Run* fRuns;
198 GrMemoryPool* fPool;
199 SkMaskFilter::BlurRec fBlurRec;
200 StrokeInfo fStrokeInfo;
201 SkTArray<BigGlyph> fBigGlyphs;
joshualitt53b5f442015-04-13 06:33:59 -0700202 Key fKey;
joshualitt8672f4d2015-04-21 08:03:04 -0700203 SkMatrix fViewMatrix;
joshualitt64c99cc2015-04-21 09:43:03 -0700204 SkColor fPaintColor;
joshualitt8672f4d2015-04-21 08:03:04 -0700205 SkScalar fX;
206 SkScalar fY;
joshualitt64c99cc2015-04-21 09:43:03 -0700207
208 // We can reuse distance field text, but only if the new viewmatrix would not result in
209 // a mip change. Because there can be multiple runs in a blob, we track the overall
210 // maximum minimum scale, and minimum maximum scale, we can support before we need to regen
211 SkScalar fMaxMinScale;
212 SkScalar fMinMaxScale;
joshualitt8672f4d2015-04-21 08:03:04 -0700213 int fRunCount;
214 uint8_t fTextType;
215
joshualitt64c99cc2015-04-21 09:43:03 -0700216 BitmapTextBlob()
joshualitta7c63892015-04-21 13:24:37 -0700217 : fMaxMinScale(-SK_ScalarMax)
joshualitt64c99cc2015-04-21 09:43:03 -0700218 , fMinMaxScale(SK_ScalarMax)
219 , fTextType(0) {}
joshualitt53b5f442015-04-13 06:33:59 -0700220
joshualitt12c20e42015-04-22 11:24:20 -0700221 ~BitmapTextBlob() override {
222 for (int i = 0; i < fRunCount; i++) {
223 fRuns[i].~Run();
224 }
225 }
226
joshualitt53b5f442015-04-13 06:33:59 -0700227 static const Key& GetKey(const BitmapTextBlob& blob) {
228 return blob.fKey;
joshualittb7133be2015-04-08 09:08:31 -0700229 }
230
joshualitt53b5f442015-04-13 06:33:59 -0700231 static uint32_t Hash(const Key& key) {
232 return SkChecksum::Murmur3(&key, sizeof(Key));
joshualitt1d89e8d2015-04-01 12:40:54 -0700233 }
234
joshualittb7133be2015-04-08 09:08:31 -0700235 void operator delete(void* p) {
236 BitmapTextBlob* blob = reinterpret_cast<BitmapTextBlob*>(p);
237 blob->fPool->release(p);
238 }
joshualitt1d89e8d2015-04-01 12:40:54 -0700239 void* operator new(size_t) {
240 SkFAIL("All blobs are created by placement new.");
241 return sk_malloc_throw(0);
242 }
243
244 void* operator new(size_t, void* p) { return p; }
245 void operator delete(void* target, void* placement) {
246 ::operator delete(target, placement);
247 }
joshualittfcfb9fc2015-04-21 07:35:10 -0700248
249 bool hasDistanceField() const { return SkToBool(fTextType & kHasDistanceField_TextType); }
250 bool hasBitmap() const { return SkToBool(fTextType & kHasBitmap_TextType); }
251 void setHasDistanceField() { fTextType |= kHasDistanceField_TextType; }
252 void setHasBitmap() { fTextType |= kHasBitmap_TextType; }
joshualitt1d89e8d2015-04-01 12:40:54 -0700253 };
254
255 typedef BitmapTextBlob::Run Run;
256 typedef Run::SubRunInfo PerSubRunInfo;
257
joshualitt9bd2daf2015-04-17 09:30:06 -0700258 inline bool canDrawAsDistanceFields(const SkPaint&, const SkMatrix& viewMatrix);
259 BitmapTextBlob* setupDFBlob(int glyphCount, const SkPaint& origPaint,
260 const SkMatrix& viewMatrix, SkGlyphCache** cache,
261 SkPaint* dfPaint, SkScalar* textRatio);
262 void bmpAppendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left, int top,
263 GrColor color, GrFontScaler*, const SkIRect& clipRect);
264 bool dfAppendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, SkScalar sx, SkScalar sy,
265 GrColor color, GrFontScaler*, const SkIRect& clipRect, SkScalar textRatio,
266 const SkMatrix& viewMatrix);
267 inline void appendGlyphPath(BitmapTextBlob* blob, GrGlyph* glyph,
joshualitt19e4c022015-05-13 11:23:03 -0700268 GrFontScaler* scaler, SkScalar x, SkScalar y);
joshualitt9bd2daf2015-04-17 09:30:06 -0700269 inline void appendGlyphCommon(BitmapTextBlob*, Run*, Run::SubRunInfo*,
270 const SkRect& positions, GrColor color,
271 size_t vertexStride, bool useVertexColor,
joshualittae32c102015-04-21 09:37:57 -0700272 GrGlyph*);
joshualitt9a27e632015-04-06 10:53:36 -0700273
robertphillips9c240a12015-05-28 07:45:59 -0700274 inline void flushRunAsPaths(GrDrawContext*, GrRenderTarget*,
robertphillipsccb1b572015-05-27 11:02:55 -0700275 const SkTextBlob::RunIterator&, const GrClip& clip,
276 const SkPaint&, SkDrawFilter*,
joshualitt9a27e632015-04-06 10:53:36 -0700277 const SkMatrix& viewMatrix, const SkIRect& clipBounds, SkScalar x,
278 SkScalar y);
joshualitt79dfb2b2015-05-11 08:58:08 -0700279 inline BitmapTextBatch* createBatch(BitmapTextBlob*, const PerSubRunInfo&,
280 int glyphCount, int run, int subRun,
281 GrColor, SkScalar transX, SkScalar transY,
282 const SkPaint&);
robertphillipsea461502015-05-26 11:38:03 -0700283 inline void flushRun(GrDrawContext*, GrPipelineBuilder*, BitmapTextBlob*, int run, GrColor,
joshualitt9bd2daf2015-04-17 09:30:06 -0700284 SkScalar transX, SkScalar transY, const SkPaint&);
robertphillipsccb1b572015-05-27 11:02:55 -0700285 inline void flushBigGlyphs(BitmapTextBlob* cacheBlob, GrDrawContext*, GrRenderTarget*,
286 const GrClip& clip, const SkPaint& skPaint,
joshualitt1107e902015-05-11 14:52:11 -0700287 SkScalar transX, SkScalar transY, const SkIRect& clipBounds);
joshualitt9a27e632015-04-06 10:53:36 -0700288
289 // We have to flush SkTextBlobs differently from drawText / drawPosText
robertphillips9c240a12015-05-28 07:45:59 -0700290 void flush(GrDrawContext*, const SkTextBlob*, BitmapTextBlob*, GrRenderTarget*,
robertphillipsccb1b572015-05-27 11:02:55 -0700291 const SkPaint&, const GrPaint&, SkDrawFilter*, const GrClip&,
292 const SkMatrix& viewMatrix, const SkIRect& clipBounds, SkScalar x, SkScalar y,
293 SkScalar transX, SkScalar transY);
robertphillipsea461502015-05-26 11:38:03 -0700294 void flush(GrDrawContext*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&,
joshualitt1107e902015-05-11 14:52:11 -0700295 const GrPaint&, const GrClip&, const SkIRect& clipBounds);
joshualitt1d89e8d2015-04-01 12:40:54 -0700296
joshualitt9bd2daf2015-04-17 09:30:06 -0700297 // A helper for drawing BitmapText in a run of distance fields
joshualittfcfb9fc2015-04-21 07:35:10 -0700298 inline void fallbackDrawPosText(BitmapTextBlob*, int runIndex,
299 GrRenderTarget*, const GrClip&,
joshualitt9bd2daf2015-04-17 09:30:06 -0700300 const GrPaint&,
301 const SkPaint&, const SkMatrix& viewMatrix,
302 const SkTDArray<char>& fallbackTxt,
303 const SkTDArray<SkScalar>& fallbackPos,
304 int scalarsPerPosition,
305 const SkPoint& offset,
306 const SkIRect& clipRect);
307
308 void internalDrawBMPText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&,
joshualitt9e36c1a2015-04-14 12:17:27 -0700309 GrColor color, const SkMatrix& viewMatrix,
joshualitt1d89e8d2015-04-01 12:40:54 -0700310 const char text[], size_t byteLength,
joshualitt9bd2daf2015-04-17 09:30:06 -0700311 SkScalar x, SkScalar y, const SkIRect& clipRect);
312 void internalDrawBMPPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&,
313 GrColor color, const SkMatrix& viewMatrix,
314 const char text[], size_t byteLength,
315 const SkScalar pos[], int scalarsPerPosition,
316 const SkPoint& offset, const SkIRect& clipRect);
317
318 void internalDrawDFText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&,
319 GrColor color, const SkMatrix& viewMatrix,
320 const char text[], size_t byteLength,
321 SkScalar x, SkScalar y, const SkIRect& clipRect,
322 SkScalar textRatio,
323 SkTDArray<char>* fallbackTxt,
324 SkTDArray<SkScalar>* fallbackPos,
325 SkPoint* offset, const SkPaint& origPaint);
326 void internalDrawDFPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&,
327 GrColor color, const SkMatrix& viewMatrix,
328 const char text[], size_t byteLength,
329 const SkScalar pos[], int scalarsPerPosition,
330 const SkPoint& offset, const SkIRect& clipRect,
331 SkScalar textRatio,
332 SkTDArray<char>* fallbackTxt,
333 SkTDArray<SkScalar>* fallbackPos);
joshualitt1d89e8d2015-04-01 12:40:54 -0700334
335 // sets up the descriptor on the blob and returns a detached cache. Client must attach
joshualitt9e36c1a2015-04-14 12:17:27 -0700336 inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd);
joshualitt9bd2daf2015-04-17 09:30:06 -0700337 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix* viewMatrix, bool noGamma);
joshualitt2a0e9f32015-04-13 06:12:21 -0700338 static inline bool MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTransY,
339 const BitmapTextBlob&, const SkPaint&,
joshualitt53b5f442015-04-13 06:33:59 -0700340 const SkMaskFilter::BlurRec&,
joshualitt1d89e8d2015-04-01 12:40:54 -0700341 const SkMatrix& viewMatrix, SkScalar x, SkScalar y);
robertphillips9c240a12015-05-28 07:45:59 -0700342 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, GrColor,
joshualitt9e36c1a2015-04-14 12:17:27 -0700343 const SkMatrix& viewMatrix,
joshualitt1d89e8d2015-04-01 12:40:54 -0700344 const SkTextBlob* blob, SkScalar x, SkScalar y,
joshualittfcfb9fc2015-04-21 07:35:10 -0700345 SkDrawFilter* drawFilter, const SkIRect& clipRect, GrRenderTarget*,
346 const GrClip&, const GrPaint&);
joshualitt9e36c1a2015-04-14 12:17:27 -0700347 inline static bool HasLCD(const SkTextBlob*);
joshualitt64c99cc2015-04-21 09:43:03 -0700348 inline void initDistanceFieldPaint(BitmapTextBlob*, SkPaint*, SkScalar* textRatio,
349 const SkMatrix&);
joshualitt9bd2daf2015-04-17 09:30:06 -0700350
joshualitt79dfb2b2015-05-11 08:58:08 -0700351 // Test methods
352 // TODO this is really ugly. It'd be much nicer if positioning could be moved to batch
353 inline BitmapTextBlob* createDrawTextBlob(GrRenderTarget*, const GrClip&, const GrPaint&,
354 const SkPaint&, const SkMatrix& viewMatrix,
355 const char text[], size_t byteLength,
356 SkScalar x, SkScalar y,
357 const SkIRect& regionClipBounds);
358 inline BitmapTextBlob* createDrawPosTextBlob(GrRenderTarget*, const GrClip&, const GrPaint&,
359 const SkPaint&, const SkMatrix& viewMatrix,
360 const char text[], size_t byteLength,
361 const SkScalar pos[], int scalarsPerPosition,
362 const SkPoint& offset,
363 const SkIRect& regionClipBounds);
364
joshualitt9bd2daf2015-04-17 09:30:06 -0700365 // Distance field text needs this table to compute a value for use in the fragment shader.
366 // Because the GrAtlasTextContext can go out of scope before the final flush, this needs to be
367 // refcnted and malloced
368 struct DistanceAdjustTable : public SkNVRefCnt<DistanceAdjustTable> {
369 DistanceAdjustTable(float gamma) { this->buildDistanceAdjustTable(gamma); }
370 ~DistanceAdjustTable() { SkDELETE_ARRAY(fTable); }
371
372 void buildDistanceAdjustTable(float gamma);
373
374 SkScalar& operator[] (int i) {
375 return fTable[i];
376 }
377
378 const SkScalar& operator[] (int i) const {
379 return fTable[i];
380 }
381
382 SkScalar* fTable;
383 };
joshualitt1d89e8d2015-04-01 12:40:54 -0700384
joshualitt1d89e8d2015-04-01 12:40:54 -0700385 GrBatchTextStrike* fCurrStrike;
joshualittb7133be2015-04-08 09:08:31 -0700386 GrTextBlobCache* fCache;
joshualitt9bd2daf2015-04-17 09:30:06 -0700387 bool fEnableDFRendering;
388 SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable;
joshualitt1d89e8d2015-04-01 12:40:54 -0700389
joshualittb7133be2015-04-08 09:08:31 -0700390 friend class GrTextBlobCache;
joshualitt1d89e8d2015-04-01 12:40:54 -0700391 friend class BitmapTextBatch;
392
joshualitt79dfb2b2015-05-11 08:58:08 -0700393#ifdef GR_TEST_UTILS
joshualitt6c891102015-05-13 08:51:49 -0700394 BATCH_TEST_FRIEND(TextBlobBatch);
joshualitt79dfb2b2015-05-11 08:58:08 -0700395#endif
396
joshualitt1d89e8d2015-04-01 12:40:54 -0700397 typedef GrTextContext INHERITED;
398};
399
400#endif