joshualitt | 374b2f7 | 2015-07-21 08:05:03 -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 | |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 8 | #ifndef GrTextBlob_DEFINED |
| 9 | #define GrTextBlob_DEFINED |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 10 | |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 11 | #include "GrColor.h" |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 12 | #include "GrDrawOpAtlas.h" |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 13 | #include "GrGlyphCache.h" |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 14 | #include "GrTextTarget.h" |
Herb Derby | dc214c2 | 2018-11-08 13:31:39 -0500 | [diff] [blame] | 15 | #include "text/GrTextContext.h" |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 16 | #include "SkDescriptor.h" |
Mike Reed | 80747ef | 2018-01-23 15:29:32 -0500 | [diff] [blame] | 17 | #include "SkMaskFilterBase.h" |
mtklein | 4e97607 | 2016-08-08 09:06:27 -0700 | [diff] [blame] | 18 | #include "SkOpts.h" |
bsalomon | 8b6fa5e | 2016-05-19 16:23:47 -0700 | [diff] [blame] | 19 | #include "SkPathEffect.h" |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 20 | #include "SkPoint3.h" |
Mike Reed | 274218e | 2018-01-08 15:05:02 -0500 | [diff] [blame] | 21 | #include "SkRectPriv.h" |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 22 | #include "SkStrikeCache.h" |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 23 | #include "SkSurfaceProps.h" |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 24 | #include "SkTInternalLList.h" |
| 25 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 26 | class GrAtlasManager; |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 27 | struct GrDistanceFieldAdjustTable; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 28 | struct GrGlyph; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 29 | |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 30 | class SkTextBlob; |
| 31 | class SkTextBlobRunIterator; |
| 32 | |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 33 | // With this flag enabled, the GrTextContext will, as a sanity check, regenerate every blob |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 34 | // that comes in to verify the integrity of its cache |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 35 | #define CACHE_SANITY_CHECK 0 |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 36 | |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 37 | /* |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 38 | * A GrTextBlob contains a fully processed SkTextBlob, suitable for nearly immediate drawing |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 39 | * on the GPU. These are initially created with valid positions and colors, but invalid |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 40 | * texture coordinates. The GrTextBlob itself has a few Blob-wide properties, and also |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 41 | * consists of a number of runs. Runs inside a blob are flushed individually so they can be |
| 42 | * reordered. |
| 43 | * |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 44 | * The only thing(aside from a memcopy) required to flush a GrTextBlob is to ensure that |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 45 | * the GrAtlas will not evict anything the Blob needs. |
| 46 | * |
| 47 | * Note: This struct should really be named GrCachedAtasTextBlob, but that is too verbose. |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 48 | * |
| 49 | * *WARNING* If you add new fields to this struct, then you may need to to update AssertEqual |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 50 | */ |
Mike Klein | 408ef21 | 2018-10-30 15:23:00 +0000 | [diff] [blame] | 51 | class GrTextBlob : public SkNVRefCnt<GrTextBlob> { |
Herb Derby | dc214c2 | 2018-11-08 13:31:39 -0500 | [diff] [blame] | 52 | struct Run; |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 53 | public: |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 54 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrTextBlob); |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 55 | |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 56 | class VertexRegenerator; |
| 57 | |
Herb Derby | dc214c2 | 2018-11-08 13:31:39 -0500 | [diff] [blame] | 58 | void generateFromGlyphRunList(GrGlyphCache* glyphCache, |
| 59 | const GrShaderCaps& shaderCaps, |
| 60 | const GrTextContext::Options& options, |
| 61 | const SkPaint& paint, |
| 62 | const SkPMColor4f& filteredColor, |
| 63 | SkScalerContextFlags scalerContextFlags, |
| 64 | const SkMatrix& viewMatrix, |
| 65 | const SkSurfaceProps& props, |
| 66 | const SkGlyphRunList& glyphRunList, |
| 67 | SkGlyphRunListPainter* glyphPainter); |
| 68 | |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 69 | static sk_sp<GrTextBlob> Make(int glyphCount, int runCount); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 70 | |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 71 | /** |
| 72 | * We currently force regeneration of a blob if old or new matrix differ in having perspective. |
| 73 | * If we ever change that then the key must contain the perspectiveness when there are distance |
| 74 | * fields as perspective distance field use 3 component vertex positions and non-perspective |
| 75 | * uses 2. |
| 76 | */ |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 77 | struct Key { |
| 78 | Key() { |
| 79 | sk_bzero(this, sizeof(Key)); |
| 80 | } |
| 81 | uint32_t fUniqueID; |
| 82 | // Color may affect the gamma of the mask we generate, but in a fairly limited way. |
| 83 | // Each color is assigned to on of a fixed number of buckets based on its |
| 84 | // luminance. For each luminance bucket there is a "canonical color" that |
| 85 | // represents the bucket. This functionality is currently only supported for A8 |
| 86 | SkColor fCanonicalColor; |
| 87 | SkPaint::Style fStyle; |
| 88 | SkPixelGeometry fPixelGeometry; |
| 89 | bool fHasBlur; |
brianosman | 8d7ffce | 2016-04-21 08:29:06 -0700 | [diff] [blame] | 90 | uint32_t fScalerContextFlags; |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 91 | |
| 92 | bool operator==(const Key& other) const { |
| 93 | return 0 == memcmp(this, &other, sizeof(Key)); |
| 94 | } |
| 95 | }; |
| 96 | |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 97 | void setupKey(const GrTextBlob::Key& key, |
Mike Reed | 80747ef | 2018-01-23 15:29:32 -0500 | [diff] [blame] | 98 | const SkMaskFilterBase::BlurRec& blurRec, |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 99 | const SkPaint& paint) { |
| 100 | fKey = key; |
| 101 | if (key.fHasBlur) { |
| 102 | fBlurRec = blurRec; |
| 103 | } |
| 104 | if (key.fStyle != SkPaint::kFill_Style) { |
| 105 | fStrokeInfo.fFrameWidth = paint.getStrokeWidth(); |
| 106 | fStrokeInfo.fMiterLimit = paint.getStrokeMiter(); |
| 107 | fStrokeInfo.fJoin = paint.getStrokeJoin(); |
| 108 | } |
| 109 | } |
| 110 | |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 111 | static const Key& GetKey(const GrTextBlob& blob) { |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 112 | return blob.fKey; |
| 113 | } |
| 114 | |
| 115 | static uint32_t Hash(const Key& key) { |
mtklein | 4e97607 | 2016-08-08 09:06:27 -0700 | [diff] [blame] | 116 | return SkOpts::hash(&key, sizeof(Key)); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | void operator delete(void* p) { |
Herb Derby | b12175f | 2018-05-23 16:38:09 -0400 | [diff] [blame] | 120 | ::operator delete(p); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 121 | } |
Herb Derby | b12175f | 2018-05-23 16:38:09 -0400 | [diff] [blame] | 122 | |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 123 | void* operator new(size_t) { |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 124 | SK_ABORT("All blobs are created by placement new."); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 125 | return sk_malloc_throw(0); |
| 126 | } |
| 127 | |
| 128 | void* operator new(size_t, void* p) { return p; } |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 129 | |
| 130 | bool hasDistanceField() const { return SkToBool(fTextType & kHasDistanceField_TextType); } |
| 131 | bool hasBitmap() const { return SkToBool(fTextType & kHasBitmap_TextType); } |
| 132 | void setHasDistanceField() { fTextType |= kHasDistanceField_TextType; } |
| 133 | void setHasBitmap() { fTextType |= kHasBitmap_TextType; } |
| 134 | |
Herb Derby | 2bb343c | 2018-11-08 15:03:48 -0500 | [diff] [blame^] | 135 | int runCountLimit() const { return fRunCountLimit; } |
joshualitt | ddd22d8 | 2016-02-16 06:47:52 -0800 | [diff] [blame] | 136 | |
Herb Derby | 2bb343c | 2018-11-08 15:03:48 -0500 | [diff] [blame^] | 137 | Run* pushBackRun() { |
| 138 | SkASSERT(fRunCount < fRunCountLimit); |
| 139 | if (fRunCount > 0) { |
| 140 | Run::SubRunInfo& newRun = fRuns[fRunCount].fSubRunInfo.back(); |
| 141 | Run::SubRunInfo& lastRun = fRuns[fRunCount - 1].fSubRunInfo.back(); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 142 | newRun.setAsSuccessor(lastRun); |
| 143 | } |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 144 | |
Herb Derby | 2bb343c | 2018-11-08 15:03:48 -0500 | [diff] [blame^] | 145 | fRunCount++; |
| 146 | return &fRuns[fRunCount - 1]; |
Jim Van Verth | 89737de | 2018-02-06 21:30:20 +0000 | [diff] [blame] | 147 | } |
| 148 | |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 149 | void setMinAndMaxScale(SkScalar scaledMax, SkScalar scaledMin) { |
| 150 | // we init fMaxMinScale and fMinMaxScale in the constructor |
| 151 | fMaxMinScale = SkMaxScalar(scaledMax, fMaxMinScale); |
| 152 | fMinMaxScale = SkMinScalar(scaledMin, fMinMaxScale); |
| 153 | } |
| 154 | |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 155 | static size_t GetVertexStride(GrMaskFormat maskFormat, bool hasWCoord) { |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 156 | switch (maskFormat) { |
| 157 | case kA8_GrMaskFormat: |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 158 | return hasWCoord ? kGrayTextDFPerspectiveVASize : kGrayTextVASize; |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 159 | case kARGB_GrMaskFormat: |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 160 | return hasWCoord ? kColorTextPerspectiveVASize : kColorTextVASize; |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 161 | default: |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 162 | SkASSERT(!hasWCoord); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 163 | return kLCDTextVASize; |
| 164 | } |
| 165 | } |
| 166 | |
Herb Derby | 0edb214 | 2018-10-16 17:04:11 -0400 | [diff] [blame] | 167 | bool mustRegenerate(const SkPaint&, bool, const SkMaskFilterBase::BlurRec& blurRec, |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 168 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y); |
| 169 | |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 170 | void flush(GrTextTarget*, const SkSurfaceProps& props, |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 171 | const GrDistanceFieldAdjustTable* distanceAdjustTable, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 172 | const SkPaint& paint, const SkPMColor4f& filteredColor, const GrClip& clip, |
Robert Phillips | e4643cc | 2018-08-14 13:01:29 -0400 | [diff] [blame] | 173 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 174 | |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 175 | void computeSubRunBounds(SkRect* outBounds, int runIndex, int subRunIndex, |
Jim Van Verth | 7027691 | 2018-06-01 13:46:46 -0400 | [diff] [blame] | 176 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y, |
| 177 | bool needsGlyphTransform) { |
joshualitt | bc81111 | 2016-02-11 12:42:02 -0800 | [diff] [blame] | 178 | // We don't yet position distance field text on the cpu, so we have to map the vertex bounds |
| 179 | // into device space. |
| 180 | // We handle vertex bounds differently for distance field text and bitmap text because |
| 181 | // the vertex bounds of bitmap text are in device space. If we are flushing multiple runs |
| 182 | // from one blob then we are going to pay the price here of mapping the rect for each run. |
| 183 | const Run& run = fRuns[runIndex]; |
| 184 | const Run::SubRunInfo& subRun = run.fSubRunInfo[subRunIndex]; |
| 185 | *outBounds = subRun.vertexBounds(); |
Jim Van Verth | 7027691 | 2018-06-01 13:46:46 -0400 | [diff] [blame] | 186 | if (needsGlyphTransform) { |
joshualitt | bc81111 | 2016-02-11 12:42:02 -0800 | [diff] [blame] | 187 | // Distance field text is positioned with the (X,Y) as part of the glyph position, |
| 188 | // and currently the view matrix is applied on the GPU |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 189 | outBounds->offset(x - fInitialX, y - fInitialY); |
| 190 | viewMatrix.mapRect(outBounds); |
joshualitt | bc81111 | 2016-02-11 12:42:02 -0800 | [diff] [blame] | 191 | } else { |
| 192 | // Bitmap text is fully positioned on the CPU, and offset by an (X,Y) translate in |
| 193 | // device space. |
| 194 | SkMatrix boundsMatrix = fInitialViewMatrixInverse; |
| 195 | |
| 196 | boundsMatrix.postTranslate(-fInitialX, -fInitialY); |
| 197 | |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 198 | boundsMatrix.postTranslate(x, y); |
joshualitt | bc81111 | 2016-02-11 12:42:02 -0800 | [diff] [blame] | 199 | |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 200 | boundsMatrix.postConcat(viewMatrix); |
joshualitt | bc81111 | 2016-02-11 12:42:02 -0800 | [diff] [blame] | 201 | boundsMatrix.mapRect(outBounds); |
| 202 | |
| 203 | // Due to floating point numerical inaccuracies, we have to round out here |
| 204 | outBounds->roundOut(outBounds); |
| 205 | } |
| 206 | } |
| 207 | |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 208 | // position + local coord |
| 209 | static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16); |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 210 | static const size_t kColorTextPerspectiveVASize = sizeof(SkPoint3) + sizeof(SkIPoint16); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 211 | static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16); |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 212 | static const size_t kGrayTextDFPerspectiveVASize = |
| 213 | sizeof(SkPoint3) + sizeof(GrColor) + sizeof(SkIPoint16); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 214 | static const size_t kLCDTextVASize = kGrayTextVASize; |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 215 | static const size_t kMaxVASize = kGrayTextDFPerspectiveVASize; |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 216 | static const int kVerticesPerGlyph = 4; |
| 217 | |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 218 | static void AssertEqual(const GrTextBlob&, const GrTextBlob&); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 219 | |
| 220 | // The color here is the GrPaint color, and it is used to determine whether we |
| 221 | // have to regenerate LCD text blobs. |
| 222 | // We use this color vs the SkPaint color because it has the colorfilter applied. |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 223 | void initReusableBlob(SkColor luminanceColor, const SkMatrix& viewMatrix, |
| 224 | SkScalar x, SkScalar y) { |
Jim Van Verth | bc2cdd1 | 2017-06-08 11:14:35 -0400 | [diff] [blame] | 225 | fLuminanceColor = luminanceColor; |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 226 | this->setupViewMatrix(viewMatrix, x, y); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 227 | } |
| 228 | |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 229 | void initThrowawayBlob(const SkMatrix& viewMatrix, SkScalar x, SkScalar y) { |
| 230 | this->setupViewMatrix(viewMatrix, x, y); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 231 | } |
| 232 | |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 233 | const Key& key() const { return fKey; } |
| 234 | |
Herb Derby | b12175f | 2018-05-23 16:38:09 -0400 | [diff] [blame] | 235 | size_t size() const { return fSize; } |
| 236 | |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 237 | ~GrTextBlob() { |
Herb Derby | 2bb343c | 2018-11-08 15:03:48 -0500 | [diff] [blame^] | 238 | for (int i = 0; i < fRunCountLimit; i++) { |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 239 | fRuns[i].~Run(); |
| 240 | } |
| 241 | } |
| 242 | |
joshualitt | bc81111 | 2016-02-11 12:42:02 -0800 | [diff] [blame] | 243 | //////////////////////////////////////////////////////////////////////////////////////////////// |
| 244 | // Internal test methods |
Jim Van Verth | 56c3714 | 2017-10-31 14:44:25 -0400 | [diff] [blame] | 245 | std::unique_ptr<GrDrawOp> test_makeOp(int glyphCount, uint16_t run, uint16_t subRun, |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 246 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 247 | const SkPaint& paint, const SkPMColor4f& filteredColor, |
Herb Derby | bc6f9c9 | 2018-08-08 13:58:45 -0400 | [diff] [blame] | 248 | const SkSurfaceProps&, const GrDistanceFieldAdjustTable*, |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 249 | GrTextTarget*); |
joshualitt | bc81111 | 2016-02-11 12:42:02 -0800 | [diff] [blame] | 250 | |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 251 | private: |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 252 | GrTextBlob() |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 253 | : fMaxMinScale(-SK_ScalarMax) |
| 254 | , fMinMaxScale(SK_ScalarMax) |
| 255 | , fTextType(0) {} |
| 256 | |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 257 | |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 258 | // This function will only be called when we are generating a blob from scratch. We record the |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 259 | // initial view matrix and initial offsets(x,y), because we record vertex bounds relative to |
| 260 | // these numbers. When blobs are reused with new matrices, we need to return to model space so |
| 261 | // we can update the vertex bounds appropriately. |
| 262 | void setupViewMatrix(const SkMatrix& viewMatrix, SkScalar x, SkScalar y) { |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 263 | fInitialViewMatrix = viewMatrix; |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 264 | if (!viewMatrix.invert(&fInitialViewMatrixInverse)) { |
| 265 | fInitialViewMatrixInverse = SkMatrix::I(); |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 266 | } |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 267 | fInitialX = x; |
| 268 | fInitialY = y; |
| 269 | |
| 270 | // make sure all initial subruns have the correct VM and X/Y applied |
Herb Derby | 2bb343c | 2018-11-08 15:03:48 -0500 | [diff] [blame^] | 271 | for (int i = 0; i < fRunCountLimit; i++) { |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 272 | fRuns[i].fSubRunInfo[0].init(fInitialViewMatrix, x, y); |
| 273 | } |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 274 | } |
| 275 | |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 276 | /* |
| 277 | * Each Run inside of the blob can have its texture coordinates regenerated if required. |
| 278 | * To determine if regeneration is necessary, fAtlasGeneration is used. If there have been |
| 279 | * any evictions inside of the atlas, then we will simply regenerate Runs. We could track |
| 280 | * this at a more fine grained level, but its not clear if this is worth it, as evictions |
| 281 | * should be fairly rare. |
| 282 | * |
| 283 | * One additional point, each run can contain glyphs with any of the three mask formats. |
| 284 | * We call these SubRuns. Because a subrun must be a contiguous range, we have to create |
| 285 | * a new subrun each time the mask format changes in a run. In theory, a run can have as |
| 286 | * many SubRuns as it has glyphs, ie if a run alternates between color emoji and A8. In |
| 287 | * practice, the vast majority of runs have only a single subrun. |
| 288 | * |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 289 | * Finally, for runs where the entire thing is too large for the GrTextContext to |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 290 | * handle, we have a bit to mark the run as flushable via rendering as paths or as scaled |
| 291 | * glyphs. It would be a bit expensive to figure out ahead of time whether or not a run |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 292 | * can flush in this manner, so we always allocate vertices for the run, regardless of |
| 293 | * whether or not it is too large. The benefit of this strategy is that we can always reuse |
| 294 | * a blob allocation regardless of viewmatrix changes. We could store positions for these |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 295 | * glyphs, however, it's not clear if this is a win because we'd still have to either go to the |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 296 | * glyph cache to get the path at flush time, or hold onto the path in the cache, which |
| 297 | * would greatly increase the memory of these cached items. |
| 298 | */ |
| 299 | struct Run { |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 300 | Run() : fPaintFlags(0) |
| 301 | , fInitialized(false) { |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 302 | // To ensure we always have one subrun, we push back a fresh run here |
| 303 | fSubRunInfo.push_back(); |
| 304 | } |
| 305 | struct SubRunInfo { |
| 306 | SubRunInfo() |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 307 | : fAtlasGeneration(GrDrawOpAtlas::kInvalidAtlasGeneration) |
| 308 | , fVertexStartIndex(0) |
| 309 | , fVertexEndIndex(0) |
| 310 | , fGlyphStartIndex(0) |
| 311 | , fGlyphEndIndex(0) |
| 312 | , fColor(GrColor_ILLEGAL) |
| 313 | , fMaskFormat(kA8_GrMaskFormat) |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 314 | , fFlags(0) { |
Mike Reed | 274218e | 2018-01-08 15:05:02 -0500 | [diff] [blame] | 315 | fVertexBounds = SkRectPriv::MakeLargestInverted(); |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 316 | } |
joshualitt | 7e97b0b | 2015-07-31 15:18:08 -0700 | [diff] [blame] | 317 | SubRunInfo(const SubRunInfo& that) |
| 318 | : fBulkUseToken(that.fBulkUseToken) |
| 319 | , fStrike(SkSafeRef(that.fStrike.get())) |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 320 | , fCurrentViewMatrix(that.fCurrentViewMatrix) |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 321 | , fVertexBounds(that.fVertexBounds) |
joshualitt | 7e97b0b | 2015-07-31 15:18:08 -0700 | [diff] [blame] | 322 | , fAtlasGeneration(that.fAtlasGeneration) |
| 323 | , fVertexStartIndex(that.fVertexStartIndex) |
| 324 | , fVertexEndIndex(that.fVertexEndIndex) |
| 325 | , fGlyphStartIndex(that.fGlyphStartIndex) |
| 326 | , fGlyphEndIndex(that.fGlyphEndIndex) |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 327 | , fX(that.fX) |
| 328 | , fY(that.fY) |
joshualitt | f9e658b | 2015-12-09 09:26:44 -0800 | [diff] [blame] | 329 | , fColor(that.fColor) |
joshualitt | 7e97b0b | 2015-07-31 15:18:08 -0700 | [diff] [blame] | 330 | , fMaskFormat(that.fMaskFormat) |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 331 | , fFlags(that.fFlags) { |
joshualitt | 7e97b0b | 2015-07-31 15:18:08 -0700 | [diff] [blame] | 332 | } |
joshualitt | 3660d53 | 2015-12-07 11:32:50 -0800 | [diff] [blame] | 333 | |
joshualitt | 18b072d | 2015-12-07 12:26:12 -0800 | [diff] [blame] | 334 | // TODO when this object is more internal, drop the privacy |
joshualitt | 3660d53 | 2015-12-07 11:32:50 -0800 | [diff] [blame] | 335 | void resetBulkUseToken() { fBulkUseToken.reset(); } |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 336 | GrDrawOpAtlas::BulkUseTokenUpdater* bulkUseToken() { return &fBulkUseToken; } |
Robert Phillips | caf1ebb | 2018-03-01 14:28:44 -0500 | [diff] [blame] | 337 | void setStrike(sk_sp<GrTextStrike> strike) { fStrike = std::move(strike); } |
| 338 | GrTextStrike* strike() const { return fStrike.get(); } |
| 339 | sk_sp<GrTextStrike> refStrike() const { return fStrike; } |
joshualitt | 3660d53 | 2015-12-07 11:32:50 -0800 | [diff] [blame] | 340 | |
| 341 | void setAtlasGeneration(uint64_t atlasGeneration) { fAtlasGeneration = atlasGeneration;} |
| 342 | uint64_t atlasGeneration() const { return fAtlasGeneration; } |
| 343 | |
| 344 | size_t byteCount() const { return fVertexEndIndex - fVertexStartIndex; } |
joshualitt | 3660d53 | 2015-12-07 11:32:50 -0800 | [diff] [blame] | 345 | size_t vertexStartIndex() const { return fVertexStartIndex; } |
joshualitt | 3660d53 | 2015-12-07 11:32:50 -0800 | [diff] [blame] | 346 | size_t vertexEndIndex() const { return fVertexEndIndex; } |
| 347 | void appendVertices(size_t vertexStride) { |
| 348 | fVertexEndIndex += vertexStride * kVerticesPerGlyph; |
| 349 | } |
| 350 | |
| 351 | uint32_t glyphCount() const { return fGlyphEndIndex - fGlyphStartIndex; } |
joshualitt | 3660d53 | 2015-12-07 11:32:50 -0800 | [diff] [blame] | 352 | uint32_t glyphStartIndex() const { return fGlyphStartIndex; } |
joshualitt | 3660d53 | 2015-12-07 11:32:50 -0800 | [diff] [blame] | 353 | uint32_t glyphEndIndex() const { return fGlyphEndIndex; } |
| 354 | void glyphAppended() { fGlyphEndIndex++; } |
joshualitt | f9e658b | 2015-12-09 09:26:44 -0800 | [diff] [blame] | 355 | void setColor(GrColor color) { fColor = color; } |
| 356 | GrColor color() const { return fColor; } |
joshualitt | 3660d53 | 2015-12-07 11:32:50 -0800 | [diff] [blame] | 357 | void setMaskFormat(GrMaskFormat format) { fMaskFormat = format; } |
| 358 | GrMaskFormat maskFormat() const { return fMaskFormat; } |
| 359 | |
joshualitt | 18b072d | 2015-12-07 12:26:12 -0800 | [diff] [blame] | 360 | void setAsSuccessor(const SubRunInfo& prev) { |
| 361 | fGlyphStartIndex = prev.glyphEndIndex(); |
| 362 | fGlyphEndIndex = prev.glyphEndIndex(); |
| 363 | |
| 364 | fVertexStartIndex = prev.vertexEndIndex(); |
| 365 | fVertexEndIndex = prev.vertexEndIndex(); |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 366 | |
| 367 | // copy over viewmatrix settings |
| 368 | this->init(prev.fCurrentViewMatrix, prev.fX, prev.fY); |
joshualitt | 18b072d | 2015-12-07 12:26:12 -0800 | [diff] [blame] | 369 | } |
| 370 | |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 371 | const SkRect& vertexBounds() const { return fVertexBounds; } |
| 372 | void joinGlyphBounds(const SkRect& glyphBounds) { |
| 373 | fVertexBounds.joinNonEmptyArg(glyphBounds); |
| 374 | } |
| 375 | |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 376 | void init(const SkMatrix& viewMatrix, SkScalar x, SkScalar y) { |
| 377 | fCurrentViewMatrix = viewMatrix; |
| 378 | fX = x; |
| 379 | fY = y; |
| 380 | } |
| 381 | |
| 382 | // This function assumes the translation will be applied before it is called again |
| 383 | void computeTranslation(const SkMatrix& viewMatrix, SkScalar x, SkScalar y, |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 384 | SkScalar* transX, SkScalar* transY); |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 385 | |
joshualitt | 3660d53 | 2015-12-07 11:32:50 -0800 | [diff] [blame] | 386 | // df properties |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 387 | void setDrawAsDistanceFields() { fFlags |= kDrawAsSDF_Flag; } |
| 388 | bool drawAsDistanceFields() const { return SkToBool(fFlags & kDrawAsSDF_Flag); } |
| 389 | void setUseLCDText(bool useLCDText) { |
| 390 | fFlags = useLCDText ? fFlags | kUseLCDText_Flag : fFlags & ~kUseLCDText_Flag; |
| 391 | } |
| 392 | bool hasUseLCDText() const { return SkToBool(fFlags & kUseLCDText_Flag); } |
| 393 | void setAntiAliased(bool antiAliased) { |
| 394 | fFlags = antiAliased ? fFlags | kAntiAliased_Flag : fFlags & ~kAntiAliased_Flag; |
| 395 | } |
| 396 | bool isAntiAliased() const { return SkToBool(fFlags & kAntiAliased_Flag); } |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 397 | void setHasWCoord(bool hasW) { |
| 398 | fFlags = hasW ? (fFlags | kHasWCoord_Flag) : fFlags & ~kHasWCoord_Flag; |
| 399 | } |
| 400 | bool hasWCoord() const { return SkToBool(fFlags & kHasWCoord_Flag); } |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 401 | void setNeedsTransform(bool needsTransform) { |
| 402 | fFlags = needsTransform ? (fFlags | kNeedsTransform_Flag) |
| 403 | : fFlags & ~kNeedsTransform_Flag; |
Jim Van Verth | cf838c7 | 2018-03-05 14:40:36 -0500 | [diff] [blame] | 404 | } |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 405 | bool needsTransform() const { return SkToBool(fFlags & kNeedsTransform_Flag); } |
joshualitt | 3660d53 | 2015-12-07 11:32:50 -0800 | [diff] [blame] | 406 | |
| 407 | private: |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 408 | enum Flag { |
Jim Van Verth | cf838c7 | 2018-03-05 14:40:36 -0500 | [diff] [blame] | 409 | kDrawAsSDF_Flag = 0x01, |
| 410 | kUseLCDText_Flag = 0x02, |
| 411 | kAntiAliased_Flag = 0x04, |
| 412 | kHasWCoord_Flag = 0x08, |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 413 | kNeedsTransform_Flag = 0x10 |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 414 | }; |
| 415 | |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 416 | GrDrawOpAtlas::BulkUseTokenUpdater fBulkUseToken; |
Robert Phillips | caf1ebb | 2018-03-01 14:28:44 -0500 | [diff] [blame] | 417 | sk_sp<GrTextStrike> fStrike; |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 418 | SkMatrix fCurrentViewMatrix; |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 419 | SkRect fVertexBounds; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 420 | uint64_t fAtlasGeneration; |
| 421 | size_t fVertexStartIndex; |
| 422 | size_t fVertexEndIndex; |
| 423 | uint32_t fGlyphStartIndex; |
| 424 | uint32_t fGlyphEndIndex; |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 425 | SkScalar fX; |
| 426 | SkScalar fY; |
joshualitt | f9e658b | 2015-12-09 09:26:44 -0800 | [diff] [blame] | 427 | GrColor fColor; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 428 | GrMaskFormat fMaskFormat; |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 429 | uint32_t fFlags; |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 430 | }; // SubRunInfo |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 431 | |
Herb Derby | 2bb343c | 2018-11-08 15:03:48 -0500 | [diff] [blame^] | 432 | // sets the last subrun of runIndex to use w values |
| 433 | void setSubRunHasW(bool hasWCoord) { |
| 434 | Run::SubRunInfo& subRun = this->fSubRunInfo.back(); |
| 435 | subRun.setHasWCoord(hasWCoord); |
| 436 | } |
| 437 | |
| 438 | // inits the override descriptor on the current run. All following subruns must use this |
| 439 | // descriptor |
| 440 | void initOverride() { |
| 441 | // Push back a new subrun to fill and set the override descriptor |
| 442 | this->pushBackSubRun(); |
| 443 | fOverrideDescriptor.reset(new SkAutoDescriptor); |
| 444 | } |
| 445 | |
| 446 | // Appends a glyph to the blob as a path only. |
| 447 | void appendPathGlyph( |
| 448 | const SkPath& path, SkPoint position, SkScalar scale, bool preTransformed); |
| 449 | |
| 450 | // Appends a glyph to the blob. If the glyph is too large, the glyph will be appended |
| 451 | // as a path. |
| 452 | void appendGlyph(GrTextBlob* blob, |
| 453 | const sk_sp<GrTextStrike>& strike, |
| 454 | const SkGlyph& skGlyph, GrGlyph::MaskStyle maskStyle, |
| 455 | SkPoint origin, |
| 456 | const SkPMColor4f& color, SkGlyphCache* skGlyphCache, |
| 457 | SkScalar textRatio, bool needsTransform); |
| 458 | |
| 459 | SkExclusiveStrikePtr setupCache(const SkPaint& skPaint, |
| 460 | const SkSurfaceProps& props, |
| 461 | SkScalerContextFlags scalerContextFlags, |
| 462 | const SkMatrix& viewMatrix); |
| 463 | |
| 464 | void setRunPaintFlags(uint16_t paintFlags) { |
| 465 | fPaintFlags = paintFlags & Run::kPaintFlagsMask; |
| 466 | } |
| 467 | |
| 468 | // sets the last subrun of runIndex to use distance field text |
| 469 | void setSubRunHasDistanceFields(bool hasLCD, bool isAntiAlias, bool hasWCoord) { |
| 470 | Run::SubRunInfo& subRun = fSubRunInfo.back(); |
| 471 | subRun.setUseLCDText(hasLCD); |
| 472 | subRun.setAntiAliased(isAntiAlias); |
| 473 | subRun.setDrawAsDistanceFields(); |
| 474 | subRun.setHasWCoord(hasWCoord); |
| 475 | } |
| 476 | |
| 477 | SubRunInfo& pushBackSubRun() { |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 478 | // Forward glyph / vertex information to seed the new sub run |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 479 | SubRunInfo& newSubRun = fSubRunInfo.push_back(); |
joshualitt | 18b072d | 2015-12-07 12:26:12 -0800 | [diff] [blame] | 480 | const SubRunInfo& prevSubRun = fSubRunInfo.fromBack(1); |
joshualitt | e43e3bd | 2015-07-29 11:10:38 -0700 | [diff] [blame] | 481 | |
joshualitt | 18b072d | 2015-12-07 12:26:12 -0800 | [diff] [blame] | 482 | newSubRun.setAsSuccessor(prevSubRun); |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 483 | return newSubRun; |
| 484 | } |
| 485 | static const int kMinSubRuns = 1; |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 486 | sk_sp<SkTypeface> fTypeface; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 487 | SkSTArray<kMinSubRuns, SubRunInfo> fSubRunInfo; |
| 488 | SkAutoDescriptor fDescriptor; |
bsalomon | 8b6fa5e | 2016-05-19 16:23:47 -0700 | [diff] [blame] | 489 | |
| 490 | // Effects from the paint that are used to build a SkScalerContext. |
| 491 | sk_sp<SkPathEffect> fPathEffect; |
bsalomon | 8b6fa5e | 2016-05-19 16:23:47 -0700 | [diff] [blame] | 492 | sk_sp<SkMaskFilter> fMaskFilter; |
joshualitt | 3660d53 | 2015-12-07 11:32:50 -0800 | [diff] [blame] | 493 | |
| 494 | // Distance field text cannot draw coloremoji, and so has to fall back. However, |
| 495 | // though the distance field text and the coloremoji may share the same run, they |
| 496 | // will have different descriptors. If fOverrideDescriptor is non-nullptr, then it |
| 497 | // will be used in place of the run's descriptor to regen texture coords |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 498 | std::unique_ptr<SkAutoDescriptor> fOverrideDescriptor; // df properties |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 499 | |
| 500 | // Any glyphs that can't be rendered with the base or override descriptor |
| 501 | // are rendered as paths |
| 502 | struct PathGlyph { |
| 503 | PathGlyph(const SkPath& path, SkScalar x, SkScalar y, SkScalar scale, bool preXformed) |
| 504 | : fPath(path) |
| 505 | , fX(x) |
| 506 | , fY(y) |
| 507 | , fScale(scale) |
| 508 | , fPreTransformed(preXformed) {} |
| 509 | SkPath fPath; |
| 510 | SkScalar fX; |
| 511 | SkScalar fY; |
| 512 | SkScalar fScale; |
| 513 | bool fPreTransformed; |
| 514 | }; |
| 515 | |
| 516 | SkTArray<PathGlyph> fPathGlyphs; |
| 517 | |
| 518 | struct { |
| 519 | unsigned fPaintFlags : 16; // needed mainly for rendering paths |
| 520 | bool fInitialized : 1; |
| 521 | }; |
| 522 | // the only flags we need to set |
| 523 | static constexpr auto kPaintFlagsMask = SkPaint::kAntiAlias_Flag; |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 524 | }; // Run |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 525 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 526 | inline std::unique_ptr<GrAtlasTextOp> makeOp( |
Jim Van Verth | 56c3714 | 2017-10-31 14:44:25 -0400 | [diff] [blame] | 527 | const Run::SubRunInfo& info, int glyphCount, uint16_t run, uint16_t subRun, |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 528 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipRect, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 529 | const SkPaint& paint, const SkPMColor4f& filteredColor, const SkSurfaceProps&, |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 530 | const GrDistanceFieldAdjustTable*, GrTextTarget*); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 531 | |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 532 | struct StrokeInfo { |
| 533 | SkScalar fFrameWidth; |
| 534 | SkScalar fMiterLimit; |
| 535 | SkPaint::Join fJoin; |
| 536 | }; |
| 537 | |
| 538 | enum TextType { |
| 539 | kHasDistanceField_TextType = 0x1, |
| 540 | kHasBitmap_TextType = 0x2, |
| 541 | }; |
| 542 | |
| 543 | // all glyph / vertex offsets are into these pools. |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 544 | char* fVertices; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 545 | GrGlyph** fGlyphs; |
| 546 | Run* fRuns; |
Mike Reed | 80747ef | 2018-01-23 15:29:32 -0500 | [diff] [blame] | 547 | SkMaskFilterBase::BlurRec fBlurRec; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 548 | StrokeInfo fStrokeInfo; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 549 | Key fKey; |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 550 | SkMatrix fInitialViewMatrix; |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 551 | SkMatrix fInitialViewMatrixInverse; |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 552 | size_t fSize; |
Jim Van Verth | bc2cdd1 | 2017-06-08 11:14:35 -0400 | [diff] [blame] | 553 | SkColor fLuminanceColor; |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 554 | SkScalar fInitialX; |
| 555 | SkScalar fInitialY; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 556 | |
| 557 | // We can reuse distance field text, but only if the new viewmatrix would not result in |
| 558 | // a mip change. Because there can be multiple runs in a blob, we track the overall |
| 559 | // maximum minimum scale, and minimum maximum scale, we can support before we need to regen |
| 560 | SkScalar fMaxMinScale; |
| 561 | SkScalar fMinMaxScale; |
Herb Derby | 2bb343c | 2018-11-08 15:03:48 -0500 | [diff] [blame^] | 562 | int fRunCount{0}; |
| 563 | int fRunCountLimit; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 564 | uint8_t fTextType; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 565 | }; |
| 566 | |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 567 | /** |
| 568 | * Used to produce vertices for a subrun of a blob. The vertices are cached in the blob itself. |
| 569 | * This is invoked each time a sub run is drawn. It regenerates the vertex data as required either |
| 570 | * because of changes to the atlas or because of different draw parameters (e.g. color change). In |
| 571 | * rare cases the draw may have to interrupted and flushed in the middle of the sub run in order to |
| 572 | * free up atlas space. Thus, this generator is stateful and should be invoked in a loop until the |
| 573 | * entire sub run has been completed. |
| 574 | */ |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 575 | class GrTextBlob::VertexRegenerator { |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 576 | public: |
| 577 | /** |
| 578 | * Consecutive VertexRegenerators often use the same SkGlyphCache. If the same instance of |
| 579 | * SkAutoGlyphCache is reused then it can save the cost of multiple detach/attach operations of |
| 580 | * SkGlyphCache. |
| 581 | */ |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 582 | VertexRegenerator(GrResourceProvider*, GrTextBlob*, int runIdx, int subRunIdx, |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 583 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y, GrColor color, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 584 | GrDeferredUploadTarget*, GrGlyphCache*, GrAtlasManager*, |
Herb Derby | 7956b59 | 2018-03-22 16:10:30 -0400 | [diff] [blame] | 585 | SkExclusiveStrikePtr*); |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 586 | |
| 587 | struct Result { |
| 588 | /** |
| 589 | * Was regenerate() able to draw all the glyphs from the sub run? If not flush all glyph |
| 590 | * draws and call regenerate() again. |
| 591 | */ |
| 592 | bool fFinished = true; |
| 593 | |
| 594 | /** |
| 595 | * How many glyphs were regenerated. Will be equal to the sub run's glyph count if |
| 596 | * fType is kFinished. |
| 597 | */ |
| 598 | int fGlyphsRegenerated = 0; |
| 599 | |
| 600 | /** |
| 601 | * Pointer where the caller finds the first regenerated vertex. |
| 602 | */ |
| 603 | const char* fFirstVertex; |
| 604 | }; |
| 605 | |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 606 | bool regenerate(Result*); |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 607 | |
| 608 | private: |
| 609 | template <bool regenPos, bool regenCol, bool regenTexCoords, bool regenGlyphs> |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 610 | bool doRegen(Result*); |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 611 | |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 612 | GrResourceProvider* fResourceProvider; |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 613 | const SkMatrix& fViewMatrix; |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 614 | GrTextBlob* fBlob; |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 615 | GrDeferredUploadTarget* fUploadTarget; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 616 | GrGlyphCache* fGlyphCache; |
| 617 | GrAtlasManager* fFullAtlasManager; |
Herb Derby | 8c4cbf4 | 2018-03-09 15:28:04 -0500 | [diff] [blame] | 618 | SkExclusiveStrikePtr* fLazyCache; |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 619 | Run* fRun; |
| 620 | Run::SubRunInfo* fSubRun; |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 621 | GrColor fColor; |
| 622 | SkScalar fTransX; |
| 623 | SkScalar fTransY; |
| 624 | |
| 625 | uint32_t fRegenFlags = 0; |
| 626 | int fCurrGlyph = 0; |
| 627 | bool fBrokenRun = false; |
| 628 | }; |
| 629 | |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 630 | #endif // GrTextBlob_DEFINED |