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 | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 22 | #ifdef GR_TEST_UTILS |
| 23 | #include "GrBatchTest.h" |
| 24 | #endif |
| 25 | |
| 26 | class BitmapTextBatch; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 27 | class GrPipelineBuilder; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 28 | class GrTextBlobCache; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | * This class implements GrTextContext using standard bitmap fonts, and can also process textblobs. |
| 32 | * TODO replace GrBitmapTextContext |
| 33 | */ |
joshualitt | dbd3593 | 2015-04-02 09:19:04 -0700 | [diff] [blame] | 34 | class GrAtlasTextContext : public GrTextContext { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 35 | public: |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 36 | static GrAtlasTextContext* Create(GrContext*, SkGpuDevice*, const SkDeviceProperties&, |
| 37 | bool enableDistanceFields); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 38 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 39 | private: |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 40 | GrAtlasTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&, |
| 41 | bool enableDistanceFields); |
| 42 | ~GrAtlasTextContext() override {} |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 43 | |
| 44 | bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, |
| 45 | const SkPaint&, const SkMatrix& viewMatrix) override; |
| 46 | |
| 47 | void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
| 48 | const SkMatrix& viewMatrix, const char text[], size_t byteLength, |
| 49 | SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override; |
| 50 | void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
| 51 | const SkMatrix& viewMatrix, |
| 52 | const char text[], size_t byteLength, |
| 53 | const SkScalar pos[], int scalarsPerPosition, |
| 54 | const SkPoint& offset, const SkIRect& regionClipBounds) override; |
| 55 | void drawTextBlob(GrRenderTarget*, const GrClip&, const SkPaint&, |
| 56 | const SkMatrix& viewMatrix, const SkTextBlob*, SkScalar x, SkScalar y, |
| 57 | SkDrawFilter*, const SkIRect& clipBounds) override; |
| 58 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 59 | /* |
| 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. |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 68 | */ |
| 69 | struct BitmapTextBlob : public SkRefCnt { |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 70 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(BitmapTextBlob); |
| 71 | |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 72 | /* |
| 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 | */ |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 95 | struct Run { |
joshualitt | c3c5990 | 2015-04-14 14:33:37 -0700 | [diff] [blame] | 96 | Run() |
| 97 | : fColor(GrColor_ILLEGAL) |
| 98 | , fInitialized(false) |
| 99 | , fDrawAsPaths(false) { |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 100 | fVertexBounds.setLargestInverted(); |
joshualitt | 97202d2 | 2015-04-22 13:47:02 -0700 | [diff] [blame] | 101 | // To ensure we always have one subrun, we push back a fresh run here |
| 102 | fSubRunInfo.push_back(); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 103 | } |
| 104 | struct SubRunInfo { |
| 105 | SubRunInfo() |
| 106 | : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration) |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 107 | , fVertexStartIndex(0) |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 108 | , fVertexEndIndex(0) |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 109 | , fGlyphStartIndex(0) |
| 110 | , fGlyphEndIndex(0) |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 111 | , fDrawAsDistanceFields(false) {} |
joshualitt | fec19e1 | 2015-04-17 10:32:32 -0700 | [diff] [blame] | 112 | // 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. |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 119 | 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 |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 129 | }; |
joshualitt | c3c5990 | 2015-04-14 14:33:37 -0700 | [diff] [blame] | 130 | |
joshualitt | 97202d2 | 2015-04-22 13:47:02 -0700 | [diff] [blame] | 131 | 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; |
joshualitt | c3c5990 | 2015-04-14 14:33:37 -0700 | [diff] [blame] | 137 | |
joshualitt | 97202d2 | 2015-04-22 13:47:02 -0700 | [diff] [blame] | 138 | newSubRun.fVertexStartIndex = prevSubRun.fVertexEndIndex; |
| 139 | newSubRun.fVertexEndIndex = prevSubRun.fVertexEndIndex; |
| 140 | return newSubRun; |
| 141 | } |
| 142 | static const int kMinSubRuns = 1; |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 143 | SkAutoTUnref<GrBatchTextStrike> fStrike; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 144 | SkAutoTUnref<SkTypeface> fTypeface; |
| 145 | SkRect fVertexBounds; |
joshualitt | 97202d2 | 2015-04-22 13:47:02 -0700 | [diff] [blame] | 146 | SkSTArray<kMinSubRuns, SubRunInfo> fSubRunInfo; |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 147 | SkAutoDescriptor fDescriptor; |
joshualitt | 97202d2 | 2015-04-22 13:47:02 -0700 | [diff] [blame] | 148 | SkAutoTDelete<SkAutoDescriptor> fOverrideDescriptor; // df properties |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 149 | GrColor fColor; |
| 150 | bool fInitialized; |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 151 | bool fDrawAsPaths; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | struct BigGlyph { |
| 155 | BigGlyph(const SkPath& path, int vx, int vy) : fPath(path), fVx(vx), fVy(vy) {} |
| 156 | SkPath fPath; |
| 157 | int fVx; |
| 158 | int fVy; |
| 159 | }; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 160 | |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 161 | struct Key { |
| 162 | Key() { |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 163 | sk_bzero(this, sizeof(Key)); |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 164 | } |
| 165 | uint32_t fUniqueID; |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 166 | // Color may affect the gamma of the mask we generate, but in a fairly limited way. |
| 167 | // Each color is assigned to on of a fixed number of buckets based on its |
| 168 | // luminance. For each luminance bucket there is a "canonical color" that |
| 169 | // represents the bucket. This functionality is currently only supported for A8 |
| 170 | SkColor fCanonicalColor; |
joshualitt | e4cee1f | 2015-05-11 13:04:28 -0700 | [diff] [blame] | 171 | SkPaint::Style fStyle; |
| 172 | SkPixelGeometry fPixelGeometry; |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 173 | bool fHasBlur; |
| 174 | |
| 175 | bool operator==(const Key& other) const { |
| 176 | return 0 == memcmp(this, &other, sizeof(Key)); |
| 177 | } |
| 178 | }; |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 179 | |
| 180 | struct StrokeInfo { |
| 181 | SkScalar fFrameWidth; |
| 182 | SkScalar fMiterLimit; |
| 183 | SkPaint::Join fJoin; |
| 184 | }; |
| 185 | |
| 186 | enum TextType { |
| 187 | kHasDistanceField_TextType = 0x1, |
| 188 | kHasBitmap_TextType = 0x2, |
| 189 | }; |
| 190 | |
| 191 | // all glyph / vertex offsets are into these pools. |
| 192 | unsigned char* fVertices; |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 193 | GrGlyph** fGlyphs; |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 194 | Run* fRuns; |
| 195 | GrMemoryPool* fPool; |
| 196 | SkMaskFilter::BlurRec fBlurRec; |
| 197 | StrokeInfo fStrokeInfo; |
| 198 | SkTArray<BigGlyph> fBigGlyphs; |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 199 | Key fKey; |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 200 | SkMatrix fViewMatrix; |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 201 | SkColor fPaintColor; |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 202 | SkScalar fX; |
| 203 | SkScalar fY; |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 204 | |
| 205 | // We can reuse distance field text, but only if the new viewmatrix would not result in |
| 206 | // a mip change. Because there can be multiple runs in a blob, we track the overall |
| 207 | // maximum minimum scale, and minimum maximum scale, we can support before we need to regen |
| 208 | SkScalar fMaxMinScale; |
| 209 | SkScalar fMinMaxScale; |
joshualitt | 8672f4d | 2015-04-21 08:03:04 -0700 | [diff] [blame] | 210 | int fRunCount; |
| 211 | uint8_t fTextType; |
| 212 | |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 213 | BitmapTextBlob() |
joshualitt | a7c6389 | 2015-04-21 13:24:37 -0700 | [diff] [blame] | 214 | : fMaxMinScale(-SK_ScalarMax) |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 215 | , fMinMaxScale(SK_ScalarMax) |
| 216 | , fTextType(0) {} |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 217 | |
joshualitt | 12c20e4 | 2015-04-22 11:24:20 -0700 | [diff] [blame] | 218 | ~BitmapTextBlob() override { |
| 219 | for (int i = 0; i < fRunCount; i++) { |
| 220 | fRuns[i].~Run(); |
| 221 | } |
| 222 | } |
| 223 | |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 224 | static const Key& GetKey(const BitmapTextBlob& blob) { |
| 225 | return blob.fKey; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 226 | } |
| 227 | |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 228 | static uint32_t Hash(const Key& key) { |
| 229 | return SkChecksum::Murmur3(&key, sizeof(Key)); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 230 | } |
| 231 | |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 232 | void operator delete(void* p) { |
| 233 | BitmapTextBlob* blob = reinterpret_cast<BitmapTextBlob*>(p); |
| 234 | blob->fPool->release(p); |
| 235 | } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 236 | void* operator new(size_t) { |
| 237 | SkFAIL("All blobs are created by placement new."); |
| 238 | return sk_malloc_throw(0); |
| 239 | } |
| 240 | |
| 241 | void* operator new(size_t, void* p) { return p; } |
| 242 | void operator delete(void* target, void* placement) { |
| 243 | ::operator delete(target, placement); |
| 244 | } |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 245 | |
| 246 | bool hasDistanceField() const { return SkToBool(fTextType & kHasDistanceField_TextType); } |
| 247 | bool hasBitmap() const { return SkToBool(fTextType & kHasBitmap_TextType); } |
| 248 | void setHasDistanceField() { fTextType |= kHasDistanceField_TextType; } |
| 249 | void setHasBitmap() { fTextType |= kHasBitmap_TextType; } |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 250 | }; |
| 251 | |
| 252 | typedef BitmapTextBlob::Run Run; |
| 253 | typedef Run::SubRunInfo PerSubRunInfo; |
| 254 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 255 | inline bool canDrawAsDistanceFields(const SkPaint&, const SkMatrix& viewMatrix); |
| 256 | BitmapTextBlob* setupDFBlob(int glyphCount, const SkPaint& origPaint, |
| 257 | const SkMatrix& viewMatrix, SkGlyphCache** cache, |
| 258 | SkPaint* dfPaint, SkScalar* textRatio); |
| 259 | void bmpAppendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left, int top, |
| 260 | GrColor color, GrFontScaler*, const SkIRect& clipRect); |
| 261 | bool dfAppendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, SkScalar sx, SkScalar sy, |
| 262 | GrColor color, GrFontScaler*, const SkIRect& clipRect, SkScalar textRatio, |
| 263 | const SkMatrix& viewMatrix); |
| 264 | inline void appendGlyphPath(BitmapTextBlob* blob, GrGlyph* glyph, |
| 265 | GrFontScaler* scaler, int x, int y); |
| 266 | inline void appendGlyphCommon(BitmapTextBlob*, Run*, Run::SubRunInfo*, |
| 267 | const SkRect& positions, GrColor color, |
| 268 | size_t vertexStride, bool useVertexColor, |
joshualitt | ae32c10 | 2015-04-21 09:37:57 -0700 | [diff] [blame] | 269 | GrGlyph*); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 270 | |
| 271 | inline void flushRunAsPaths(const SkTextBlob::RunIterator&, const SkPaint&, SkDrawFilter*, |
| 272 | const SkMatrix& viewMatrix, const SkIRect& clipBounds, SkScalar x, |
| 273 | SkScalar y); |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 274 | inline BitmapTextBatch* createBatch(BitmapTextBlob*, const PerSubRunInfo&, |
| 275 | int glyphCount, int run, int subRun, |
| 276 | GrColor, SkScalar transX, SkScalar transY, |
| 277 | const SkPaint&); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 278 | inline void flushRun(GrDrawTarget*, GrPipelineBuilder*, BitmapTextBlob*, int run, GrColor, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 279 | SkScalar transX, SkScalar transY, const SkPaint&); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 280 | inline void flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRenderTarget* rt, |
joshualitt | 1107e90 | 2015-05-11 14:52:11 -0700 | [diff] [blame^] | 281 | const SkPaint& skPaint, |
| 282 | SkScalar transX, SkScalar transY, const SkIRect& clipBounds); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 283 | |
| 284 | // We have to flush SkTextBlobs differently from drawText / drawPosText |
| 285 | void flush(GrDrawTarget*, const SkTextBlob*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&, |
| 286 | const GrPaint&, SkDrawFilter*, const GrClip&, const SkMatrix& viewMatrix, |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 287 | const SkIRect& clipBounds, SkScalar x, SkScalar y, SkScalar transX, SkScalar transY); |
joshualitt | 9a27e63 | 2015-04-06 10:53:36 -0700 | [diff] [blame] | 288 | void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&, |
joshualitt | 1107e90 | 2015-05-11 14:52:11 -0700 | [diff] [blame^] | 289 | const GrPaint&, const GrClip&, const SkIRect& clipBounds); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 290 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 291 | // A helper for drawing BitmapText in a run of distance fields |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 292 | inline void fallbackDrawPosText(BitmapTextBlob*, int runIndex, |
| 293 | GrRenderTarget*, const GrClip&, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 294 | const GrPaint&, |
| 295 | const SkPaint&, const SkMatrix& viewMatrix, |
| 296 | const SkTDArray<char>& fallbackTxt, |
| 297 | const SkTDArray<SkScalar>& fallbackPos, |
| 298 | int scalarsPerPosition, |
| 299 | const SkPoint& offset, |
| 300 | const SkIRect& clipRect); |
| 301 | |
| 302 | void internalDrawBMPText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 303 | GrColor color, const SkMatrix& viewMatrix, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 304 | const char text[], size_t byteLength, |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 305 | SkScalar x, SkScalar y, const SkIRect& clipRect); |
| 306 | void internalDrawBMPPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, |
| 307 | GrColor color, const SkMatrix& viewMatrix, |
| 308 | const char text[], size_t byteLength, |
| 309 | const SkScalar pos[], int scalarsPerPosition, |
| 310 | const SkPoint& offset, const SkIRect& clipRect); |
| 311 | |
| 312 | void internalDrawDFText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, |
| 313 | GrColor color, const SkMatrix& viewMatrix, |
| 314 | const char text[], size_t byteLength, |
| 315 | SkScalar x, SkScalar y, const SkIRect& clipRect, |
| 316 | SkScalar textRatio, |
| 317 | SkTDArray<char>* fallbackTxt, |
| 318 | SkTDArray<SkScalar>* fallbackPos, |
| 319 | SkPoint* offset, const SkPaint& origPaint); |
| 320 | void internalDrawDFPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, |
| 321 | GrColor color, const SkMatrix& viewMatrix, |
| 322 | const char text[], size_t byteLength, |
| 323 | const SkScalar pos[], int scalarsPerPosition, |
| 324 | const SkPoint& offset, const SkIRect& clipRect, |
| 325 | SkScalar textRatio, |
| 326 | SkTDArray<char>* fallbackTxt, |
| 327 | SkTDArray<SkScalar>* fallbackPos); |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 328 | |
| 329 | // 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] | 330 | inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 331 | inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix* viewMatrix, bool noGamma); |
joshualitt | 2a0e9f3 | 2015-04-13 06:12:21 -0700 | [diff] [blame] | 332 | static inline bool MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTransY, |
| 333 | const BitmapTextBlob&, const SkPaint&, |
joshualitt | 53b5f44 | 2015-04-13 06:33:59 -0700 | [diff] [blame] | 334 | const SkMaskFilter::BlurRec&, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 335 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y); |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 336 | void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, GrColor, |
| 337 | const SkMatrix& viewMatrix, |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 338 | const SkTextBlob* blob, SkScalar x, SkScalar y, |
joshualitt | fcfb9fc | 2015-04-21 07:35:10 -0700 | [diff] [blame] | 339 | SkDrawFilter* drawFilter, const SkIRect& clipRect, GrRenderTarget*, |
| 340 | const GrClip&, const GrPaint&); |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 341 | inline static bool HasLCD(const SkTextBlob*); |
joshualitt | 64c99cc | 2015-04-21 09:43:03 -0700 | [diff] [blame] | 342 | inline void initDistanceFieldPaint(BitmapTextBlob*, SkPaint*, SkScalar* textRatio, |
| 343 | const SkMatrix&); |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 344 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 345 | // Test methods |
| 346 | // TODO this is really ugly. It'd be much nicer if positioning could be moved to batch |
| 347 | inline BitmapTextBlob* createDrawTextBlob(GrRenderTarget*, const GrClip&, const GrPaint&, |
| 348 | const SkPaint&, const SkMatrix& viewMatrix, |
| 349 | const char text[], size_t byteLength, |
| 350 | SkScalar x, SkScalar y, |
| 351 | const SkIRect& regionClipBounds); |
| 352 | inline BitmapTextBlob* createDrawPosTextBlob(GrRenderTarget*, const GrClip&, const GrPaint&, |
| 353 | const SkPaint&, const SkMatrix& viewMatrix, |
| 354 | const char text[], size_t byteLength, |
| 355 | const SkScalar pos[], int scalarsPerPosition, |
| 356 | const SkPoint& offset, |
| 357 | const SkIRect& regionClipBounds); |
| 358 | |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 359 | // Distance field text needs this table to compute a value for use in the fragment shader. |
| 360 | // Because the GrAtlasTextContext can go out of scope before the final flush, this needs to be |
| 361 | // refcnted and malloced |
| 362 | struct DistanceAdjustTable : public SkNVRefCnt<DistanceAdjustTable> { |
| 363 | DistanceAdjustTable(float gamma) { this->buildDistanceAdjustTable(gamma); } |
| 364 | ~DistanceAdjustTable() { SkDELETE_ARRAY(fTable); } |
| 365 | |
| 366 | void buildDistanceAdjustTable(float gamma); |
| 367 | |
| 368 | SkScalar& operator[] (int i) { |
| 369 | return fTable[i]; |
| 370 | } |
| 371 | |
| 372 | const SkScalar& operator[] (int i) const { |
| 373 | return fTable[i]; |
| 374 | } |
| 375 | |
| 376 | SkScalar* fTable; |
| 377 | }; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 378 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 379 | GrBatchTextStrike* fCurrStrike; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 380 | GrTextBlobCache* fCache; |
joshualitt | 9bd2daf | 2015-04-17 09:30:06 -0700 | [diff] [blame] | 381 | bool fEnableDFRendering; |
| 382 | SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 383 | |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 384 | friend class GrTextBlobCache; |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 385 | friend class BitmapTextBatch; |
| 386 | |
joshualitt | 79dfb2b | 2015-05-11 08:58:08 -0700 | [diff] [blame] | 387 | #ifdef GR_TEST_UTILS |
| 388 | BATCH_TEST_FRIEND(TextBlob); |
| 389 | #endif |
| 390 | |
joshualitt | 1d89e8d | 2015-04-01 12:40:54 -0700 | [diff] [blame] | 391 | typedef GrTextContext INHERITED; |
| 392 | }; |
| 393 | |
| 394 | #endif |