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 | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 14 | #include "GrBatchFontCache.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 15 | #include "GrGeometryProcessor.h" |
| 16 | #include "SkDescriptor.h" |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 17 | #include "GrMemoryPool.h" |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 18 | #include "SkMaskFilter.h" |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 19 | #include "SkTextBlob.h" |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 20 | #include "SkTInternalLList.h" |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 21 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 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) |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 101 | , fVertexStartIndex(0) |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 102 | , fVertexEndIndex(0) |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 103 | , fGlyphStartIndex(0) |
| 104 | , fGlyphEndIndex(0) |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 105 | , fDrawAsDistanceFields(false) {} |
joshualitt | fec19e1 | 2015-04-17 10:32:32 -0700 | [diff] [blame] | 106 | // Distance field text cannot draw coloremoji, and so has to fall back. However, |
| 107 | // though the distance field text and the coloremoji may share the same run, they |
| 108 | // will have different descriptors. If fOverrideDescriptor is non-NULL, then it |
| 109 | // will be used in place of the run's descriptor to regen texture coords |
| 110 | // TODO we could have a descriptor cache, it would reduce the size of these blobs |
| 111 | // significantly, and then the subrun could just have a refed pointer to the |
| 112 | // correct descriptor. |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 113 | SkAutoTDelete<SkAutoDescriptor> fOverrideDescriptor; // df properties |
| 114 | GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken; |
| 115 | uint64_t fAtlasGeneration; |
| 116 | size_t fVertexStartIndex; |
| 117 | size_t fVertexEndIndex; |
| 118 | uint32_t fGlyphStartIndex; |
| 119 | uint32_t fGlyphEndIndex; |
| 120 | SkScalar fTextRatio; // df property |
| 121 | GrMaskFormat fMaskFormat; |
| 122 | bool fDrawAsDistanceFields; // df property |
| 123 | bool fUseLCDText; // df property |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 124 | }; |
joshualitt | c3c5990 | 2015-04-14 14:33:37 -0700 | [diff] [blame] | 125 | |
| 126 | class SubRunInfoArray { |
| 127 | public: |
| 128 | SubRunInfoArray() |
| 129 | : fSubRunCount(0) |
| 130 | , fSubRunAllocation(kMinSubRuns) { |
joshualitt | fec19e1 | 2015-04-17 10:32:32 -0700 | [diff] [blame] | 131 | SK_COMPILE_ASSERT(kMinSubRuns > 0, insufficient_subrun_allocation); |
| 132 | // We always seed with one here, so we can assume a valid subrun during |
| 133 | // push_back |
joshualitt | c3c5990 | 2015-04-14 14:33:37 -0700 | [diff] [blame] | 134 | fPtr = reinterpret_cast<SubRunInfo*>(fSubRunStorage.get()); |
joshualitt | fec19e1 | 2015-04-17 10:32:32 -0700 | [diff] [blame] | 135 | SkNEW_PLACEMENT(&fPtr[fSubRunCount++], SubRunInfo); |
| 136 | } |
| 137 | ~SubRunInfoArray() { |
| 138 | for (int i = 0; i < fSubRunCount; i++) { |
| 139 | fPtr[i].~SubRunInfo(); |
| 140 | } |
joshualitt | c3c5990 | 2015-04-14 14:33:37 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | int count() const { return fSubRunCount; } |
| 144 | SubRunInfo& back() { return fPtr[fSubRunCount - 1]; } |
| 145 | SubRunInfo& push_back() { |
| 146 | if (fSubRunCount >= fSubRunAllocation) { |
| 147 | fSubRunAllocation = fSubRunAllocation << 1; |
| 148 | fSubRunStorage.realloc(fSubRunAllocation * sizeof(SubRunInfo)); |
| 149 | fPtr = reinterpret_cast<SubRunInfo*>(fSubRunStorage.get()); |
| 150 | } |
| 151 | SkNEW_PLACEMENT(&fPtr[fSubRunCount], SubRunInfo); |
joshualitt | fec19e1 | 2015-04-17 10:32:32 -0700 | [diff] [blame] | 152 | |
| 153 | // Forward glyph / vertex information to seed the new sub run |
| 154 | SubRunInfo& newSubRun = fPtr[fSubRunCount]; |
| 155 | SubRunInfo& prevSubRun = fPtr[fSubRunCount - 1]; |
| 156 | newSubRun.fGlyphStartIndex = prevSubRun.fGlyphEndIndex; |
| 157 | newSubRun.fGlyphEndIndex = prevSubRun.fGlyphEndIndex; |
| 158 | |
| 159 | newSubRun.fVertexStartIndex = prevSubRun.fVertexEndIndex; |
| 160 | newSubRun.fVertexEndIndex = prevSubRun.fVertexEndIndex; |
joshualitt | c3c5990 | 2015-04-14 14:33:37 -0700 | [diff] [blame] | 161 | return fPtr[fSubRunCount++]; |
| 162 | } |
| 163 | SubRunInfo& operator[](int index) { |
| 164 | return fPtr[index]; |
| 165 | } |
| 166 | const SubRunInfo& operator[](int index) const { |
| 167 | return fPtr[index]; |
| 168 | } |
| 169 | |
| 170 | private: |
| 171 | static const int kMinSubRuns = 1; |
| 172 | static const int kMinSubRunStorage = kMinSubRuns * sizeof(SubRunInfo); |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 173 | SubRunInfo* fPtr; |
joshualitt | c3c5990 | 2015-04-14 14:33:37 -0700 | [diff] [blame] | 174 | SkAutoSTMalloc<kMinSubRunStorage, unsigned char> fSubRunStorage; |
| 175 | int fSubRunCount; |
| 176 | int fSubRunAllocation; |
joshualitt | c3c5990 | 2015-04-14 14:33:37 -0700 | [diff] [blame] | 177 | }; |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 178 | SkAutoTUnref<GrBatchTextStrike> fStrike; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 179 | SkAutoTUnref<SkTypeface> fTypeface; |
| 180 | SkRect fVertexBounds; |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 181 | SubRunInfoArray fSubRunInfo; |
| 182 | SkAutoDescriptor fDescriptor; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 183 | GrColor fColor; |
| 184 | bool fInitialized; |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 185 | bool fDrawAsPaths; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | struct BigGlyph { |
| 189 | BigGlyph(const SkPath& path, int vx, int vy) : fPath(path), fVx(vx), fVy(vy) {} |
| 190 | SkPath fPath; |
| 191 | int fVx; |
| 192 | int fVy; |
| 193 | }; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 194 | |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 195 | struct Key { |
| 196 | Key() { |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 197 | sk_bzero(this, sizeof(Key)); |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 198 | } |
| 199 | uint32_t fUniqueID; |
| 200 | SkPaint::Style fStyle; |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 201 | // Color may affect the gamma of the mask we generate, but in a fairly limited way. |
| 202 | // Each color is assigned to on of a fixed number of buckets based on its |
| 203 | // luminance. For each luminance bucket there is a "canonical color" that |
| 204 | // represents the bucket. This functionality is currently only supported for A8 |
| 205 | SkColor fCanonicalColor; |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 206 | bool fHasBlur; |
| 207 | |
| 208 | bool operator==(const Key& other) const { |
| 209 | return 0 == memcmp(this, &other, sizeof(Key)); |
| 210 | } |
| 211 | }; |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 212 | |
| 213 | struct StrokeInfo { |
| 214 | SkScalar fFrameWidth; |
| 215 | SkScalar fMiterLimit; |
| 216 | SkPaint::Join fJoin; |
| 217 | }; |
| 218 | |
| 219 | enum TextType { |
| 220 | kHasDistanceField_TextType = 0x1, |
| 221 | kHasBitmap_TextType = 0x2, |
| 222 | }; |
| 223 | |
| 224 | // all glyph / vertex offsets are into these pools. |
| 225 | unsigned char* fVertices; |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 226 | GrGlyph** fGlyphs; |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 227 | Run* fRuns; |
| 228 | GrMemoryPool* fPool; |
| 229 | SkMaskFilter::BlurRec fBlurRec; |
| 230 | StrokeInfo fStrokeInfo; |
| 231 | SkTArray<BigGlyph> fBigGlyphs; |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 232 | Key fKey; |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 233 | SkMatrix fViewMatrix; |
| 234 | #ifdef SK_DEBUG |
| 235 | mutable SkScalar fTotalXError; |
| 236 | mutable SkScalar fTotalYError; |
| 237 | #endif |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 238 | SkColor fPaintColor; |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 239 | SkScalar fX; |
| 240 | SkScalar fY; |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 241 | |
| 242 | // We can reuse distance field text, but only if the new viewmatrix would not result in |
| 243 | // a mip change. Because there can be multiple runs in a blob, we track the overall |
| 244 | // maximum minimum scale, and minimum maximum scale, we can support before we need to regen |
| 245 | SkScalar fMaxMinScale; |
| 246 | SkScalar fMinMaxScale; |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 247 | int fRunCount; |
| 248 | uint8_t fTextType; |
| 249 | |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 250 | BitmapTextBlob() |
joshualitt | a7c6389 | 2015-04-21 13:24:37 -0700 | [diff] [blame] | 251 | : fMaxMinScale(-SK_ScalarMax) |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 252 | , fMinMaxScale(SK_ScalarMax) |
| 253 | , fTextType(0) {} |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 254 | |
| 255 | static const Key& GetKey(const BitmapTextBlob& blob) { |
| 256 | return blob.fKey; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 257 | } |
| 258 | |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 259 | static uint32_t Hash(const Key& key) { |
| 260 | return SkChecksum::Murmur3(&key, sizeof(Key)); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 261 | } |
| 262 | |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 263 | void operator delete(void* p) { |
| 264 | BitmapTextBlob* blob = reinterpret_cast<BitmapTextBlob*>(p); |
| 265 | blob->fPool->release(p); |
| 266 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 267 | void* operator new(size_t) { |
| 268 | SkFAIL("All blobs are created by placement new."); |
| 269 | return sk_malloc_throw(0); |
| 270 | } |
| 271 | |
| 272 | void* operator new(size_t, void* p) { return p; } |
| 273 | void operator delete(void* target, void* placement) { |
| 274 | ::operator delete(target, placement); |
| 275 | } |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 276 | |
| 277 | bool hasDistanceField() const { return SkToBool(fTextType & kHasDistanceField_TextType); } |
| 278 | bool hasBitmap() const { return SkToBool(fTextType & kHasBitmap_TextType); } |
| 279 | void setHasDistanceField() { fTextType |= kHasDistanceField_TextType; } |
| 280 | void setHasBitmap() { fTextType |= kHasBitmap_TextType; } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 281 | }; |
| 282 | |
| 283 | typedef BitmapTextBlob::Run Run; |
| 284 | typedef Run::SubRunInfo PerSubRunInfo; |
| 285 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 286 | inline bool canDrawAsDistanceFields(const SkPaint&, const SkMatrix& viewMatrix); |
| 287 | BitmapTextBlob* setupDFBlob(int glyphCount, const SkPaint& origPaint, |
| 288 | const SkMatrix& viewMatrix, SkGlyphCache** cache, |
| 289 | SkPaint* dfPaint, SkScalar* textRatio); |
| 290 | void bmpAppendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left, int top, |
| 291 | GrColor color, GrFontScaler*, const SkIRect& clipRect); |
| 292 | bool dfAppendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, SkScalar sx, SkScalar sy, |
| 293 | GrColor color, GrFontScaler*, const SkIRect& clipRect, SkScalar textRatio, |
| 294 | const SkMatrix& viewMatrix); |
| 295 | inline void appendGlyphPath(BitmapTextBlob* blob, GrGlyph* glyph, |
| 296 | GrFontScaler* scaler, int x, int y); |
| 297 | inline void appendGlyphCommon(BitmapTextBlob*, Run*, Run::SubRunInfo*, |
| 298 | const SkRect& positions, GrColor color, |
| 299 | size_t vertexStride, bool useVertexColor, |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 300 | GrGlyph*); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 301 | |
| 302 | inline void flushRunAsPaths(const SkTextBlob::RunIterator&, const SkPaint&, SkDrawFilter*, |
| 303 | const SkMatrix& viewMatrix, const SkIRect& clipBounds, SkScalar x, |
| 304 | SkScalar y); |
| 305 | inline void flushRun(GrDrawTarget*, GrPipelineBuilder*, BitmapTextBlob*, int run, GrColor, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 306 | SkScalar transX, SkScalar transY, const SkPaint&); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 307 | inline void flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRenderTarget* rt, |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 308 | const GrPaint& grPaint, const GrClip& clip, |
| 309 | SkScalar transX, SkScalar transY); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 310 | |
| 311 | // We have to flush SkTextBlobs differently from drawText / drawPosText |
| 312 | void flush(GrDrawTarget*, const SkTextBlob*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&, |
| 313 | const GrPaint&, SkDrawFilter*, const GrClip&, const SkMatrix& viewMatrix, |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 314 | const SkIRect& clipBounds, SkScalar x, SkScalar y, SkScalar transX, SkScalar transY); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 315 | void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 316 | const GrPaint&, const GrClip&); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 317 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 318 | // A helper for drawing BitmapText in a run of distance fields |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 319 | inline void fallbackDrawPosText(BitmapTextBlob*, int runIndex, |
| 320 | GrRenderTarget*, const GrClip&, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 321 | const GrPaint&, |
| 322 | const SkPaint&, const SkMatrix& viewMatrix, |
| 323 | const SkTDArray<char>& fallbackTxt, |
| 324 | const SkTDArray<SkScalar>& fallbackPos, |
| 325 | int scalarsPerPosition, |
| 326 | const SkPoint& offset, |
| 327 | const SkIRect& clipRect); |
| 328 | |
| 329 | void internalDrawBMPText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 330 | GrColor color, const SkMatrix& viewMatrix, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 331 | const char text[], size_t byteLength, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 332 | SkScalar x, SkScalar y, const SkIRect& clipRect); |
| 333 | void internalDrawBMPPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, |
| 334 | GrColor color, const SkMatrix& viewMatrix, |
| 335 | const char text[], size_t byteLength, |
| 336 | const SkScalar pos[], int scalarsPerPosition, |
| 337 | const SkPoint& offset, const SkIRect& clipRect); |
| 338 | |
| 339 | void internalDrawDFText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, |
| 340 | GrColor color, const SkMatrix& viewMatrix, |
| 341 | const char text[], size_t byteLength, |
| 342 | SkScalar x, SkScalar y, const SkIRect& clipRect, |
| 343 | SkScalar textRatio, |
| 344 | SkTDArray<char>* fallbackTxt, |
| 345 | SkTDArray<SkScalar>* fallbackPos, |
| 346 | SkPoint* offset, const SkPaint& origPaint); |
| 347 | void internalDrawDFPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, |
| 348 | GrColor color, const SkMatrix& viewMatrix, |
| 349 | const char text[], size_t byteLength, |
| 350 | const SkScalar pos[], int scalarsPerPosition, |
| 351 | const SkPoint& offset, const SkIRect& clipRect, |
| 352 | SkScalar textRatio, |
| 353 | SkTDArray<char>* fallbackTxt, |
| 354 | SkTDArray<SkScalar>* fallbackPos); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 355 | |
| 356 | // 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] | 357 | inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 358 | inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix* viewMatrix, bool noGamma); |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 359 | static inline bool MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTransY, |
| 360 | const BitmapTextBlob&, const SkPaint&, |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 361 | const SkMaskFilter::BlurRec&, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 362 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y); |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 363 | void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, GrColor, |
| 364 | const SkMatrix& viewMatrix, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 365 | const SkTextBlob* blob, SkScalar x, SkScalar y, |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 366 | SkDrawFilter* drawFilter, const SkIRect& clipRect, GrRenderTarget*, |
| 367 | const GrClip&, const GrPaint&); |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 368 | inline static bool HasLCD(const SkTextBlob*); |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 369 | inline void initDistanceFieldPaint(BitmapTextBlob*, SkPaint*, SkScalar* textRatio, |
| 370 | const SkMatrix&); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 371 | |
| 372 | // Distance field text needs this table to compute a value for use in the fragment shader. |
| 373 | // Because the GrAtlasTextContext can go out of scope before the final flush, this needs to be |
| 374 | // refcnted and malloced |
| 375 | struct DistanceAdjustTable : public SkNVRefCnt<DistanceAdjustTable> { |
| 376 | DistanceAdjustTable(float gamma) { this->buildDistanceAdjustTable(gamma); } |
| 377 | ~DistanceAdjustTable() { SkDELETE_ARRAY(fTable); } |
| 378 | |
| 379 | void buildDistanceAdjustTable(float gamma); |
| 380 | |
| 381 | SkScalar& operator[] (int i) { |
| 382 | return fTable[i]; |
| 383 | } |
| 384 | |
| 385 | const SkScalar& operator[] (int i) const { |
| 386 | return fTable[i]; |
| 387 | } |
| 388 | |
| 389 | SkScalar* fTable; |
| 390 | }; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 391 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 392 | GrBatchTextStrike* fCurrStrike; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 393 | GrTextBlobCache* fCache; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 394 | bool fEnableDFRendering; |
| 395 | SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 396 | |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 397 | friend class GrTextBlobCache; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 398 | friend class BitmapTextBatch; |
| 399 | |
| 400 | typedef GrTextContext INHERITED; |
| 401 | }; |
| 402 | |
| 403 | #endif |