joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
joshualitt | b4c507e | 2015-04-08 08:07:59 -0700 | [diff] [blame] | 13 | #include "GrBatchAtlas.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 14 | #include "GrGeometryProcessor.h" |
| 15 | #include "SkDescriptor.h" |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 16 | #include "GrMemoryPool.h" |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 17 | #include "SkMaskFilter.h" |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 18 | #include "SkTextBlob.h" |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 19 | #include "SkTInternalLList.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 20 | |
| 21 | class GrBatchTextStrike; |
| 22 | class GrPipelineBuilder; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 23 | class GrTextBlobCache; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 24 | |
| 25 | /* |
| 26 | * This class implements GrTextContext using standard bitmap fonts, and can also process textblobs. |
| 27 | * TODO replace GrBitmapTextContext |
| 28 | */ |
joshualitt | dbd3593 | 2015-04-02 09:19:04 -0700 | [diff] [blame] | 29 | class GrAtlasTextContext : public GrTextContext { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 30 | public: |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 31 | static GrAtlasTextContext* Create(GrContext*, SkGpuDevice*, const SkDeviceProperties&, |
| 32 | bool enableDistanceFields); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 33 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 34 | private: |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 35 | GrAtlasTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&, |
| 36 | bool enableDistanceFields); |
| 37 | ~GrAtlasTextContext() override {} |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 38 | |
| 39 | bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, |
| 40 | const SkPaint&, const SkMatrix& viewMatrix) override; |
| 41 | |
| 42 | void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
| 43 | const SkMatrix& viewMatrix, const char text[], size_t byteLength, |
| 44 | SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override; |
| 45 | void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
| 46 | const SkMatrix& viewMatrix, |
| 47 | const char text[], size_t byteLength, |
| 48 | const SkScalar pos[], int scalarsPerPosition, |
| 49 | const SkPoint& offset, const SkIRect& regionClipBounds) override; |
| 50 | void drawTextBlob(GrRenderTarget*, const GrClip&, const SkPaint&, |
| 51 | const SkMatrix& viewMatrix, const SkTextBlob*, SkScalar x, SkScalar y, |
| 52 | SkDrawFilter*, const SkIRect& clipBounds) override; |
| 53 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 54 | /* |
| 55 | * A BitmapTextBlob contains a fully processed SkTextBlob, suitable for nearly immediate drawing |
| 56 | * on the GPU. These are initially created with valid positions and colors, but invalid |
| 57 | * texture coordinates. The BitmapTextBlob itself has a few Blob-wide properties, and also |
| 58 | * consists of a number of runs. Runs inside a blob are flushed individually so they can be |
| 59 | * reordered. |
| 60 | * |
| 61 | * The only thing(aside from a memcopy) required to flush a BitmapTextBlob is to ensure that |
| 62 | * the GrAtlas will not evict anything the Blob needs. |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 63 | */ |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 64 | // TODO Pack these bytes |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 65 | struct BitmapTextBlob : public SkRefCnt { |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 66 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(BitmapTextBlob); |
| 67 | |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 68 | /* |
| 69 | * Each Run inside of the blob can have its texture coordinates regenerated if required. |
| 70 | * To determine if regeneration is necessary, fAtlasGeneration is used. If there have been |
| 71 | * any evictions inside of the atlas, then we will simply regenerate Runs. We could track |
| 72 | * this at a more fine grained level, but its not clear if this is worth it, as evictions |
| 73 | * should be fairly rare. |
| 74 | * |
| 75 | * One additional point, each run can contain glyphs with any of the three mask formats. |
| 76 | * We call these SubRuns. Because a subrun must be a contiguous range, we have to create |
| 77 | * a new subrun each time the mask format changes in a run. In theory, a run can have as |
| 78 | * many SubRuns as it has glyphs, ie if a run alternates between color emoji and A8. In |
| 79 | * practice, the vast majority of runs have only a single subrun. |
| 80 | * |
| 81 | * Finally, for runs where the entire thing is too large for the GrAtlasTextContext to |
| 82 | * handle, we have a bit to mark the run as flusahable via rendering as paths. It is worth |
| 83 | * pointing. It would be a bit expensive to figure out ahead of time whether or not a run |
| 84 | * can flush in this manner, so we always allocate vertices for the run, regardless of |
| 85 | * whether or not it is too large. The benefit of this strategy is that we can always reuse |
| 86 | * a blob allocation regardless of viewmatrix changes. We could store positions for these |
| 87 | * glyphs. However, its not clear if this is a win because we'd still have to either go the |
| 88 | * glyph cache to get the path at flush time, or hold onto the path in the cache, which |
| 89 | * would greatly increase the memory of these cached items. |
| 90 | */ |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 91 | struct Run { |
joshualitt | c3c5990 | 2015-04-14 14:33:37 -0700 | [diff] [blame] | 92 | Run() |
| 93 | : fColor(GrColor_ILLEGAL) |
| 94 | , fInitialized(false) |
| 95 | , fDrawAsPaths(false) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 96 | fVertexBounds.setLargestInverted(); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 97 | } |
| 98 | struct SubRunInfo { |
| 99 | SubRunInfo() |
| 100 | : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration) |
| 101 | , fGlyphStartIndex(0) |
| 102 | , fGlyphEndIndex(0) |
| 103 | , fVertexStartIndex(0) |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 104 | , fVertexEndIndex(0) |
| 105 | , fDrawAsDistanceFields(false) {} |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 106 | GrMaskFormat fMaskFormat; |
| 107 | uint64_t fAtlasGeneration; |
| 108 | uint32_t fGlyphStartIndex; |
| 109 | uint32_t fGlyphEndIndex; |
| 110 | size_t fVertexStartIndex; |
| 111 | size_t fVertexEndIndex; |
joshualitt | b4c507e | 2015-04-08 08:07:59 -0700 | [diff] [blame] | 112 | GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 113 | |
| 114 | // distance field properties |
| 115 | bool fDrawAsDistanceFields; |
| 116 | bool fUseLCDText; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 117 | }; |
joshualitt | c3c5990 | 2015-04-14 14:33:37 -0700 | [diff] [blame] | 118 | |
| 119 | class SubRunInfoArray { |
| 120 | public: |
| 121 | SubRunInfoArray() |
| 122 | : fSubRunCount(0) |
| 123 | , fSubRunAllocation(kMinSubRuns) { |
| 124 | fPtr = reinterpret_cast<SubRunInfo*>(fSubRunStorage.get()); |
| 125 | this->push_back(); |
| 126 | } |
| 127 | |
| 128 | int count() const { return fSubRunCount; } |
| 129 | SubRunInfo& back() { return fPtr[fSubRunCount - 1]; } |
| 130 | SubRunInfo& push_back() { |
| 131 | if (fSubRunCount >= fSubRunAllocation) { |
| 132 | fSubRunAllocation = fSubRunAllocation << 1; |
| 133 | fSubRunStorage.realloc(fSubRunAllocation * sizeof(SubRunInfo)); |
| 134 | fPtr = reinterpret_cast<SubRunInfo*>(fSubRunStorage.get()); |
| 135 | } |
| 136 | SkNEW_PLACEMENT(&fPtr[fSubRunCount], SubRunInfo); |
| 137 | return fPtr[fSubRunCount++]; |
| 138 | } |
| 139 | SubRunInfo& operator[](int index) { |
| 140 | return fPtr[index]; |
| 141 | } |
| 142 | const SubRunInfo& operator[](int index) const { |
| 143 | return fPtr[index]; |
| 144 | } |
| 145 | |
| 146 | private: |
| 147 | static const int kMinSubRuns = 1; |
| 148 | static const int kMinSubRunStorage = kMinSubRuns * sizeof(SubRunInfo); |
| 149 | SkAutoSTMalloc<kMinSubRunStorage, unsigned char> fSubRunStorage; |
| 150 | int fSubRunCount; |
| 151 | int fSubRunAllocation; |
| 152 | SubRunInfo* fPtr; |
| 153 | }; |
| 154 | SubRunInfoArray fSubRunInfo; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 155 | SkAutoDescriptor fDescriptor; |
| 156 | SkAutoTUnref<SkTypeface> fTypeface; |
| 157 | SkRect fVertexBounds; |
| 158 | GrColor fColor; |
| 159 | bool fInitialized; |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 160 | bool fDrawAsPaths; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | struct BigGlyph { |
| 164 | BigGlyph(const SkPath& path, int vx, int vy) : fPath(path), fVx(vx), fVy(vy) {} |
| 165 | SkPath fPath; |
| 166 | int fVx; |
| 167 | int fVy; |
| 168 | }; |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 169 | #ifdef SK_DEBUG |
| 170 | mutable SkScalar fTotalXError; |
| 171 | mutable SkScalar fTotalYError; |
| 172 | #endif |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 173 | SkColor fPaintColor; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 174 | SkTArray<BigGlyph> fBigGlyphs; |
| 175 | SkMatrix fViewMatrix; |
| 176 | SkScalar fX; |
| 177 | SkScalar fY; |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 178 | int fRunCount; |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 179 | SkMaskFilter::BlurRec fBlurRec; |
| 180 | struct StrokeInfo { |
| 181 | SkScalar fFrameWidth; |
| 182 | SkScalar fMiterLimit; |
| 183 | SkPaint::Join fJoin; |
| 184 | }; |
| 185 | StrokeInfo fStrokeInfo; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 186 | GrMemoryPool* fPool; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 187 | |
| 188 | // all glyph / vertex offsets are into these pools. |
| 189 | unsigned char* fVertices; |
| 190 | GrGlyph::PackedID* fGlyphIDs; |
| 191 | Run* fRuns; |
| 192 | |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 193 | struct Key { |
| 194 | Key() { |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 195 | sk_bzero(this, sizeof(Key)); |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 196 | } |
| 197 | uint32_t fUniqueID; |
| 198 | SkPaint::Style fStyle; |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 199 | // Color may affect the gamma of the mask we generate, but in a fairly limited way. |
| 200 | // Each color is assigned to on of a fixed number of buckets based on its |
| 201 | // luminance. For each luminance bucket there is a "canonical color" that |
| 202 | // represents the bucket. This functionality is currently only supported for A8 |
| 203 | SkColor fCanonicalColor; |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 204 | bool fHasBlur; |
| 205 | |
| 206 | bool operator==(const Key& other) const { |
| 207 | return 0 == memcmp(this, &other, sizeof(Key)); |
| 208 | } |
| 209 | }; |
| 210 | Key fKey; |
| 211 | |
| 212 | static const Key& GetKey(const BitmapTextBlob& blob) { |
| 213 | return blob.fKey; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 214 | } |
| 215 | |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 216 | static uint32_t Hash(const Key& key) { |
| 217 | return SkChecksum::Murmur3(&key, sizeof(Key)); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 218 | } |
| 219 | |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 220 | void operator delete(void* p) { |
| 221 | BitmapTextBlob* blob = reinterpret_cast<BitmapTextBlob*>(p); |
| 222 | blob->fPool->release(p); |
| 223 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 224 | void* operator new(size_t) { |
| 225 | SkFAIL("All blobs are created by placement new."); |
| 226 | return sk_malloc_throw(0); |
| 227 | } |
| 228 | |
| 229 | void* operator new(size_t, void* p) { return p; } |
| 230 | void operator delete(void* target, void* placement) { |
| 231 | ::operator delete(target, placement); |
| 232 | } |
| 233 | }; |
| 234 | |
| 235 | typedef BitmapTextBlob::Run Run; |
| 236 | typedef Run::SubRunInfo PerSubRunInfo; |
| 237 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 238 | inline bool canDrawAsDistanceFields(const SkPaint&, const SkMatrix& viewMatrix); |
| 239 | BitmapTextBlob* setupDFBlob(int glyphCount, const SkPaint& origPaint, |
| 240 | const SkMatrix& viewMatrix, SkGlyphCache** cache, |
| 241 | SkPaint* dfPaint, SkScalar* textRatio); |
| 242 | void bmpAppendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left, int top, |
| 243 | GrColor color, GrFontScaler*, const SkIRect& clipRect); |
| 244 | bool dfAppendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, SkScalar sx, SkScalar sy, |
| 245 | GrColor color, GrFontScaler*, const SkIRect& clipRect, SkScalar textRatio, |
| 246 | const SkMatrix& viewMatrix); |
| 247 | inline void appendGlyphPath(BitmapTextBlob* blob, GrGlyph* glyph, |
| 248 | GrFontScaler* scaler, int x, int y); |
| 249 | inline void appendGlyphCommon(BitmapTextBlob*, Run*, Run::SubRunInfo*, |
| 250 | const SkRect& positions, GrColor color, |
| 251 | size_t vertexStride, bool useVertexColor, |
| 252 | GrGlyph::PackedID); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 253 | |
| 254 | inline void flushRunAsPaths(const SkTextBlob::RunIterator&, const SkPaint&, SkDrawFilter*, |
| 255 | const SkMatrix& viewMatrix, const SkIRect& clipBounds, SkScalar x, |
| 256 | SkScalar y); |
| 257 | inline void flushRun(GrDrawTarget*, GrPipelineBuilder*, BitmapTextBlob*, int run, GrColor, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 258 | SkScalar transX, SkScalar transY, const SkPaint&); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 259 | inline void flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRenderTarget* rt, |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 260 | const GrPaint& grPaint, const GrClip& clip, |
| 261 | SkScalar transX, SkScalar transY); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 262 | |
| 263 | // We have to flush SkTextBlobs differently from drawText / drawPosText |
| 264 | void flush(GrDrawTarget*, const SkTextBlob*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&, |
| 265 | const GrPaint&, SkDrawFilter*, const GrClip&, const SkMatrix& viewMatrix, |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 266 | const SkIRect& clipBounds, SkScalar x, SkScalar y, SkScalar transX, SkScalar transY); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 267 | void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 268 | const GrPaint&, const GrClip&); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 269 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 270 | // A helper for drawing BitmapText in a run of distance fields |
| 271 | inline void fallbackDrawPosText(GrRenderTarget*, const GrClip&, |
| 272 | const GrPaint&, |
| 273 | const SkPaint&, const SkMatrix& viewMatrix, |
| 274 | const SkTDArray<char>& fallbackTxt, |
| 275 | const SkTDArray<SkScalar>& fallbackPos, |
| 276 | int scalarsPerPosition, |
| 277 | const SkPoint& offset, |
| 278 | const SkIRect& clipRect); |
| 279 | |
| 280 | void internalDrawBMPText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 281 | GrColor color, const SkMatrix& viewMatrix, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 282 | const char text[], size_t byteLength, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 283 | SkScalar x, SkScalar y, const SkIRect& clipRect); |
| 284 | void internalDrawBMPPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, |
| 285 | GrColor color, const SkMatrix& viewMatrix, |
| 286 | const char text[], size_t byteLength, |
| 287 | const SkScalar pos[], int scalarsPerPosition, |
| 288 | const SkPoint& offset, const SkIRect& clipRect); |
| 289 | |
| 290 | void internalDrawDFText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, |
| 291 | GrColor color, const SkMatrix& viewMatrix, |
| 292 | const char text[], size_t byteLength, |
| 293 | SkScalar x, SkScalar y, const SkIRect& clipRect, |
| 294 | SkScalar textRatio, |
| 295 | SkTDArray<char>* fallbackTxt, |
| 296 | SkTDArray<SkScalar>* fallbackPos, |
| 297 | SkPoint* offset, const SkPaint& origPaint); |
| 298 | void internalDrawDFPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, |
| 299 | GrColor color, const SkMatrix& viewMatrix, |
| 300 | const char text[], size_t byteLength, |
| 301 | const SkScalar pos[], int scalarsPerPosition, |
| 302 | const SkPoint& offset, const SkIRect& clipRect, |
| 303 | SkScalar textRatio, |
| 304 | SkTDArray<char>* fallbackTxt, |
| 305 | SkTDArray<SkScalar>* fallbackPos); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 306 | |
| 307 | // sets up the descriptor on the blob and returns a detached cache. Client must attach |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 308 | inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 309 | inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix* viewMatrix, bool noGamma); |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 310 | static inline bool MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTransY, |
| 311 | const BitmapTextBlob&, const SkPaint&, |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 312 | const SkMaskFilter::BlurRec&, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 313 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y); |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 314 | void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, GrColor, |
| 315 | const SkMatrix& viewMatrix, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 316 | const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 317 | SkDrawFilter* drawFilter, const SkIRect& clipRect); |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 318 | inline static bool HasLCD(const SkTextBlob*); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 319 | inline void initDistanceFieldPaint(SkPaint*, SkScalar* textRatio, const SkMatrix&); |
| 320 | |
| 321 | // Distance field text needs this table to compute a value for use in the fragment shader. |
| 322 | // Because the GrAtlasTextContext can go out of scope before the final flush, this needs to be |
| 323 | // refcnted and malloced |
| 324 | struct DistanceAdjustTable : public SkNVRefCnt<DistanceAdjustTable> { |
| 325 | DistanceAdjustTable(float gamma) { this->buildDistanceAdjustTable(gamma); } |
| 326 | ~DistanceAdjustTable() { SkDELETE_ARRAY(fTable); } |
| 327 | |
| 328 | void buildDistanceAdjustTable(float gamma); |
| 329 | |
| 330 | SkScalar& operator[] (int i) { |
| 331 | return fTable[i]; |
| 332 | } |
| 333 | |
| 334 | const SkScalar& operator[] (int i) const { |
| 335 | return fTable[i]; |
| 336 | } |
| 337 | |
| 338 | SkScalar* fTable; |
| 339 | }; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 340 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 341 | GrBatchTextStrike* fCurrStrike; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 342 | GrTextBlobCache* fCache; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 343 | bool fEnableDFRendering; |
| 344 | SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 345 | |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 346 | friend class GrTextBlobCache; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 347 | friend class BitmapTextBatch; |
| 348 | |
| 349 | typedef GrTextContext INHERITED; |
| 350 | }; |
| 351 | |
| 352 | #endif |