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; |
Herb Derby | 660c2ff | 2019-11-14 18:22:41 -0500 | [diff] [blame] | 28 | class GrAtlasTextOp; |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 29 | struct GrDistanceFieldAdjustTable; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 30 | struct GrGlyph; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 31 | |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 32 | class SkTextBlob; |
| 33 | class SkTextBlobRunIterator; |
| 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 | * |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 45 | */ |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 46 | class GrTextBlob final : public SkNVRefCnt<GrTextBlob>, public SkGlyphRunPainterInterface { |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 47 | public: |
Herb Derby | 660c2ff | 2019-11-14 18:22:41 -0500 | [diff] [blame] | 48 | class SubRun; |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 49 | class VertexRegenerator; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 50 | using SubRunBufferSpec = std::tuple<uint32_t, uint32_t, size_t, size_t>; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 51 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 52 | enum SubRunType { |
| 53 | kDirectMask, |
| 54 | kTransformedMask, |
| 55 | kTransformedPath, |
| 56 | kTransformedSDFT |
| 57 | }; |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 58 | |
| 59 | struct Key { |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 60 | Key(); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 61 | uint32_t fUniqueID; |
| 62 | // Color may affect the gamma of the mask we generate, but in a fairly limited way. |
| 63 | // Each color is assigned to on of a fixed number of buckets based on its |
| 64 | // luminance. For each luminance bucket there is a "canonical color" that |
| 65 | // represents the bucket. This functionality is currently only supported for A8 |
| 66 | SkColor fCanonicalColor; |
| 67 | SkPaint::Style fStyle; |
| 68 | SkPixelGeometry fPixelGeometry; |
| 69 | bool fHasBlur; |
brianosman | 8d7ffce | 2016-04-21 08:29:06 -0700 | [diff] [blame] | 70 | uint32_t fScalerContextFlags; |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 71 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 72 | bool operator==(const Key& other) const; |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 75 | // Any glyphs that can't be rendered with the base or override descriptor |
| 76 | // are rendered as paths |
| 77 | struct PathGlyph { |
| 78 | PathGlyph(const SkPath& path, SkPoint origin); |
| 79 | SkPath fPath; |
| 80 | SkPoint fOrigin; |
| 81 | }; |
| 82 | |
| 83 | // Hold data to draw the different types of sub run. SubRuns are produced knowing all the |
| 84 | // glyphs that are included in them. |
| 85 | class SubRun { |
| 86 | public: |
| 87 | // SubRun for masks |
| 88 | SubRun(SubRunType type, |
| 89 | GrTextBlob* textBlob, |
| 90 | const SkStrikeSpec& strikeSpec, |
| 91 | GrMaskFormat format, |
| 92 | const SubRunBufferSpec& bufferSpec, |
| 93 | sk_sp<GrTextStrike>&& grStrike); |
| 94 | |
| 95 | // SubRun for paths |
| 96 | SubRun(GrTextBlob* textBlob, const SkStrikeSpec& strikeSpec); |
| 97 | |
| 98 | void appendGlyphs(const SkZip<SkGlyphVariant, SkPoint>& drawables); |
| 99 | |
| 100 | // TODO when this object is more internal, drop the privacy |
| 101 | void resetBulkUseToken(); |
| 102 | GrDrawOpAtlas::BulkUseTokenUpdater* bulkUseToken(); |
| 103 | void setStrike(sk_sp<GrTextStrike> strike); |
| 104 | GrTextStrike* strike() const; |
| 105 | sk_sp<GrTextStrike> refStrike() const; |
| 106 | |
| 107 | void setAtlasGeneration(uint64_t atlasGeneration); |
| 108 | uint64_t atlasGeneration() const; |
| 109 | |
| 110 | size_t vertexStartIndex() const; |
| 111 | uint32_t glyphCount() const; |
| 112 | uint32_t glyphStartIndex() const; |
| 113 | |
| 114 | void setColor(GrColor color); |
| 115 | GrColor color() const; |
| 116 | |
| 117 | GrMaskFormat maskFormat() const; |
| 118 | |
| 119 | const SkRect& vertexBounds() const; |
| 120 | void joinGlyphBounds(const SkRect& glyphBounds); |
| 121 | |
| 122 | void init(const SkMatrix& viewMatrix, SkScalar x, SkScalar y); |
| 123 | |
| 124 | // This function assumes the translation will be applied before it is called again |
| 125 | void computeTranslation(const SkMatrix& viewMatrix, SkScalar x, SkScalar y, |
| 126 | SkScalar* transX, SkScalar* transY); |
| 127 | |
| 128 | bool drawAsDistanceFields() const; |
| 129 | bool drawAsPaths() const; |
| 130 | bool needsTransform() const; |
| 131 | bool hasW() const; |
| 132 | |
| 133 | // df properties |
| 134 | void setUseLCDText(bool useLCDText); |
| 135 | bool hasUseLCDText() const; |
| 136 | void setAntiAliased(bool antiAliased); |
| 137 | bool isAntiAliased() const; |
| 138 | |
| 139 | const SkStrikeSpec& strikeSpec() const; |
| 140 | |
| 141 | const SubRunType fType; |
| 142 | GrTextBlob* const fBlob; |
| 143 | const GrMaskFormat fMaskFormat; |
| 144 | const uint32_t fGlyphStartIndex; |
| 145 | const uint32_t fGlyphEndIndex; |
| 146 | const size_t fVertexStartIndex; |
| 147 | const size_t fVertexEndIndex; |
| 148 | const SkStrikeSpec fStrikeSpec; |
| 149 | sk_sp<GrTextStrike> fStrike; |
| 150 | struct { |
| 151 | bool useLCDText:1; |
| 152 | bool antiAliased:1; |
| 153 | } fFlags{false, false}; |
| 154 | GrColor fColor; |
| 155 | GrDrawOpAtlas::BulkUseTokenUpdater fBulkUseToken; |
| 156 | SkRect fVertexBounds = SkRectPriv::MakeLargestInverted(); |
| 157 | uint64_t fAtlasGeneration{GrDrawOpAtlas::kInvalidAtlasGeneration}; |
| 158 | SkScalar fX; |
| 159 | SkScalar fY; |
| 160 | SkMatrix fCurrentViewMatrix; |
| 161 | std::vector<PathGlyph> fPaths; |
| 162 | }; // SubRun |
| 163 | |
| 164 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrTextBlob); |
| 165 | |
| 166 | // Change memory management to handle the data after GrTextBlob, but in the same allocation |
| 167 | // of memory. Only allow placement new. |
| 168 | void operator delete(void* p); |
| 169 | void* operator new(size_t); |
| 170 | void* operator new(size_t, void* p); |
| 171 | |
| 172 | ~GrTextBlob() override; |
| 173 | |
| 174 | // Make an empty GrTextBlob, with all the invariants set to make the right decisions when |
| 175 | // adding SubRuns. |
| 176 | static sk_sp<GrTextBlob> Make(int glyphCount, |
| 177 | GrStrikeCache* strikeCache, |
| 178 | const SkMatrix& viewMatrix, |
| 179 | SkPoint origin, |
| 180 | GrColor color, |
| 181 | bool forceWForDistanceFields); |
| 182 | |
| 183 | void generateFromGlyphRunList(const GrShaderCaps& shaderCaps, |
| 184 | const GrTextContext::Options& options, |
| 185 | const SkPaint& paint, |
| 186 | const SkMatrix& viewMatrix, |
| 187 | const SkSurfaceProps& props, |
| 188 | const SkGlyphRunList& glyphRunList, |
| 189 | SkGlyphRunListPainter* glyphPainter); |
| 190 | |
| 191 | // Key manipulation functions |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 192 | void setupKey(const GrTextBlob::Key& key, |
Mike Reed | 80747ef | 2018-01-23 15:29:32 -0500 | [diff] [blame] | 193 | const SkMaskFilterBase::BlurRec& blurRec, |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 194 | const SkPaint& paint); |
| 195 | static const Key& GetKey(const GrTextBlob& blob); |
| 196 | static uint32_t Hash(const Key& key); |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 197 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 198 | bool hasDistanceField() const; |
| 199 | bool hasBitmap() const; |
| 200 | bool hasPerspective() const; |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 201 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 202 | void setHasDistanceField(); |
| 203 | void setHasBitmap(); |
| 204 | void setMinAndMaxScale(SkScalar scaledMin, SkScalar scaledMax); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 205 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 206 | static size_t GetVertexStride(GrMaskFormat maskFormat, bool hasWCoord); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 207 | |
Herb Derby | 0edb214 | 2018-10-16 17:04:11 -0400 | [diff] [blame] | 208 | bool mustRegenerate(const SkPaint&, bool, const SkMaskFilterBase::BlurRec& blurRec, |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 209 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y); |
| 210 | |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 211 | void flush(GrTextTarget*, const SkSurfaceProps& props, |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 212 | const GrDistanceFieldAdjustTable* distanceAdjustTable, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 213 | const SkPaint& paint, const SkPMColor4f& filteredColor, const GrClip& clip, |
Robert Phillips | e4643cc | 2018-08-14 13:01:29 -0400 | [diff] [blame] | 214 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 215 | |
Herb Derby | 660c2ff | 2019-11-14 18:22:41 -0500 | [diff] [blame] | 216 | void computeSubRunBounds(SkRect* outBounds, const SubRun& subRun, |
Jim Van Verth | 7027691 | 2018-06-01 13:46:46 -0400 | [diff] [blame] | 217 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y, |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 218 | bool needsGlyphTransform); |
joshualitt | bc81111 | 2016-02-11 12:42:02 -0800 | [diff] [blame] | 219 | |
Herb Derby | cd498e1 | 2019-12-06 14:17:31 -0500 | [diff] [blame] | 220 | // Normal text mask, SDFT, or color. |
| 221 | struct Mask2DVertex { |
| 222 | SkPoint devicePos; |
| 223 | GrColor color; |
| 224 | SkIPoint16 atlasPos; |
| 225 | }; |
| 226 | struct ARGB2DVertex { |
| 227 | SkPoint devicePos; |
| 228 | SkIPoint16 atlasPos; |
| 229 | }; |
| 230 | |
| 231 | // Perspective SDFT or SDFT forced to 3D or perspective color. |
| 232 | struct SDFT3DVertex { |
| 233 | SkPoint3 devicePos; |
| 234 | GrColor color; |
| 235 | SkIPoint16 atlasPos; |
| 236 | }; |
| 237 | struct ARGB3DVertex { |
| 238 | SkPoint3 devicePos; |
| 239 | SkIPoint16 atlasPos; |
| 240 | }; |
| 241 | |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 242 | static const int kVerticesPerGlyph = 4; |
| 243 | |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 244 | // This function will only be called when we are generating a blob from scratch. |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 245 | // The color here is the GrPaint color, and it is used to determine whether we |
| 246 | // have to regenerate LCD text blobs. |
Herb Derby | e9f691d | 2019-12-04 12:11:13 -0500 | [diff] [blame] | 247 | // We use this color vs the SkPaint color because it has the color filter applied. |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 248 | void initReusableBlob(SkColor luminanceColor); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 249 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 250 | const Key& key() const; |
| 251 | size_t size() const; |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 252 | |
joshualitt | bc81111 | 2016-02-11 12:42:02 -0800 | [diff] [blame] | 253 | // Internal test methods |
Herb Derby | a6c4a30 | 2019-11-21 11:58:10 -0500 | [diff] [blame] | 254 | std::unique_ptr<GrDrawOp> test_makeOp(int glyphCount, |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 255 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 256 | const SkPaint& paint, const SkPMColor4f& filteredColor, |
Herb Derby | bc6f9c9 | 2018-08-08 13:58:45 -0400 | [diff] [blame] | 257 | const SkSurfaceProps&, const GrDistanceFieldAdjustTable*, |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 258 | GrTextTarget*); |
joshualitt | bc81111 | 2016-02-11 12:42:02 -0800 | [diff] [blame] | 259 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 260 | bool hasW(SubRunType type) const; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 261 | |
| 262 | SubRun* makeSubRun(SubRunType type, |
| 263 | const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 264 | const SkStrikeSpec& strikeSpec, |
| 265 | GrMaskFormat format); |
| 266 | |
| 267 | void addSingleMaskFormat( |
| 268 | SubRunType type, |
| 269 | const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 270 | const SkStrikeSpec& strikeSpec, |
| 271 | GrMaskFormat format); |
| 272 | |
| 273 | void addMultiMaskFormat( |
| 274 | SubRunType type, |
| 275 | const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 276 | const SkStrikeSpec& strikeSpec); |
| 277 | |
| 278 | void addSDFT(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 279 | const SkStrikeSpec& strikeSpec, |
| 280 | const SkFont& runFont, |
| 281 | SkScalar minScale, |
| 282 | SkScalar maxScale); |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 283 | |
Herb Derby | 660c2ff | 2019-11-14 18:22:41 -0500 | [diff] [blame] | 284 | private: |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 285 | enum TextType { |
| 286 | kHasDistanceField_TextType = 0x1, |
| 287 | kHasBitmap_TextType = 0x2, |
| 288 | }; |
Herb Derby | 00ae959 | 2019-12-03 15:55:56 -0500 | [diff] [blame] | 289 | |
| 290 | struct StrokeInfo { |
| 291 | SkScalar fFrameWidth; |
| 292 | SkScalar fMiterLimit; |
| 293 | SkPaint::Join fJoin; |
| 294 | }; |
| 295 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 296 | GrTextBlob(size_t size, |
| 297 | GrStrikeCache* strikeCache, |
| 298 | const SkMatrix& viewMatrix, |
| 299 | SkPoint origin, |
| 300 | GrColor color, |
| 301 | bool forceWForDistanceFields); |
Herb Derby | 00ae959 | 2019-12-03 15:55:56 -0500 | [diff] [blame] | 302 | |
Herb Derby | c72594a | 2019-03-05 17:39:38 -0500 | [diff] [blame] | 303 | std::unique_ptr<GrAtlasTextOp> makeOp( |
Herb Derby | a6c4a30 | 2019-11-21 11:58:10 -0500 | [diff] [blame] | 304 | SubRun& info, int glyphCount, |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 305 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipRect, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 306 | const SkPaint& paint, const SkPMColor4f& filteredColor, const SkSurfaceProps&, |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 307 | const GrDistanceFieldAdjustTable*, GrTextTarget*); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 308 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 309 | // Methods to satisfy SkGlyphRunPainterInterface |
Herb Derby | 20eafff | 2019-10-16 16:21:13 -0400 | [diff] [blame] | 310 | void processDeviceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
Herb Derby | 36a54c1 | 2019-06-06 10:50:56 -0400 | [diff] [blame] | 311 | const SkStrikeSpec& strikeSpec) override; |
Herb Derby | 1213041 | 2019-10-21 18:02:24 -0400 | [diff] [blame] | 312 | void processSourcePaths(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 313 | const SkFont& runFont, |
Herb Derby | 36a54c1 | 2019-06-06 10:50:56 -0400 | [diff] [blame] | 314 | const SkStrikeSpec& strikeSpec) override; |
Herb Derby | 20eafff | 2019-10-16 16:21:13 -0400 | [diff] [blame] | 315 | void processSourceSDFT(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
Herb Derby | 36a54c1 | 2019-06-06 10:50:56 -0400 | [diff] [blame] | 316 | const SkStrikeSpec& strikeSpec, |
Herb Derby | c72594a | 2019-03-05 17:39:38 -0500 | [diff] [blame] | 317 | const SkFont& runFont, |
Herb Derby | c72594a | 2019-03-05 17:39:38 -0500 | [diff] [blame] | 318 | SkScalar minScale, |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 319 | SkScalar maxScale) override; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 320 | void processSourceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 321 | const SkStrikeSpec& strikeSpec) override; |
Herb Derby | c72594a | 2019-03-05 17:39:38 -0500 | [diff] [blame] | 322 | |
Herb Derby | 00ae959 | 2019-12-03 15:55:56 -0500 | [diff] [blame] | 323 | // Overall size of this struct plus vertices and glyphs at the end. |
| 324 | const size_t fSize; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 325 | |
Herb Derby | 00ae959 | 2019-12-03 15:55:56 -0500 | [diff] [blame] | 326 | // Lifetime: The GrStrikeCache is owned by and has the same lifetime as the GrRecordingContext. |
| 327 | // The GrRecordingContext also owns the GrTextBlob cache which owns this GrTextBlob. |
| 328 | GrStrikeCache* const fStrikeCache; |
| 329 | |
Herb Derby | e9f691d | 2019-12-04 12:11:13 -0500 | [diff] [blame] | 330 | // The initial view matrix and its inverse. This is used for moving additional draws of this |
| 331 | // same text blob. We record the initial view matrix and initial offsets(x,y), because we |
| 332 | // record vertex bounds relative to these numbers. When blobs are reused with new matrices, |
| 333 | // we need to return to source space so we can update the vertex bounds appropriately. |
| 334 | const SkMatrix fInitialViewMatrix; |
| 335 | const SkMatrix fInitialViewMatrixInverse; |
| 336 | |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 337 | // Initial position of this blob. Used for calculating position differences when reusing this |
| 338 | // blob. |
| 339 | const SkPoint fInitialOrigin; |
| 340 | |
Herb Derby | 00ae959 | 2019-12-03 15:55:56 -0500 | [diff] [blame] | 341 | // From the distance field options to force distance fields to have a W coordinate. |
| 342 | const bool fForceWForDistanceFields; |
| 343 | |
| 344 | // The color of the text to draw for solid colors. |
| 345 | const GrColor fColor; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 346 | |
| 347 | // Pool of bytes for vertex data. |
| 348 | char* fVertices; |
| 349 | // How much (in bytes) of the vertex data is used while accumulating SubRuns. |
| 350 | size_t fVerticesCursor{0}; |
| 351 | // Pointers to every glyph that will be drawn. |
| 352 | GrGlyph** fGlyphs; |
| 353 | // Number of glyphs stored in fGlyphs while accumulating SubRuns. |
| 354 | uint32_t fGlyphsCursor{0}; |
| 355 | |
| 356 | // Assume one run per text blob. |
| 357 | SkSTArray<1, SubRun> fSubRuns; |
| 358 | |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 359 | SkMaskFilterBase::BlurRec fBlurRec; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 360 | StrokeInfo fStrokeInfo; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 361 | Key fKey; |
Jim Van Verth | bc2cdd1 | 2017-06-08 11:14:35 -0400 | [diff] [blame] | 362 | SkColor fLuminanceColor; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 363 | |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 364 | // 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] | 365 | // a mip change. Because there can be multiple runs in a blob, we track the overall |
| 366 | // 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] | 367 | SkScalar fMaxMinScale{-SK_ScalarMax}; |
| 368 | SkScalar fMinMaxScale{SK_ScalarMax}; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 369 | |
Herb Derby | a00da61 | 2019-03-04 17:10:01 -0500 | [diff] [blame] | 370 | uint8_t fTextType{0}; |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 371 | }; |
| 372 | |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 373 | /** |
| 374 | * Used to produce vertices for a subrun of a blob. The vertices are cached in the blob itself. |
| 375 | * This is invoked each time a sub run is drawn. It regenerates the vertex data as required either |
| 376 | * because of changes to the atlas or because of different draw parameters (e.g. color change). In |
| 377 | * rare cases the draw may have to interrupted and flushed in the middle of the sub run in order to |
| 378 | * free up atlas space. Thus, this generator is stateful and should be invoked in a loop until the |
| 379 | * entire sub run has been completed. |
| 380 | */ |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 381 | class GrTextBlob::VertexRegenerator { |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 382 | public: |
| 383 | /** |
| 384 | * Consecutive VertexRegenerators often use the same SkGlyphCache. If the same instance of |
| 385 | * SkAutoGlyphCache is reused then it can save the cost of multiple detach/attach operations of |
| 386 | * SkGlyphCache. |
| 387 | */ |
Herb Derby | 660c2ff | 2019-11-14 18:22:41 -0500 | [diff] [blame] | 388 | VertexRegenerator(GrResourceProvider*, GrTextBlob*, |
| 389 | GrTextBlob::SubRun* subRun, |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 390 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y, GrColor color, |
Herb Derby | cb443a5 | 2019-11-11 18:01:36 -0500 | [diff] [blame] | 391 | GrDeferredUploadTarget*, GrStrikeCache*, GrAtlasManager*); |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 392 | |
| 393 | struct Result { |
| 394 | /** |
| 395 | * Was regenerate() able to draw all the glyphs from the sub run? If not flush all glyph |
| 396 | * draws and call regenerate() again. |
| 397 | */ |
| 398 | bool fFinished = true; |
| 399 | |
| 400 | /** |
| 401 | * How many glyphs were regenerated. Will be equal to the sub run's glyph count if |
| 402 | * fType is kFinished. |
| 403 | */ |
| 404 | int fGlyphsRegenerated = 0; |
| 405 | |
| 406 | /** |
| 407 | * Pointer where the caller finds the first regenerated vertex. |
| 408 | */ |
| 409 | const char* fFirstVertex; |
| 410 | }; |
| 411 | |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 412 | bool regenerate(Result*); |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 413 | |
| 414 | private: |
Brian Osman | 5d6be8f | 2019-01-08 12:02:51 -0500 | [diff] [blame] | 415 | bool doRegen(Result*, bool regenPos, bool regenCol, bool regenTexCoords, bool regenGlyphs); |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 416 | |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 417 | GrResourceProvider* fResourceProvider; |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 418 | const SkMatrix& fViewMatrix; |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 419 | GrTextBlob* fBlob; |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 420 | GrDeferredUploadTarget* fUploadTarget; |
Herb Derby | 3a4f227 | 2019-11-13 15:09:32 -0500 | [diff] [blame] | 421 | GrStrikeCache* fGrStrikeCache; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 422 | GrAtlasManager* fFullAtlasManager; |
Herb Derby | cb443a5 | 2019-11-11 18:01:36 -0500 | [diff] [blame] | 423 | SkTLazy<SkBulkGlyphMetricsAndImages> fMetricsAndImages; |
Herb Derby | 69ff895 | 2018-11-12 11:39:12 -0500 | [diff] [blame] | 424 | SubRun* fSubRun; |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 425 | GrColor fColor; |
| 426 | SkScalar fTransX; |
| 427 | SkScalar fTransY; |
| 428 | |
| 429 | uint32_t fRegenFlags = 0; |
| 430 | int fCurrGlyph = 0; |
| 431 | bool fBrokenRun = false; |
| 432 | }; |
| 433 | |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 434 | #endif // GrTextBlob_DEFINED |