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