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 | |
Herb Derby | b33140a | 2021-02-08 17:57:03 -0500 | [diff] [blame] | 11 | #include <algorithm> |
Robert Phillips | 51b3e60 | 2020-04-09 12:48:50 -0400 | [diff] [blame] | 12 | #include <limits> |
| 13 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/core/SkPoint3.h" |
Robert Phillips | 51b3e60 | 2020-04-09 12:48:50 -0400 | [diff] [blame] | 15 | #include "include/core/SkRefCnt.h" |
| 16 | #include "src/core/SkGlyphRunPainter.h" |
| 17 | #include "src/core/SkIPoint16.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/core/SkMaskFilterBase.h" |
| 19 | #include "src/core/SkOpts.h" |
| 20 | #include "src/core/SkRectPriv.h" |
Herb Derby | e7efd08 | 2019-05-28 11:30:33 -0400 | [diff] [blame] | 21 | #include "src/core/SkStrikeSpec.h" |
Michael Ludwig | b23630c | 2021-08-10 12:27:25 -0400 | [diff] [blame] | 22 | #include "src/core/SkTInternalLList.h" |
Robert Phillips | 51b3e60 | 2020-04-09 12:48:50 -0400 | [diff] [blame] | 23 | #include "src/core/SkTLazy.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 24 | #include "src/gpu/GrColor.h" |
Herb Derby | d5a6764 | 2021-04-16 09:07:24 -0400 | [diff] [blame] | 25 | #include "src/gpu/GrSubRunAllocator.h" |
Herb Derby | d5a6764 | 2021-04-16 09:07:24 -0400 | [diff] [blame] | 26 | #include "src/gpu/ops/GrOp.h" |
joshualitt | 374b2f7 | 2015-07-21 08:05:03 -0700 | [diff] [blame] | 27 | |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 28 | class GrAtlasManager; |
Herb Derby | 660c2ff | 2019-11-14 18:22:41 -0500 | [diff] [blame] | 29 | class GrAtlasTextOp; |
Robert Phillips | 51b3e60 | 2020-04-09 12:48:50 -0400 | [diff] [blame] | 30 | class GrDeferredUploadTarget; |
Robert Phillips | 5fa68b4 | 2020-03-31 08:34:22 -0400 | [diff] [blame] | 31 | class GrGlyph; |
Robert Phillips | 7114395 | 2021-06-17 14:55:07 -0400 | [diff] [blame] | 32 | class GrMeshDrawTarget; |
Robert Phillips | 41bd97d | 2020-04-07 14:19:37 -0400 | [diff] [blame] | 33 | class GrStrikeCache; |
Herb Derby | 3d00a97 | 2020-07-14 11:43:14 -0400 | [diff] [blame] | 34 | class GrSubRun; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 35 | |
Brian Osman | 449b115 | 2020-04-15 16:43:00 -0400 | [diff] [blame] | 36 | class SkMatrixProvider; |
Robert Phillips | 41bd97d | 2020-04-07 14:19:37 -0400 | [diff] [blame] | 37 | class SkSurfaceProps; |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 38 | class SkTextBlob; |
| 39 | class SkTextBlobRunIterator; |
| 40 | |
Robert Phillips | 643f481 | 2021-08-11 09:31:00 -0400 | [diff] [blame^] | 41 | namespace skgpu { namespace v1 { class SurfaceDrawContext; }} |
Herb Derby | 1526444 | 2020-12-16 10:45:50 -0500 | [diff] [blame] | 42 | |
Herb Derby | d90024d | 2020-11-20 10:21:32 -0500 | [diff] [blame] | 43 | // -- GrAtlasSubRun -------------------------------------------------------------------------------- |
| 44 | // GrAtlasSubRun is the API that GrAtlasTextOp uses to generate vertex data for drawing. |
Herb Derby | 018f5f6 | 2020-10-28 15:55:32 -0400 | [diff] [blame] | 45 | // There are three different ways GrAtlasSubRun is specialized. |
Herb Derby | 1526444 | 2020-12-16 10:45:50 -0500 | [diff] [blame] | 46 | // * DirectMaskSubRun - this is by far the most common type of SubRun. The mask pixels are |
Herb Derby | 018f5f6 | 2020-10-28 15:55:32 -0400 | [diff] [blame] | 47 | // in 1:1 correspondence with the pixels on the device. The destination rectangles in this |
Herb Derby | 1526444 | 2020-12-16 10:45:50 -0500 | [diff] [blame] | 48 | // SubRun are in device space. This SubRun handles color glyphs. |
Herb Derby | 7d3886d | 2020-11-09 09:08:42 -0500 | [diff] [blame] | 49 | // * TransformedMaskSubRun - handles glyph where the image in the atlas needs to be |
Herb Derby | 018f5f6 | 2020-10-28 15:55:32 -0400 | [diff] [blame] | 50 | // transformed to the screen. It is usually used for large color glyph which can't be |
| 51 | // drawn with paths or scaled distance fields. The destination rectangles are in source |
| 52 | // space. |
Herb Derby | 7d3886d | 2020-11-09 09:08:42 -0500 | [diff] [blame] | 53 | // * SDFTSubRun - scaled distance field text handles largish single color glyphs that still |
Herb Derby | 1526444 | 2020-12-16 10:45:50 -0500 | [diff] [blame] | 54 | // can fit in the atlas; the sizes between direct SubRun, and path SubRun. The destination |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 55 | |
| 56 | class GrAtlasSubRun; |
| 57 | using GrAtlasSubRunOwner = std::unique_ptr<GrAtlasSubRun, GrSubRunAllocator::Destroyer>; |
Herb Derby | d90024d | 2020-11-20 10:21:32 -0500 | [diff] [blame] | 58 | class GrAtlasSubRun { |
Herb Derby | c24a6af | 2020-07-16 12:10:52 -0400 | [diff] [blame] | 59 | public: |
| 60 | static constexpr int kVerticesPerGlyph = 4; |
Herb Derby | d90024d | 2020-11-20 10:21:32 -0500 | [diff] [blame] | 61 | |
| 62 | virtual ~GrAtlasSubRun() = default; |
| 63 | |
Herb Derby | 46d1e9f | 2020-12-01 14:12:04 -0500 | [diff] [blame] | 64 | virtual size_t vertexStride(const SkMatrix& drawMatrix) const = 0; |
Herb Derby | c24a6af | 2020-07-16 12:10:52 -0400 | [diff] [blame] | 65 | virtual int glyphCount() const = 0; |
| 66 | |
Robert Phillips | 46eb3ab | 2021-08-02 17:09:01 -0400 | [diff] [blame] | 67 | #if SK_GPU_V1 |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 68 | virtual std::tuple<const GrClip*, GrOp::Owner> |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 69 | makeAtlasTextOp( |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 70 | const GrClip*, |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 71 | const SkMatrixProvider& viewMatrix, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 72 | const SkGlyphRunList&, |
| 73 | const SkPaint&, |
| 74 | skgpu::v1::SurfaceDrawContext*, |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 75 | GrAtlasSubRunOwner subRun) const = 0; |
Robert Phillips | 46eb3ab | 2021-08-02 17:09:01 -0400 | [diff] [blame] | 76 | #endif |
| 77 | |
Herb Derby | c24a6af | 2020-07-16 12:10:52 -0400 | [diff] [blame] | 78 | virtual void fillVertexData( |
| 79 | void* vertexDst, int offset, int count, |
Herb Derby | 4089418 | 2020-12-02 11:39:48 -0500 | [diff] [blame] | 80 | GrColor color, const SkMatrix& positionMatrix, |
Herb Derby | c24a6af | 2020-07-16 12:10:52 -0400 | [diff] [blame] | 81 | SkIRect clip) const = 0; |
Herb Derby | 43ad791 | 2020-07-20 16:14:19 -0400 | [diff] [blame] | 82 | |
Herb Derby | c27d535 | 2020-08-12 13:58:34 -0400 | [diff] [blame] | 83 | virtual void testingOnly_packedGlyphIDToGrGlyph(GrStrikeCache* cache) = 0; |
| 84 | |
Herb Derby | 43ad791 | 2020-07-20 16:14:19 -0400 | [diff] [blame] | 85 | // This call is not thread safe. It should only be called from GrDrawOp::onPrepare which |
| 86 | // is single threaded. |
| 87 | virtual std::tuple<bool, int> regenerateAtlas( |
Robert Phillips | 7114395 | 2021-06-17 14:55:07 -0400 | [diff] [blame] | 88 | int begin, int end, GrMeshDrawTarget* target) const = 0; |
Herb Derby | c24a6af | 2020-07-16 12:10:52 -0400 | [diff] [blame] | 89 | }; |
Herb Derby | d90024d | 2020-11-20 10:21:32 -0500 | [diff] [blame] | 90 | |
| 91 | // -- GrSubRun ------------------------------------------------------------------------------------- |
Herb Derby | 1526444 | 2020-12-16 10:45:50 -0500 | [diff] [blame] | 92 | // GrSubRun is the API the GrTextBlob uses for the SubRun. |
| 93 | // There are several types of SubRun, which can be broken into five classes: |
Herb Derby | d90024d | 2020-11-20 10:21:32 -0500 | [diff] [blame] | 94 | // * PathSubRun - handle very large single color glyphs using paths to render the glyph. |
| 95 | // * DirectMaskSubRun - handle the majority of the glyphs where the cache entry's pixels are in |
| 96 | // 1:1 correspondence to the device pixels. |
| 97 | // * TransformedMaskSubRun - handle large bitmap/argb glyphs that need to be scaled to the screen. |
| 98 | // * SDFTSubRun - use signed distance fields to draw largish glyphs to the screen. |
| 99 | // * GrAtlasSubRun - this is an abstract class used for atlas drawing. |
Herb Derby | c1a0600 | 2021-03-11 10:57:16 -0500 | [diff] [blame] | 100 | class GrSubRun; |
| 101 | using GrSubRunOwner = std::unique_ptr<GrSubRun, GrSubRunAllocator::Destroyer>; |
Herb Derby | d90024d | 2020-11-20 10:21:32 -0500 | [diff] [blame] | 102 | class GrSubRun { |
| 103 | public: |
| 104 | virtual ~GrSubRun() = default; |
| 105 | |
Robert Phillips | 46eb3ab | 2021-08-02 17:09:01 -0400 | [diff] [blame] | 106 | #if SK_GPU_V1 |
Herb Derby | d90024d | 2020-11-20 10:21:32 -0500 | [diff] [blame] | 107 | // Produce GPU ops for this subRun. |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 108 | virtual void draw(const GrClip*, |
Herb Derby | d90024d | 2020-11-20 10:21:32 -0500 | [diff] [blame] | 109 | const SkMatrixProvider& viewMatrix, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 110 | const SkGlyphRunList&, |
| 111 | const SkPaint&, |
| 112 | skgpu::v1::SurfaceDrawContext*) const = 0; |
Robert Phillips | 46eb3ab | 2021-08-02 17:09:01 -0400 | [diff] [blame] | 113 | #endif |
Herb Derby | d90024d | 2020-11-20 10:21:32 -0500 | [diff] [blame] | 114 | |
| 115 | // Given an already cached subRun, can this subRun handle this combination paint, matrix, and |
| 116 | // position. |
Herb Derby | 743c697 | 2021-02-23 12:57:56 -0500 | [diff] [blame] | 117 | virtual bool canReuse(const SkPaint& paint, const SkMatrix& drawMatrix) const = 0; |
Herb Derby | d90024d | 2020-11-20 10:21:32 -0500 | [diff] [blame] | 118 | |
Herb Derby | 1526444 | 2020-12-16 10:45:50 -0500 | [diff] [blame] | 119 | // Return the underlying atlas SubRun if it exists. Otherwise, return nullptr. |
Herb Derby | d90024d | 2020-11-20 10:21:32 -0500 | [diff] [blame] | 120 | // * Don't use this API. It is only to support testing. |
| 121 | virtual GrAtlasSubRun* testingOnly_atlasSubRun() = 0; |
| 122 | |
Herb Derby | c1a0600 | 2021-03-11 10:57:16 -0500 | [diff] [blame] | 123 | GrSubRunOwner fNext; |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | struct GrSubRunList { |
| 127 | class Iterator { |
| 128 | public: |
| 129 | using value_type = GrSubRun; |
| 130 | using difference_type = ptrdiff_t; |
| 131 | using pointer = value_type*; |
| 132 | using reference = value_type&; |
| 133 | using iterator_category = std::input_iterator_tag; |
Herb Derby | 1526444 | 2020-12-16 10:45:50 -0500 | [diff] [blame] | 134 | Iterator(GrSubRun* subRun) : fPtr{subRun} { } |
| 135 | Iterator& operator++() { fPtr = fPtr->fNext.get(); return *this; } |
| 136 | Iterator operator++(int) { Iterator tmp(*this); operator++(); return tmp; } |
| 137 | bool operator==(const Iterator& rhs) const { return fPtr == rhs.fPtr; } |
| 138 | bool operator!=(const Iterator& rhs) const { return fPtr != rhs.fPtr; } |
| 139 | reference operator*() { return *fPtr; } |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 140 | |
| 141 | private: |
| 142 | GrSubRun* fPtr; |
| 143 | }; |
| 144 | |
Herb Derby | c1a0600 | 2021-03-11 10:57:16 -0500 | [diff] [blame] | 145 | void append(GrSubRunOwner subRun) { |
| 146 | GrSubRunOwner* newTail = &subRun->fNext; |
Herb Derby | 1526444 | 2020-12-16 10:45:50 -0500 | [diff] [blame] | 147 | *fTail = std::move(subRun); |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 148 | fTail = newTail; |
| 149 | } |
| 150 | bool isEmpty() const { return fHead == nullptr; } |
Herb Derby | 1526444 | 2020-12-16 10:45:50 -0500 | [diff] [blame] | 151 | Iterator begin() { return Iterator{ fHead.get()}; } |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 152 | Iterator end() { return Iterator{nullptr}; } |
Herb Derby | 6b27ae8 | 2021-02-23 13:03:59 -0500 | [diff] [blame] | 153 | Iterator begin() const { return Iterator{ fHead.get()}; } |
| 154 | Iterator end() const { return Iterator{nullptr}; } |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 155 | GrSubRun& front() const {return *fHead; } |
| 156 | |
Herb Derby | c1a0600 | 2021-03-11 10:57:16 -0500 | [diff] [blame] | 157 | GrSubRunOwner fHead{nullptr}; |
| 158 | GrSubRunOwner* fTail{&fHead}; |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | // A GrTextBlob contains a fully processed SkTextBlob, suitable for nearly immediate drawing |
| 162 | // on the GPU. These are initially created with valid positions and colors, but invalid |
| 163 | // texture coordinates. |
| 164 | // |
| 165 | // A GrTextBlob contains a number of SubRuns that are created in the blob's arena. Each SubRun |
| 166 | // tracks its own GrGlyph* and vertex data. The memory is organized in the arena in the following |
| 167 | // way so that the pointers for the GrGlyph* and vertex data are known before creating the SubRun. |
| 168 | // |
| 169 | // GrGlyph*... | vertexData... | SubRun | GrGlyph*... | vertexData... | SubRun etc. |
| 170 | // |
| 171 | // In these classes, I'm trying to follow the convention about matrices and origins. |
| 172 | // * draw Matrix|Origin - describes the current draw command. |
| 173 | // * initial Matrix - describes the combined initial matrix and origin the GrTextBlob was created |
| 174 | // with. |
| 175 | // |
| 176 | // |
| 177 | class GrTextBlob final : public SkNVRefCnt<GrTextBlob>, public SkGlyphRunPainterInterface { |
| 178 | public: |
Herb Derby | 6447784 | 2021-03-08 13:47:06 -0500 | [diff] [blame] | 179 | |
| 180 | // Key is not used as part of a hash map, so the hash is never taken. It's only used in a |
| 181 | // list search using operator =(). |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 182 | struct Key { |
Herb Derby | 6447784 | 2021-03-08 13:47:06 -0500 | [diff] [blame] | 183 | static std::tuple<bool, Key> Make(const SkGlyphRunList& glyphRunList, |
Herb Derby | 0da2c14 | 2021-03-22 15:28:23 -0400 | [diff] [blame] | 184 | const SkPaint& paint, |
Herb Derby | 6447784 | 2021-03-08 13:47:06 -0500 | [diff] [blame] | 185 | const SkSurfaceProps& surfaceProps, |
| 186 | const GrColorInfo& colorInfo, |
| 187 | const SkMatrix& drawMatrix, |
| 188 | const GrSDFTControl& control); |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 189 | uint32_t fUniqueID; |
| 190 | // Color may affect the gamma of the mask we generate, but in a fairly limited way. |
| 191 | // Each color is assigned to on of a fixed number of buckets based on its |
| 192 | // luminance. For each luminance bucket there is a "canonical color" that |
| 193 | // represents the bucket. This functionality is currently only supported for A8 |
| 194 | SkColor fCanonicalColor; |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 195 | SkScalar fFrameWidth; |
| 196 | SkScalar fMiterLimit; |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 197 | SkPixelGeometry fPixelGeometry; |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 198 | SkMaskFilterBase::BlurRec fBlurRec; |
| 199 | uint32_t fScalerContextFlags; |
Herb Derby | e4ef35c | 2021-03-01 11:49:32 -0500 | [diff] [blame] | 200 | SkMatrix fDrawMatrix; |
| 201 | // Below here fields are of size 1 byte. |
| 202 | uint8_t fSetOfDrawingTypes; |
| 203 | bool fHasBlur; |
| 204 | SkPaint::Style fStyle; |
| 205 | SkPaint::Join fJoin; |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 206 | |
| 207 | bool operator==(const Key& other) const; |
| 208 | }; |
| 209 | |
| 210 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrTextBlob); |
| 211 | |
Herb Derby | 63fe8e5 | 2021-03-08 13:22:56 -0500 | [diff] [blame] | 212 | // Make a GrTextBlob and its sub runs. |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 213 | static sk_sp<GrTextBlob> Make(const SkGlyphRunList& glyphRunList, |
Herb Derby | 0da2c14 | 2021-03-22 15:28:23 -0400 | [diff] [blame] | 214 | const SkPaint& paint, |
Herb Derby | 63fe8e5 | 2021-03-08 13:22:56 -0500 | [diff] [blame] | 215 | const SkMatrix& drawMatrix, |
| 216 | const GrSDFTControl& control, |
| 217 | SkGlyphRunListPainter* painter); |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 218 | |
| 219 | ~GrTextBlob() override; |
| 220 | |
| 221 | // Change memory management to handle the data after GrTextBlob, but in the same allocation |
| 222 | // of memory. Only allow placement new. |
| 223 | void operator delete(void* p); |
| 224 | void* operator new(size_t); |
| 225 | void* operator new(size_t, void* p); |
| 226 | |
Herb Derby | c8e31ea | 2021-03-08 12:42:17 -0500 | [diff] [blame] | 227 | const Key& key() { return fKey; } |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 228 | |
| 229 | void addKey(const Key& key); |
| 230 | bool hasPerspective() const; |
| 231 | const SkMatrix& initialMatrix() const { return fInitialMatrix; } |
| 232 | |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 233 | std::tuple<SkScalar, SkScalar> scaleBounds() const { |
| 234 | return {fMaxMinScale, fMinMaxScale}; |
| 235 | } |
| 236 | |
Herb Derby | 743c697 | 2021-02-23 12:57:56 -0500 | [diff] [blame] | 237 | bool canReuse(const SkPaint& paint, const SkMatrix& drawMatrix) const; |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 238 | |
| 239 | const Key& key() const; |
| 240 | size_t size() const; |
| 241 | |
Herb Derby | 6b27ae8 | 2021-02-23 13:03:59 -0500 | [diff] [blame] | 242 | const GrSubRunList& subRunList() const { |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 243 | return fSubRunList; |
| 244 | } |
| 245 | |
Herb Derby | d90024d | 2020-11-20 10:21:32 -0500 | [diff] [blame] | 246 | private: |
Herb Derby | 1526444 | 2020-12-16 10:45:50 -0500 | [diff] [blame] | 247 | GrTextBlob(int allocSize, const SkMatrix& drawMatrix, SkColor initialLuminance); |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 248 | |
Herb Derby | d15c52d | 2021-02-23 13:33:12 -0500 | [diff] [blame] | 249 | template<typename AddSingleMaskFormat> |
| 250 | void addMultiMaskFormat( |
| 251 | AddSingleMaskFormat addSingle, |
| 252 | const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 253 | const SkStrikeSpec& strikeSpec); |
| 254 | |
Robert Phillips | 46eb3ab | 2021-08-02 17:09:01 -0400 | [diff] [blame] | 255 | #if SK_GPU_V1 |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 256 | // Methods to satisfy SkGlyphRunPainterInterface |
| 257 | void processDeviceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 258 | const SkStrikeSpec& strikeSpec) override; |
| 259 | void processSourcePaths(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 260 | const SkFont& runFont, |
| 261 | const SkStrikeSpec& strikeSpec) override; |
| 262 | void processSourceSDFT(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 263 | const SkStrikeSpec& strikeSpec, |
| 264 | const SkFont& runFont, |
| 265 | SkScalar minScale, |
| 266 | SkScalar maxScale) override; |
| 267 | void processSourceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 268 | const SkStrikeSpec& strikeSpec) override; |
Robert Phillips | 46eb3ab | 2021-08-02 17:09:01 -0400 | [diff] [blame] | 269 | #endif // SK_GPU_V1 |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 270 | |
Herb Derby | 1526444 | 2020-12-16 10:45:50 -0500 | [diff] [blame] | 271 | // The allocator must come first because it needs to be destroyed last. Other fields of this |
| 272 | // structure may have pointers into it. |
| 273 | GrSubRunAllocator fAlloc; |
| 274 | |
| 275 | // Owner and list of the SubRun. |
| 276 | GrSubRunList fSubRunList; |
| 277 | |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 278 | // Overall size of this struct plus vertices and glyphs at the end. |
Herb Derby | 1526444 | 2020-12-16 10:45:50 -0500 | [diff] [blame] | 279 | const int fSize; |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 280 | |
| 281 | // The initial view matrix combined with the initial origin. Used to determine if a cached |
| 282 | // subRun can be used in this draw situation. |
| 283 | const SkMatrix fInitialMatrix; |
| 284 | |
| 285 | const SkColor fInitialLuminance; |
| 286 | |
| 287 | Key fKey; |
| 288 | |
| 289 | // We can reuse distance field text, but only if the new view matrix would not result in |
| 290 | // a mip change. Because there can be multiple runs in a blob, we track the overall |
| 291 | // maximum minimum scale, and minimum maximum scale, we can support before we need to regen |
| 292 | SkScalar fMaxMinScale{-SK_ScalarMax}; |
| 293 | SkScalar fMinMaxScale{SK_ScalarMax}; |
| 294 | |
| 295 | bool fSomeGlyphsExcluded{false}; |
Herb Derby | d90024d | 2020-11-20 10:21:32 -0500 | [diff] [blame] | 296 | }; |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 297 | |
Robert Phillips | 46eb3ab | 2021-08-02 17:09:01 -0400 | [diff] [blame] | 298 | #if SK_GPU_V1 |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 299 | class GrSubRunNoCachePainter : public SkGlyphRunPainterInterface { |
| 300 | public: |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 301 | GrSubRunNoCachePainter(skgpu::v1::SurfaceDrawContext*, |
| 302 | GrSubRunAllocator*, |
| 303 | const GrClip*, |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 304 | const SkMatrixProvider& viewMatrix, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 305 | const SkGlyphRunList&, |
| 306 | const SkPaint&); |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 307 | void processDeviceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 308 | const SkStrikeSpec& strikeSpec) override; |
| 309 | void processSourceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 310 | const SkStrikeSpec& strikeSpec) override; |
| 311 | void processSourcePaths(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 312 | const SkFont& runFont, const SkStrikeSpec& strikeSpec) override; |
| 313 | void processSourceSDFT(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 314 | const SkStrikeSpec& strikeSpec, const SkFont& runFont, |
| 315 | SkScalar minScale, SkScalar maxScale) override; |
Robert Phillips | 46eb3ab | 2021-08-02 17:09:01 -0400 | [diff] [blame] | 316 | |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 317 | private: |
Robert Phillips | 46eb3ab | 2021-08-02 17:09:01 -0400 | [diff] [blame] | 318 | |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 319 | // Draw passes ownership of the sub run to the op. |
| 320 | void draw(GrAtlasSubRunOwner subRun); |
| 321 | |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 322 | skgpu::v1::SurfaceDrawContext* const fSDC; |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 323 | GrSubRunAllocator* const fAlloc; |
| 324 | const GrClip* const fClip; |
| 325 | const SkMatrixProvider& fViewMatrix; |
| 326 | const SkGlyphRunList& fGlyphRunList; |
Herb Derby | 0da2c14 | 2021-03-22 15:28:23 -0400 | [diff] [blame] | 327 | const SkPaint& fPaint; |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 328 | }; |
Robert Phillips | 46eb3ab | 2021-08-02 17:09:01 -0400 | [diff] [blame] | 329 | #endif // SK_GPU_V1 |
Herb Derby | 2e0b5bb | 2020-11-19 11:03:50 -0500 | [diff] [blame] | 330 | |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 331 | #endif // GrTextBlob_DEFINED |