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