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/SkPoint3.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/core/SkDescriptor.h" |
| 13 | #include "src/core/SkMaskFilterBase.h" |
| 14 | #include "src/core/SkOpts.h" |
| 15 | #include "src/core/SkRectPriv.h" |
Herb Derby | e7efd08 | 2019-05-28 11:30:33 -0400 | [diff] [blame] | 16 | #include "src/core/SkStrikeSpec.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrDrawOpAtlas.h" |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 19 | |
Brian Salomon | 43cbd72 | 2020-01-03 22:09:12 -0500 | [diff] [blame] | 20 | #include <limits> |
| 21 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 22 | class GrAtlasManager; |
Herb Derby | 660c2ff | 2019-11-14 18:22:41 -0500 | [diff] [blame] | 23 | class GrAtlasTextOp; |
Robert Phillips | 5fa68b4 | 2020-03-31 08:34:22 -0400 | [diff] [blame] | 24 | class GrGlyph; |
Robert Phillips | 41bd97d | 2020-04-07 14:19:37 -0400 | [diff] [blame^] | 25 | class GrStrikeCache; |
| 26 | class GrTextContext; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 27 | |
Robert Phillips | 41bd97d | 2020-04-07 14:19:37 -0400 | [diff] [blame^] | 28 | class SkSurfaceProps; |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 29 | class SkTextBlob; |
| 30 | class SkTextBlobRunIterator; |
| 31 | |
Herb Derby | c514e7d | 2019-12-11 17:00:31 -0500 | [diff] [blame] | 32 | |
| 33 | // A GrTextBlob contains a fully processed SkTextBlob, suitable for nearly immediate drawing |
| 34 | // on the GPU. These are initially created with valid positions and colors, but invalid |
| 35 | // texture coordinates. |
| 36 | // |
| 37 | // A GrTextBlob contains a number of SubRuns that are created in the blob's arena. Each SubRun |
| 38 | // tracks its own GrGlyph* and vertex data. The memory is organized in the arena in the following |
| 39 | // way so that the pointers for the GrGlyph* and vertex data are known before creating the SubRun. |
| 40 | // |
| 41 | // GrGlyph*... | vertexData... | SubRun | GrGlyph*... | vertexData... | SubRun etc. |
| 42 | // |
Herb Derby | 5bf5b04 | 2019-12-12 16:37:03 -0500 | [diff] [blame] | 43 | // In these classes, I'm trying to follow the convention about matrices and origins. |
| 44 | // * draw Matrix|Origin - describes the current draw command. |
| 45 | // * initial Matrix|Origin - describes the matrix and origin the GrTextBlob was created with. |
| 46 | // * current Matrix|Origin - describes the matrix and origin that are currently in the SubRun's |
| 47 | // vertex data. |
| 48 | // |
| 49 | // When handling repeated drawing using the same GrTextBlob initial data are compared to drawing |
| 50 | // data to see if this blob can service this drawing. If it can, but small changes are needed to |
| 51 | // the vertex data, the current data of the SubRuns is adjusted to conform to the drawing data |
| 52 | // from the op using the VertexRegenerator. |
| 53 | // |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 54 | class GrTextBlob final : public SkNVRefCnt<GrTextBlob>, public SkGlyphRunPainterInterface { |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 55 | public: |
Herb Derby | 660c2ff | 2019-11-14 18:22:41 -0500 | [diff] [blame] | 56 | class SubRun; |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 57 | class VertexRegenerator; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 58 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 59 | enum SubRunType { |
| 60 | kDirectMask, |
| 61 | kTransformedMask, |
| 62 | kTransformedPath, |
| 63 | kTransformedSDFT |
| 64 | }; |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 65 | |
| 66 | struct Key { |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 67 | Key(); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 68 | uint32_t fUniqueID; |
| 69 | // Color may affect the gamma of the mask we generate, but in a fairly limited way. |
| 70 | // Each color is assigned to on of a fixed number of buckets based on its |
| 71 | // luminance. For each luminance bucket there is a "canonical color" that |
| 72 | // represents the bucket. This functionality is currently only supported for A8 |
| 73 | SkColor fCanonicalColor; |
| 74 | SkPaint::Style fStyle; |
Herb Derby | 5c7f38a | 2019-12-13 16:28:42 +0000 | [diff] [blame] | 75 | SkPixelGeometry fPixelGeometry; |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 76 | bool fHasBlur; |
Herb Derby | 5c7f38a | 2019-12-13 16:28:42 +0000 | [diff] [blame] | 77 | uint32_t fScalerContextFlags; |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 78 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 79 | bool operator==(const Key& other) const; |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 80 | }; |
| 81 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 82 | // Any glyphs that can't be rendered with the base or override descriptor |
| 83 | // are rendered as paths |
| 84 | struct PathGlyph { |
| 85 | PathGlyph(const SkPath& path, SkPoint origin); |
| 86 | SkPath fPath; |
| 87 | SkPoint fOrigin; |
| 88 | }; |
| 89 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 90 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrTextBlob); |
| 91 | |
| 92 | // Change memory management to handle the data after GrTextBlob, but in the same allocation |
| 93 | // of memory. Only allow placement new. |
| 94 | void operator delete(void* p); |
| 95 | void* operator new(size_t); |
| 96 | void* operator new(size_t, void* p); |
| 97 | |
| 98 | ~GrTextBlob() override; |
| 99 | |
| 100 | // Make an empty GrTextBlob, with all the invariants set to make the right decisions when |
| 101 | // adding SubRuns. |
Herb Derby | 659e409 | 2019-12-06 15:38:10 -0500 | [diff] [blame] | 102 | static sk_sp<GrTextBlob> Make(const SkGlyphRunList& glyphRunList, |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 103 | GrStrikeCache* strikeCache, |
Herb Derby | 1c5be7b | 2019-12-13 12:03:06 -0500 | [diff] [blame] | 104 | const SkMatrix& drawMatrix, |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 105 | GrColor color, |
| 106 | bool forceWForDistanceFields); |
| 107 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 108 | // Key manipulation functions |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 109 | void setupKey(const GrTextBlob::Key& key, |
Mike Reed | 80747ef | 2018-01-23 15:29:32 -0500 | [diff] [blame] | 110 | const SkMaskFilterBase::BlurRec& blurRec, |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 111 | const SkPaint& paint); |
| 112 | static const Key& GetKey(const GrTextBlob& blob); |
| 113 | static uint32_t Hash(const Key& key); |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 114 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 115 | bool hasDistanceField() const; |
| 116 | bool hasBitmap() const; |
| 117 | bool hasPerspective() const; |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 118 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 119 | void setHasDistanceField(); |
| 120 | void setHasBitmap(); |
| 121 | void setMinAndMaxScale(SkScalar scaledMin, SkScalar scaledMax); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 122 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 123 | static size_t GetVertexStride(GrMaskFormat maskFormat, bool hasWCoord); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 124 | |
Herb Derby | 0edb214 | 2018-10-16 17:04:11 -0400 | [diff] [blame] | 125 | bool mustRegenerate(const SkPaint&, bool, const SkMaskFilterBase::BlurRec& blurRec, |
Herb Derby | 5bf5b04 | 2019-12-12 16:37:03 -0500 | [diff] [blame] | 126 | const SkMatrix& drawMatrix, SkPoint drawOrigin); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 127 | |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 128 | void flush(GrTextTarget*, const SkSurfaceProps& props, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 129 | const SkPaint& paint, const SkPMColor4f& filteredColor, const GrClip& clip, |
Herb Derby | 5bf5b04 | 2019-12-12 16:37:03 -0500 | [diff] [blame] | 130 | const SkMatrix& drawMatrix, SkPoint drawOrigin); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 131 | |
Herb Derby | 660c2ff | 2019-11-14 18:22:41 -0500 | [diff] [blame] | 132 | void computeSubRunBounds(SkRect* outBounds, const SubRun& subRun, |
Herb Derby | 5bf5b04 | 2019-12-12 16:37:03 -0500 | [diff] [blame] | 133 | const SkMatrix& drawMatrix, SkPoint drawOrigin, |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 134 | bool needsGlyphTransform); |
joshualitt | bc81111 | 2016-02-11 12:42:02 -0800 | [diff] [blame] | 135 | |
Herb Derby | cd498e1 | 2019-12-06 14:17:31 -0500 | [diff] [blame] | 136 | // Normal text mask, SDFT, or color. |
| 137 | struct Mask2DVertex { |
| 138 | SkPoint devicePos; |
| 139 | GrColor color; |
| 140 | SkIPoint16 atlasPos; |
| 141 | }; |
| 142 | struct ARGB2DVertex { |
| 143 | SkPoint devicePos; |
| 144 | SkIPoint16 atlasPos; |
| 145 | }; |
| 146 | |
| 147 | // Perspective SDFT or SDFT forced to 3D or perspective color. |
| 148 | struct SDFT3DVertex { |
| 149 | SkPoint3 devicePos; |
| 150 | GrColor color; |
| 151 | SkIPoint16 atlasPos; |
| 152 | }; |
| 153 | struct ARGB3DVertex { |
| 154 | SkPoint3 devicePos; |
| 155 | SkIPoint16 atlasPos; |
| 156 | }; |
| 157 | |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 158 | static const int kVerticesPerGlyph = 4; |
| 159 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 160 | const Key& key() const; |
| 161 | size_t size() const; |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 162 | |
joshualitt | bc81111 | 2016-02-11 12:42:02 -0800 | [diff] [blame] | 163 | // Internal test methods |
Robert Phillips | 841c9a5 | 2020-03-27 12:41:31 -0400 | [diff] [blame] | 164 | std::unique_ptr<GrDrawOp> test_makeOp(int glyphCount, const SkMatrix& drawMatrix, |
| 165 | SkPoint drawOrigin, const SkPaint& paint, |
| 166 | const SkPMColor4f& filteredColor, const SkSurfaceProps&, |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 167 | GrTextTarget*); |
joshualitt | bc81111 | 2016-02-11 12:42:02 -0800 | [diff] [blame] | 168 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 169 | bool hasW(SubRunType type) const; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 170 | |
| 171 | SubRun* makeSubRun(SubRunType type, |
| 172 | const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 173 | const SkStrikeSpec& strikeSpec, |
| 174 | GrMaskFormat format); |
| 175 | |
| 176 | void addSingleMaskFormat( |
| 177 | SubRunType type, |
| 178 | const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 179 | const SkStrikeSpec& strikeSpec, |
| 180 | GrMaskFormat format); |
| 181 | |
| 182 | void addMultiMaskFormat( |
| 183 | SubRunType type, |
| 184 | const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 185 | const SkStrikeSpec& strikeSpec); |
| 186 | |
| 187 | void addSDFT(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 188 | const SkStrikeSpec& strikeSpec, |
| 189 | const SkFont& runFont, |
| 190 | SkScalar minScale, |
| 191 | SkScalar maxScale); |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 192 | |
Herb Derby | 660c2ff | 2019-11-14 18:22:41 -0500 | [diff] [blame] | 193 | private: |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 194 | enum TextType { |
| 195 | kHasDistanceField_TextType = 0x1, |
| 196 | kHasBitmap_TextType = 0x2, |
| 197 | }; |
Herb Derby | 00ae959 | 2019-12-03 15:55:56 -0500 | [diff] [blame] | 198 | |
| 199 | struct StrokeInfo { |
| 200 | SkScalar fFrameWidth; |
| 201 | SkScalar fMiterLimit; |
| 202 | SkPaint::Join fJoin; |
| 203 | }; |
| 204 | |
Herb Derby | cb71889 | 2019-12-07 00:07:42 -0500 | [diff] [blame] | 205 | GrTextBlob(size_t allocSize, |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 206 | GrStrikeCache* strikeCache, |
Herb Derby | 1c5be7b | 2019-12-13 12:03:06 -0500 | [diff] [blame] | 207 | const SkMatrix& drawMatrix, |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 208 | SkPoint origin, |
| 209 | GrColor color, |
Herb Derby | aebc5f8 | 2019-12-10 14:07:10 -0500 | [diff] [blame] | 210 | SkColor initialLuminance, |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 211 | bool forceWForDistanceFields); |
Herb Derby | 00ae959 | 2019-12-03 15:55:56 -0500 | [diff] [blame] | 212 | |
Herb Derby | cb71889 | 2019-12-07 00:07:42 -0500 | [diff] [blame] | 213 | void insertSubRun(SubRun* subRun); |
| 214 | |
Robert Phillips | 841c9a5 | 2020-03-27 12:41:31 -0400 | [diff] [blame] | 215 | std::unique_ptr<GrAtlasTextOp> makeOp(SubRun& info, int glyphCount, const SkMatrix& drawMatrix, |
| 216 | SkPoint drawOrigin, const SkIRect& clipRect, |
| 217 | const SkPaint& paint, const SkPMColor4f& filteredColor, |
| 218 | const SkSurfaceProps&, GrTextTarget*); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 219 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 220 | // Methods to satisfy SkGlyphRunPainterInterface |
Herb Derby | 20eafff | 2019-10-16 16:21:13 -0400 | [diff] [blame] | 221 | void processDeviceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
Herb Derby | 36a54c1 | 2019-06-06 10:50:56 -0400 | [diff] [blame] | 222 | const SkStrikeSpec& strikeSpec) override; |
Herb Derby | 1213041 | 2019-10-21 18:02:24 -0400 | [diff] [blame] | 223 | void processSourcePaths(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 224 | const SkFont& runFont, |
Herb Derby | 36a54c1 | 2019-06-06 10:50:56 -0400 | [diff] [blame] | 225 | const SkStrikeSpec& strikeSpec) override; |
Herb Derby | 20eafff | 2019-10-16 16:21:13 -0400 | [diff] [blame] | 226 | void processSourceSDFT(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
Herb Derby | 36a54c1 | 2019-06-06 10:50:56 -0400 | [diff] [blame] | 227 | const SkStrikeSpec& strikeSpec, |
Herb Derby | c72594a | 2019-03-05 17:39:38 -0500 | [diff] [blame] | 228 | const SkFont& runFont, |
Herb Derby | c72594a | 2019-03-05 17:39:38 -0500 | [diff] [blame] | 229 | SkScalar minScale, |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 230 | SkScalar maxScale) override; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 231 | void processSourceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 232 | const SkStrikeSpec& strikeSpec) override; |
Herb Derby | c72594a | 2019-03-05 17:39:38 -0500 | [diff] [blame] | 233 | |
Herb Derby | 00ae959 | 2019-12-03 15:55:56 -0500 | [diff] [blame] | 234 | // Overall size of this struct plus vertices and glyphs at the end. |
| 235 | const size_t fSize; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 236 | |
Herb Derby | 00ae959 | 2019-12-03 15:55:56 -0500 | [diff] [blame] | 237 | // Lifetime: The GrStrikeCache is owned by and has the same lifetime as the GrRecordingContext. |
| 238 | // The GrRecordingContext also owns the GrTextBlob cache which owns this GrTextBlob. |
| 239 | GrStrikeCache* const fStrikeCache; |
| 240 | |
Herb Derby | e9f691d | 2019-12-04 12:11:13 -0500 | [diff] [blame] | 241 | // The initial view matrix and its inverse. This is used for moving additional draws of this |
| 242 | // same text blob. We record the initial view matrix and initial offsets(x,y), because we |
| 243 | // record vertex bounds relative to these numbers. When blobs are reused with new matrices, |
| 244 | // we need to return to source space so we can update the vertex bounds appropriately. |
Herb Derby | 1c5be7b | 2019-12-13 12:03:06 -0500 | [diff] [blame] | 245 | const SkMatrix fInitialMatrix; |
| 246 | const SkMatrix fInitialMatrixInverse; |
Herb Derby | e9f691d | 2019-12-04 12:11:13 -0500 | [diff] [blame] | 247 | |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 248 | // Initial position of this blob. Used for calculating position differences when reusing this |
| 249 | // blob. |
| 250 | const SkPoint fInitialOrigin; |
| 251 | |
Herb Derby | 00ae959 | 2019-12-03 15:55:56 -0500 | [diff] [blame] | 252 | // From the distance field options to force distance fields to have a W coordinate. |
| 253 | const bool fForceWForDistanceFields; |
| 254 | |
| 255 | // The color of the text to draw for solid colors. |
| 256 | const GrColor fColor; |
Herb Derby | aebc5f8 | 2019-12-10 14:07:10 -0500 | [diff] [blame] | 257 | const SkColor fInitialLuminance; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 258 | |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 259 | SkMaskFilterBase::BlurRec fBlurRec; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 260 | StrokeInfo fStrokeInfo; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 261 | Key fKey; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 262 | |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 263 | // We can reuse distance field text, but only if the new view matrix would not result in |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 264 | // a mip change. Because there can be multiple runs in a blob, we track the overall |
| 265 | // 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] | 266 | SkScalar fMaxMinScale{-SK_ScalarMax}; |
| 267 | SkScalar fMinMaxScale{SK_ScalarMax}; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 268 | |
Herb Derby | a00da61 | 2019-03-04 17:10:01 -0500 | [diff] [blame] | 269 | uint8_t fTextType{0}; |
Herb Derby | cb71889 | 2019-12-07 00:07:42 -0500 | [diff] [blame] | 270 | |
| 271 | SubRun* fFirstSubRun{nullptr}; |
| 272 | SubRun* fLastSubRun{nullptr}; |
| 273 | SkArenaAlloc fAlloc; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 274 | }; |
| 275 | |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 276 | /** |
| 277 | * Used to produce vertices for a subrun of a blob. The vertices are cached in the blob itself. |
| 278 | * This is invoked each time a sub run is drawn. It regenerates the vertex data as required either |
| 279 | * because of changes to the atlas or because of different draw parameters (e.g. color change). In |
| 280 | * rare cases the draw may have to interrupted and flushed in the middle of the sub run in order to |
| 281 | * free up atlas space. Thus, this generator is stateful and should be invoked in a loop until the |
| 282 | * entire sub run has been completed. |
| 283 | */ |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 284 | class GrTextBlob::VertexRegenerator { |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 285 | public: |
| 286 | /** |
| 287 | * Consecutive VertexRegenerators often use the same SkGlyphCache. If the same instance of |
| 288 | * SkAutoGlyphCache is reused then it can save the cost of multiple detach/attach operations of |
| 289 | * SkGlyphCache. |
| 290 | */ |
Herb Derby | c514e7d | 2019-12-11 17:00:31 -0500 | [diff] [blame] | 291 | VertexRegenerator(GrResourceProvider*, GrTextBlob::SubRun* subRun, |
Herb Derby | 5ddc34c | 2020-02-01 20:38:30 -0500 | [diff] [blame] | 292 | GrDeferredUploadTarget*, GrAtlasManager*); |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 293 | |
Herb Derby | 23f2976 | 2020-01-10 16:26:14 -0500 | [diff] [blame] | 294 | // Return {success, number of glyphs regenerated} |
| 295 | std::tuple<bool, int> regenerate(int begin, int end); |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 296 | |
| 297 | private: |
Herb Derby | 23f2976 | 2020-01-10 16:26:14 -0500 | [diff] [blame] | 298 | // Return {success, number of glyphs regenerated} |
Herb Derby | 3d05192 | 2020-01-31 16:59:29 -0500 | [diff] [blame] | 299 | std::tuple<bool, int> updateTextureCoordinates(int begin, int end); |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 300 | |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 301 | GrResourceProvider* fResourceProvider; |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 302 | GrDeferredUploadTarget* fUploadTarget; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 303 | GrAtlasManager* fFullAtlasManager; |
Herb Derby | cb443a5 | 2019-11-11 18:01:36 -0500 | [diff] [blame] | 304 | SkTLazy<SkBulkGlyphMetricsAndImages> fMetricsAndImages; |
Herb Derby | 69ff895 | 2018-11-12 11:39:12 -0500 | [diff] [blame] | 305 | SubRun* fSubRun; |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 306 | }; |
| 307 | |
Herb Derby | a6026a2 | 2020-01-09 14:04:25 -0500 | [diff] [blame] | 308 | // -- GrTextBlob::SubRun --------------------------------------------------------------------------- |
| 309 | // Hold data to draw the different types of sub run. SubRuns are produced knowing all the |
| 310 | // glyphs that are included in them. |
| 311 | class GrTextBlob::SubRun { |
| 312 | public: |
| 313 | // SubRun for masks |
| 314 | SubRun(SubRunType type, |
| 315 | GrTextBlob* textBlob, |
| 316 | const SkStrikeSpec& strikeSpec, |
| 317 | GrMaskFormat format, |
| 318 | const SkSpan<GrGlyph*>& glyphs, const SkSpan<char>& vertexData, |
| 319 | sk_sp<GrTextStrike>&& grStrike); |
| 320 | |
| 321 | // SubRun for paths |
| 322 | SubRun(GrTextBlob* textBlob, const SkStrikeSpec& strikeSpec); |
| 323 | |
| 324 | void appendGlyphs(const SkZip<SkGlyphVariant, SkPoint>& drawables); |
| 325 | |
| 326 | // TODO when this object is more internal, drop the privacy |
| 327 | void resetBulkUseToken(); |
| 328 | GrDrawOpAtlas::BulkUseTokenUpdater* bulkUseToken(); |
| 329 | void setStrike(sk_sp<GrTextStrike> strike); |
| 330 | GrTextStrike* strike() const; |
| 331 | |
| 332 | GrMaskFormat maskFormat() const; |
| 333 | |
| 334 | size_t vertexStride() const; |
| 335 | size_t colorOffset() const; |
| 336 | size_t texCoordOffset() const; |
| 337 | char* quadStart(size_t index) const; |
Herb Derby | 23f2976 | 2020-01-10 16:26:14 -0500 | [diff] [blame] | 338 | size_t quadOffset(size_t index) const; |
Herb Derby | a6026a2 | 2020-01-09 14:04:25 -0500 | [diff] [blame] | 339 | |
| 340 | const SkRect& vertexBounds() const; |
| 341 | void joinGlyphBounds(const SkRect& glyphBounds); |
| 342 | |
| 343 | bool drawAsDistanceFields() const; |
| 344 | bool drawAsPaths() const; |
| 345 | bool needsTransform() const; |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 346 | bool needsPadding() const; |
Herb Derby | a6026a2 | 2020-01-09 14:04:25 -0500 | [diff] [blame] | 347 | |
| 348 | void translateVerticesIfNeeded(const SkMatrix& drawMatrix, SkPoint drawOrigin); |
| 349 | void updateVerticesColorIfNeeded(GrColor newColor); |
| 350 | void updateTexCoords(int begin, int end); |
| 351 | |
| 352 | // df properties |
| 353 | void setUseLCDText(bool useLCDText); |
| 354 | bool hasUseLCDText() const; |
| 355 | void setAntiAliased(bool antiAliased); |
| 356 | bool isAntiAliased() const; |
| 357 | |
| 358 | const SkStrikeSpec& strikeSpec() const; |
| 359 | |
| 360 | SubRun* fNextSubRun{nullptr}; |
| 361 | const SubRunType fType; |
| 362 | GrTextBlob* const fBlob; |
| 363 | const GrMaskFormat fMaskFormat; |
| 364 | const SkSpan<GrGlyph*> fGlyphs; |
| 365 | const SkSpan<char> fVertexData; |
| 366 | const SkStrikeSpec fStrikeSpec; |
| 367 | sk_sp<GrTextStrike> fStrike; |
| 368 | struct { |
| 369 | bool useLCDText:1; |
| 370 | bool antiAliased:1; |
| 371 | } fFlags{false, false}; |
| 372 | GrDrawOpAtlas::BulkUseTokenUpdater fBulkUseToken; |
| 373 | SkRect fVertexBounds = SkRectPriv::MakeLargestInverted(); |
| 374 | uint64_t fAtlasGeneration{GrDrawOpAtlas::kInvalidAtlasGeneration}; |
| 375 | GrColor fCurrentColor; |
| 376 | SkPoint fCurrentOrigin; |
| 377 | SkMatrix fCurrentMatrix; |
| 378 | std::vector<PathGlyph> fPaths; |
| 379 | |
| 380 | private: |
| 381 | bool hasW() const; |
| 382 | |
| 383 | }; // SubRun |
| 384 | |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 385 | #endif // GrTextBlob_DEFINED |