joshualitt | 259fbf1 | 2015-07-21 11:39:34 -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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkColorFilter.h" |
| 9 | #include "include/gpu/GrContext.h" |
| 10 | #include "src/core/SkMaskFilterBase.h" |
| 11 | #include "src/core/SkPaintPriv.h" |
| 12 | #include "src/gpu/GrBlurUtils.h" |
| 13 | #include "src/gpu/GrClip.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrStyle.h" |
Michael Ludwig | 663afe5 | 2019-06-03 16:46:19 -0400 | [diff] [blame] | 15 | #include "src/gpu/geometry/GrShape.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/gpu/ops/GrAtlasTextOp.h" |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 17 | #include "src/gpu/text/GrAtlasManager.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/text/GrTextBlob.h" |
| 19 | #include "src/gpu/text/GrTextTarget.h" |
Ben Wagner | 75d6db7 | 2018-09-20 14:39:39 -0400 | [diff] [blame] | 20 | |
Mike Klein | 79aea6a | 2018-06-11 10:45:26 -0400 | [diff] [blame] | 21 | #include <new> |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 22 | |
Ben Wagner | 75d6db7 | 2018-09-20 14:39:39 -0400 | [diff] [blame] | 23 | template <size_t N> static size_t sk_align(size_t s) { |
| 24 | return ((s + (N-1)) / N) * N; |
| 25 | } |
| 26 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 27 | static void calculate_translation(bool applyVM, |
| 28 | const SkMatrix& newViewMatrix, SkScalar newX, SkScalar newY, |
| 29 | const SkMatrix& currentViewMatrix, SkScalar currentX, |
| 30 | SkScalar currentY, SkScalar* transX, SkScalar* transY) { |
| 31 | if (applyVM) { |
| 32 | *transX = newViewMatrix.getTranslateX() + |
| 33 | newViewMatrix.getScaleX() * (newX - currentX) + |
| 34 | newViewMatrix.getSkewX() * (newY - currentY) - |
| 35 | currentViewMatrix.getTranslateX(); |
| 36 | |
| 37 | *transY = newViewMatrix.getTranslateY() + |
| 38 | newViewMatrix.getSkewY() * (newX - currentX) + |
| 39 | newViewMatrix.getScaleY() * (newY - currentY) - |
| 40 | currentViewMatrix.getTranslateY(); |
| 41 | } else { |
| 42 | *transX = newX - currentX; |
| 43 | *transY = newY - currentY; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | static SkMatrix make_inverse(const SkMatrix& matrix) { |
| 48 | SkMatrix inverseMatrix; |
| 49 | if (!matrix.invert(&inverseMatrix)) { |
| 50 | inverseMatrix = SkMatrix::I(); |
| 51 | } |
| 52 | return inverseMatrix; |
| 53 | } |
| 54 | |
| 55 | // -- GrTextBlob::Key ------------------------------------------------------------------------------ |
| 56 | GrTextBlob::Key::Key() { sk_bzero(this, sizeof(Key)); } |
| 57 | |
| 58 | bool GrTextBlob::Key::operator==(const GrTextBlob::Key& other) const { |
| 59 | return 0 == memcmp(this, &other, sizeof(Key)); |
| 60 | } |
| 61 | |
| 62 | // -- GrTextBlob::PathGlyph ------------------------------------------------------------------------ |
| 63 | GrTextBlob::PathGlyph::PathGlyph(const SkPath& path, SkPoint origin) |
| 64 | : fPath(path) |
| 65 | , fOrigin(origin) {} |
| 66 | |
| 67 | // -- GrTextBlob::SubRun --------------------------------------------------------------------------- |
| 68 | GrTextBlob::SubRun::SubRun(SubRunType type, GrTextBlob* textBlob, const SkStrikeSpec& strikeSpec, |
| 69 | GrMaskFormat format, const GrTextBlob::SubRunBufferSpec& bufferSpec, |
| 70 | sk_sp<GrTextStrike>&& grStrike) |
| 71 | : fType{type} |
| 72 | , fBlob{textBlob} |
| 73 | , fMaskFormat{format} |
| 74 | , fGlyphStartIndex{std::get<0>(bufferSpec)} |
| 75 | , fGlyphEndIndex{std::get<1>(bufferSpec)} |
| 76 | , fVertexStartIndex{std::get<2>(bufferSpec)} |
| 77 | , fVertexEndIndex{std::get<3>(bufferSpec)} |
| 78 | , fStrikeSpec{strikeSpec} |
| 79 | , fStrike{grStrike} |
| 80 | , fColor{textBlob->fColor} |
| 81 | , fX{textBlob->fInitialOrigin.x()} |
| 82 | , fY{textBlob->fInitialOrigin.y()} |
| 83 | , fCurrentViewMatrix{textBlob->fInitialViewMatrix} { |
| 84 | SkASSERT(type != kTransformedPath); |
| 85 | } |
| 86 | |
| 87 | GrTextBlob::SubRun::SubRun(GrTextBlob* textBlob, const SkStrikeSpec& strikeSpec) |
| 88 | : fType{kTransformedPath} |
| 89 | , fBlob{textBlob} |
| 90 | , fMaskFormat{kA8_GrMaskFormat} |
| 91 | , fGlyphStartIndex{0} |
| 92 | , fGlyphEndIndex{0} |
| 93 | , fVertexStartIndex{0} |
| 94 | , fVertexEndIndex{0} |
| 95 | , fStrikeSpec{strikeSpec} |
| 96 | , fStrike{nullptr} |
| 97 | , fColor{textBlob->fColor} |
| 98 | , fPaths{} { } |
| 99 | |
| 100 | void GrTextBlob::SubRun::appendGlyphs(const SkZip<SkGlyphVariant, SkPoint>& drawables) { |
| 101 | GrTextStrike* grStrike = fStrike.get(); |
| 102 | SkScalar strikeToSource = fStrikeSpec.strikeToSourceRatio(); |
| 103 | uint32_t glyphCursor = fGlyphStartIndex; |
| 104 | size_t vertexCursor = fVertexStartIndex; |
| 105 | bool hasW = this->hasW(); |
| 106 | GrColor color = this->color(); |
| 107 | // glyphs drawn in perspective must always have a w coord. |
| 108 | SkASSERT(hasW || !fBlob->fInitialViewMatrix.hasPerspective()); |
| 109 | size_t vertexStride = GetVertexStride(fMaskFormat, hasW); |
| 110 | // We always write the third position component used by SDFs. If it is unused it gets |
| 111 | // overwritten. Similarly, we always write the color and the blob will later overwrite it |
| 112 | // with texture coords if it is unused. |
| 113 | size_t colorOffset = hasW ? sizeof(SkPoint3) : sizeof(SkPoint); |
| 114 | for (auto [variant, pos] : drawables) { |
| 115 | SkGlyph* skGlyph = variant; |
| 116 | GrGlyph* grGlyph = grStrike->getGlyph(*skGlyph); |
| 117 | // Only floor the device coordinates. |
| 118 | SkRect dstRect; |
| 119 | if (!this->needsTransform()) { |
| 120 | pos = {SkScalarFloorToScalar(pos.x()), SkScalarFloorToScalar(pos.y())}; |
| 121 | dstRect = grGlyph->destRect(pos); |
| 122 | } else { |
| 123 | dstRect = grGlyph->destRect(pos, strikeToSource); |
| 124 | } |
| 125 | |
| 126 | this->joinGlyphBounds(dstRect); |
| 127 | |
| 128 | intptr_t vertex = reinterpret_cast<intptr_t>(fBlob->fVertices + vertexCursor); |
| 129 | |
| 130 | // V0 |
| 131 | *reinterpret_cast<SkPoint3*>(vertex) = {dstRect.fLeft, dstRect.fTop, 1.f}; |
| 132 | *reinterpret_cast<GrColor*>(vertex + colorOffset) = color; |
| 133 | vertex += vertexStride; |
| 134 | |
| 135 | // V1 |
| 136 | *reinterpret_cast<SkPoint3*>(vertex) = {dstRect.fLeft, dstRect.fBottom, 1.f}; |
| 137 | *reinterpret_cast<GrColor*>(vertex + colorOffset) = color; |
| 138 | vertex += vertexStride; |
| 139 | |
| 140 | // V2 |
| 141 | *reinterpret_cast<SkPoint3*>(vertex) = {dstRect.fRight, dstRect.fTop, 1.f}; |
| 142 | *reinterpret_cast<GrColor*>(vertex + colorOffset) = color; |
| 143 | vertex += vertexStride; |
| 144 | |
| 145 | // V3 |
| 146 | *reinterpret_cast<SkPoint3*>(vertex) = {dstRect.fRight, dstRect.fBottom, 1.f}; |
| 147 | *reinterpret_cast<GrColor*>(vertex + colorOffset) = color; |
| 148 | |
| 149 | vertexCursor += vertexStride * kVerticesPerGlyph; |
| 150 | fBlob->fGlyphs[glyphCursor++] = grGlyph; |
| 151 | } |
| 152 | SkASSERT(glyphCursor == fGlyphEndIndex); |
| 153 | SkASSERT(vertexCursor == fVertexEndIndex); |
| 154 | } |
| 155 | |
| 156 | void GrTextBlob::SubRun::resetBulkUseToken() { fBulkUseToken.reset(); } |
| 157 | |
| 158 | GrDrawOpAtlas::BulkUseTokenUpdater* GrTextBlob::SubRun::bulkUseToken() { return &fBulkUseToken; } |
| 159 | void GrTextBlob::SubRun::setStrike(sk_sp<GrTextStrike> strike) { fStrike = std::move(strike); } |
| 160 | GrTextStrike* GrTextBlob::SubRun::strike() const { return fStrike.get(); } |
| 161 | sk_sp<GrTextStrike> GrTextBlob::SubRun::refStrike() const { return fStrike; } |
| 162 | void GrTextBlob::SubRun::setAtlasGeneration(uint64_t atlasGeneration) { fAtlasGeneration = atlasGeneration;} |
| 163 | uint64_t GrTextBlob::SubRun::atlasGeneration() const { return fAtlasGeneration; } |
| 164 | size_t GrTextBlob::SubRun::vertexStartIndex() const { return fVertexStartIndex; } |
| 165 | uint32_t GrTextBlob::SubRun::glyphCount() const { return fGlyphEndIndex - fGlyphStartIndex; } |
| 166 | uint32_t GrTextBlob::SubRun::glyphStartIndex() const { return fGlyphStartIndex; } |
| 167 | void GrTextBlob::SubRun::setColor(GrColor color) { fColor = color; } |
| 168 | GrColor GrTextBlob::SubRun::color() const { return fColor; } |
| 169 | GrMaskFormat GrTextBlob::SubRun::maskFormat() const { return fMaskFormat; } |
| 170 | const SkRect& GrTextBlob::SubRun::vertexBounds() const { return fVertexBounds; } |
| 171 | void GrTextBlob::SubRun::joinGlyphBounds(const SkRect& glyphBounds) { |
| 172 | fVertexBounds.joinNonEmptyArg(glyphBounds); |
| 173 | } |
| 174 | |
| 175 | void GrTextBlob::SubRun::init(const SkMatrix& viewMatrix, SkScalar x, SkScalar y) { |
| 176 | fCurrentViewMatrix = viewMatrix; |
| 177 | fX = x; |
| 178 | fY = y; |
| 179 | } |
| 180 | |
| 181 | void GrTextBlob::SubRun::computeTranslation(const SkMatrix& viewMatrix, |
| 182 | SkScalar x, SkScalar y, SkScalar* transX, |
| 183 | SkScalar* transY) { |
| 184 | // Don't use the matrix to translate on distance field for fallback subruns. |
| 185 | calculate_translation(!this->drawAsDistanceFields() && !this->needsTransform(), viewMatrix, |
| 186 | x, y, fCurrentViewMatrix, fX, fY, transX, transY); |
| 187 | fCurrentViewMatrix = viewMatrix; |
| 188 | fX = x; |
| 189 | fY = y; |
| 190 | } |
| 191 | |
| 192 | bool GrTextBlob::SubRun::drawAsDistanceFields() const { return fType == kTransformedSDFT; } |
| 193 | |
| 194 | bool GrTextBlob::SubRun::drawAsPaths() const { return fType == kTransformedPath; } |
| 195 | |
| 196 | bool GrTextBlob::SubRun::needsTransform() const { |
| 197 | return fType == kTransformedPath |
| 198 | || fType == kTransformedMask |
| 199 | || fType == kTransformedSDFT; |
| 200 | } |
| 201 | |
| 202 | bool GrTextBlob::SubRun::hasW() const { |
| 203 | return fBlob->hasW(fType); |
| 204 | } |
| 205 | |
| 206 | void GrTextBlob::SubRun::setUseLCDText(bool useLCDText) { fFlags.useLCDText = useLCDText; } |
| 207 | bool GrTextBlob::SubRun::hasUseLCDText() const { return fFlags.useLCDText; } |
| 208 | void GrTextBlob::SubRun::setAntiAliased(bool antiAliased) { fFlags.antiAliased = antiAliased; } |
| 209 | bool GrTextBlob::SubRun::isAntiAliased() const { return fFlags.antiAliased; } |
| 210 | const SkStrikeSpec& GrTextBlob::SubRun::strikeSpec() const { return fStrikeSpec; } |
| 211 | |
| 212 | // -- GrTextBlob ----------------------------------------------------------------------------------- |
| 213 | void GrTextBlob::operator delete(void* p) { ::operator delete(p); } |
| 214 | void* GrTextBlob::operator new(size_t) { SK_ABORT("All blobs are created by placement new."); } |
| 215 | void* GrTextBlob::operator new(size_t, void* p) { return p; } |
| 216 | |
| 217 | GrTextBlob::~GrTextBlob() = default; |
| 218 | |
Herb Derby | a00da61 | 2019-03-04 17:10:01 -0500 | [diff] [blame] | 219 | sk_sp<GrTextBlob> GrTextBlob::Make(int glyphCount, |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 220 | GrStrikeCache* strikeCache, |
Herb Derby | e9f691d | 2019-12-04 12:11:13 -0500 | [diff] [blame] | 221 | const SkMatrix& viewMatrix, |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 222 | SkPoint origin, |
Herb Derby | a00da61 | 2019-03-04 17:10:01 -0500 | [diff] [blame] | 223 | GrColor color, |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 224 | bool forceWForDistanceFields) { |
Herb Derby | cd498e1 | 2019-12-06 14:17:31 -0500 | [diff] [blame] | 225 | |
Herb Derby | 99f228e | 2019-12-06 16:48:55 -0500 | [diff] [blame] | 226 | size_t vertexSize = sizeof(skstd::aligned_union_t<0, Mask2DVertex, ARGB2DVertex>); |
Herb Derby | e74c776 | 2019-12-04 14:15:41 -0500 | [diff] [blame] | 227 | if (viewMatrix.hasPerspective() || forceWForDistanceFields) { |
Herb Derby | 99f228e | 2019-12-06 16:48:55 -0500 | [diff] [blame] | 228 | vertexSize = sizeof(skstd::aligned_union_t<0, SDFT3DVertex, ARGB3DVertex>); |
Herb Derby | e74c776 | 2019-12-04 14:15:41 -0500 | [diff] [blame] | 229 | } |
| 230 | |
Herb Derby | cd498e1 | 2019-12-06 14:17:31 -0500 | [diff] [blame] | 231 | size_t quadSize = kVerticesPerGlyph * vertexSize; |
| 232 | |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 233 | // We allocate size for the GrTextBlob itself, plus size for the vertices array, |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 234 | // and size for the glyphIds array. |
Herb Derby | e74c776 | 2019-12-04 14:15:41 -0500 | [diff] [blame] | 235 | size_t verticesCount = glyphCount * quadSize; |
Ben Wagner | 75d6db7 | 2018-09-20 14:39:39 -0400 | [diff] [blame] | 236 | |
Herb Derby | f7d5d74 | 2018-11-16 13:24:32 -0500 | [diff] [blame] | 237 | size_t blobStart = 0; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 238 | size_t vertex = sk_align<alignof(char)> (blobStart + sizeof(GrTextBlob) * 1); |
| 239 | size_t glyphs = sk_align<alignof(GrGlyph*)> (vertex + sizeof(char) * verticesCount); |
| 240 | size_t size = (glyphs + sizeof(GrGlyph*) * glyphCount); |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 241 | |
Herb Derby | b12175f | 2018-05-23 16:38:09 -0400 | [diff] [blame] | 242 | void* allocation = ::operator new (size); |
| 243 | |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 244 | if (CACHE_SANITY_CHECK) { |
| 245 | sk_bzero(allocation, size); |
| 246 | } |
| 247 | |
Herb Derby | 00ae959 | 2019-12-03 15:55:56 -0500 | [diff] [blame] | 248 | sk_sp<GrTextBlob> blob{new (allocation) GrTextBlob{ |
Herb Derby | e9f691d | 2019-12-04 12:11:13 -0500 | [diff] [blame] | 249 | size, strikeCache, viewMatrix, origin, color, forceWForDistanceFields}}; |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 250 | |
| 251 | // setup offsets for vertices / glyphs |
Herb Derby | f7d5d74 | 2018-11-16 13:24:32 -0500 | [diff] [blame] | 252 | blob->fVertices = SkTAddOffset<char>(blob.get(), vertex); |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 253 | blob->fGlyphs = SkTAddOffset<GrGlyph*>(blob.get(), glyphs); |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 254 | |
Herb Derby | f7d5d74 | 2018-11-16 13:24:32 -0500 | [diff] [blame] | 255 | return blob; |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 258 | void GrTextBlob::generateFromGlyphRunList(const GrShaderCaps& shaderCaps, |
| 259 | const GrTextContext::Options& options, |
| 260 | const SkPaint& paint, |
| 261 | const SkMatrix& viewMatrix, |
| 262 | const SkSurfaceProps& props, |
| 263 | const SkGlyphRunList& glyphRunList, |
| 264 | SkGlyphRunListPainter* glyphPainter) { |
| 265 | const SkPaint& runPaint = glyphRunList.paint(); |
| 266 | this->initReusableBlob(SkPaintPriv::ComputeLuminanceColor(runPaint)); |
| 267 | |
| 268 | glyphPainter->processGlyphRunList(glyphRunList, |
| 269 | viewMatrix, |
| 270 | props, |
| 271 | shaderCaps.supportsDistanceFieldText(), |
| 272 | options, |
| 273 | this); |
| 274 | } |
| 275 | |
| 276 | void GrTextBlob::setupKey(const GrTextBlob::Key& key, const SkMaskFilterBase::BlurRec& blurRec, |
| 277 | const SkPaint& paint) { |
| 278 | fKey = key; |
| 279 | if (key.fHasBlur) { |
| 280 | fBlurRec = blurRec; |
| 281 | } |
| 282 | if (key.fStyle != SkPaint::kFill_Style) { |
| 283 | fStrokeInfo.fFrameWidth = paint.getStrokeWidth(); |
| 284 | fStrokeInfo.fMiterLimit = paint.getStrokeMiter(); |
| 285 | fStrokeInfo.fJoin = paint.getStrokeJoin(); |
| 286 | } |
| 287 | } |
| 288 | const GrTextBlob::Key& GrTextBlob::GetKey(const GrTextBlob& blob) { return blob.fKey; } |
| 289 | uint32_t GrTextBlob::Hash(const GrTextBlob::Key& key) { return SkOpts::hash(&key, sizeof(Key)); } |
| 290 | |
| 291 | bool GrTextBlob::hasDistanceField() const { return SkToBool(fTextType & kHasDistanceField_TextType); } |
| 292 | bool GrTextBlob::hasBitmap() const { return SkToBool(fTextType & kHasBitmap_TextType); } |
| 293 | bool GrTextBlob::hasPerspective() const { return fInitialViewMatrix.hasPerspective(); } |
| 294 | |
| 295 | void GrTextBlob::setHasDistanceField() { fTextType |= kHasDistanceField_TextType; } |
| 296 | void GrTextBlob::setHasBitmap() { fTextType |= kHasBitmap_TextType; } |
| 297 | void GrTextBlob::setMinAndMaxScale(SkScalar scaledMin, SkScalar scaledMax) { |
| 298 | // we init fMaxMinScale and fMinMaxScale in the constructor |
| 299 | fMaxMinScale = SkMaxScalar(scaledMin, fMaxMinScale); |
| 300 | fMinMaxScale = SkMinScalar(scaledMax, fMinMaxScale); |
| 301 | } |
| 302 | |
| 303 | size_t GrTextBlob::GetVertexStride(GrMaskFormat maskFormat, bool hasWCoord) { |
| 304 | switch (maskFormat) { |
| 305 | case kA8_GrMaskFormat: |
Herb Derby | cd498e1 | 2019-12-06 14:17:31 -0500 | [diff] [blame] | 306 | return hasWCoord ? sizeof(SDFT3DVertex) : sizeof(Mask2DVertex); |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 307 | case kARGB_GrMaskFormat: |
Herb Derby | cd498e1 | 2019-12-06 14:17:31 -0500 | [diff] [blame] | 308 | return hasWCoord ? sizeof(ARGB3DVertex) : sizeof(ARGB2DVertex); |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 309 | default: |
| 310 | SkASSERT(!hasWCoord); |
Herb Derby | cd498e1 | 2019-12-06 14:17:31 -0500 | [diff] [blame] | 311 | return sizeof(Mask2DVertex); |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
Herb Derby | 0edb214 | 2018-10-16 17:04:11 -0400 | [diff] [blame] | 315 | bool GrTextBlob::mustRegenerate(const SkPaint& paint, bool anyRunHasSubpixelPosition, |
| 316 | const SkMaskFilterBase::BlurRec& blurRec, |
| 317 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y) { |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 318 | // If we have LCD text then our canonical color will be set to transparent, in this case we have |
| 319 | // to regenerate the blob on any color change |
| 320 | // We use the grPaint to get any color filter effects |
| 321 | if (fKey.fCanonicalColor == SK_ColorTRANSPARENT && |
Mike Reed | ec7278e | 2019-02-01 14:00:34 -0500 | [diff] [blame] | 322 | fLuminanceColor != SkPaintPriv::ComputeLuminanceColor(paint)) { |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 323 | return true; |
| 324 | } |
| 325 | |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 326 | if (fInitialViewMatrix.hasPerspective() != viewMatrix.hasPerspective()) { |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 327 | return true; |
| 328 | } |
| 329 | |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 330 | /** This could be relaxed for blobs with only distance field glyphs. */ |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 331 | if (fInitialViewMatrix.hasPerspective() && !fInitialViewMatrix.cheapEqualTo(viewMatrix)) { |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 332 | return true; |
| 333 | } |
| 334 | |
| 335 | // We only cache one masked version |
| 336 | if (fKey.fHasBlur && |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 337 | (fBlurRec.fSigma != blurRec.fSigma || fBlurRec.fStyle != blurRec.fStyle)) { |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 338 | return true; |
| 339 | } |
| 340 | |
| 341 | // Similarly, we only cache one version for each style |
| 342 | if (fKey.fStyle != SkPaint::kFill_Style && |
Herb Derby | bc6f9c9 | 2018-08-08 13:58:45 -0400 | [diff] [blame] | 343 | (fStrokeInfo.fFrameWidth != paint.getStrokeWidth() || |
| 344 | fStrokeInfo.fMiterLimit != paint.getStrokeMiter() || |
| 345 | fStrokeInfo.fJoin != paint.getStrokeJoin())) { |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 346 | return true; |
| 347 | } |
| 348 | |
| 349 | // Mixed blobs must be regenerated. We could probably figure out a way to do integer scrolls |
| 350 | // for mixed blobs if this becomes an issue. |
| 351 | if (this->hasBitmap() && this->hasDistanceField()) { |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 352 | // Identical view matrices and we can reuse in all cases |
| 353 | return !(fInitialViewMatrix.cheapEqualTo(viewMatrix) && SkPoint{x, y} == fInitialOrigin); |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | if (this->hasBitmap()) { |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 357 | if (fInitialViewMatrix.getScaleX() != viewMatrix.getScaleX() || |
| 358 | fInitialViewMatrix.getScaleY() != viewMatrix.getScaleY() || |
| 359 | fInitialViewMatrix.getSkewX() != viewMatrix.getSkewX() || |
| 360 | fInitialViewMatrix.getSkewY() != viewMatrix.getSkewY()) { |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 361 | return true; |
| 362 | } |
| 363 | |
Herb Derby | 9830fc4 | 2019-09-12 10:58:26 -0400 | [diff] [blame] | 364 | // TODO(herb): this is not needed for full pixel glyph choice, but is needed to adjust |
| 365 | // the quads properly. Devise a system that regenerates the quads from original data |
| 366 | // using the transform to allow this to be used in general. |
| 367 | |
| 368 | // We can update the positions in the text blob without regenerating the whole |
| 369 | // blob, but only for integer translations. |
| 370 | // This cool bit of math will determine the necessary translation to apply to the |
| 371 | // already generated vertex coordinates to move them to the correct position. |
| 372 | // Figure out the translation in view space given a translation in source space. |
| 373 | SkScalar transX = viewMatrix.getTranslateX() + |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 374 | viewMatrix.getScaleX() * (x - fInitialOrigin.x()) + |
| 375 | viewMatrix.getSkewX() * (y - fInitialOrigin.y()) - |
Herb Derby | 9830fc4 | 2019-09-12 10:58:26 -0400 | [diff] [blame] | 376 | fInitialViewMatrix.getTranslateX(); |
| 377 | SkScalar transY = viewMatrix.getTranslateY() + |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 378 | viewMatrix.getSkewY() * (x - fInitialOrigin.x()) + |
| 379 | viewMatrix.getScaleY() * (y - fInitialOrigin.y()) - |
Herb Derby | 9830fc4 | 2019-09-12 10:58:26 -0400 | [diff] [blame] | 380 | fInitialViewMatrix.getTranslateY(); |
| 381 | if (!SkScalarIsInt(transX) || !SkScalarIsInt(transY)) { |
| 382 | return true; |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 383 | } |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 384 | } else if (this->hasDistanceField()) { |
| 385 | // A scale outside of [blob.fMaxMinScale, blob.fMinMaxScale] would result in a different |
| 386 | // distance field being generated, so we have to regenerate in those cases |
| 387 | SkScalar newMaxScale = viewMatrix.getMaxScale(); |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 388 | SkScalar oldMaxScale = fInitialViewMatrix.getMaxScale(); |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 389 | SkScalar scaleAdjust = newMaxScale / oldMaxScale; |
| 390 | if (scaleAdjust < fMaxMinScale || scaleAdjust > fMinMaxScale) { |
| 391 | return true; |
| 392 | } |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 393 | } |
| 394 | |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 395 | // It is possible that a blob has neither distanceField nor bitmaptext. This is in the case |
| 396 | // when all of the runs inside the blob are drawn as paths. In this case, we always regenerate |
| 397 | // the blob anyways at flush time, so no need to regenerate explicitly |
| 398 | return false; |
| 399 | } |
| 400 | |
Herb Derby | c1b482c | 2018-08-09 15:02:27 -0400 | [diff] [blame] | 401 | void GrTextBlob::flush(GrTextTarget* target, const SkSurfaceProps& props, |
| 402 | const GrDistanceFieldAdjustTable* distanceAdjustTable, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 403 | const SkPaint& paint, const SkPMColor4f& filteredColor, const GrClip& clip, |
Robert Phillips | e4643cc | 2018-08-14 13:01:29 -0400 | [diff] [blame] | 404 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y) { |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 405 | |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 406 | for (auto& subRun : fSubRuns) { |
| 407 | if (subRun.drawAsPaths()) { |
Herb Derby | dac1ed5 | 2018-09-12 17:04:21 -0400 | [diff] [blame] | 408 | SkPaint runPaint{paint}; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 409 | runPaint.setAntiAlias(subRun.isAntiAliased()); |
| 410 | // If there are shaders, blurs or styles, the path must be scaled into source |
| 411 | // space independently of the CTM. This allows the CTM to be correct for the |
| 412 | // different effects. |
| 413 | GrStyle style(runPaint); |
Herb Derby | 9f49148 | 2018-08-08 11:53:00 -0400 | [diff] [blame] | 414 | |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 415 | bool scalePath = runPaint.getShader() |
| 416 | || style.applies() |
| 417 | || runPaint.getMaskFilter(); |
Robert Phillips | 137ca52 | 2018-08-15 10:14:33 -0400 | [diff] [blame] | 418 | |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 419 | // The origin for the blob may have changed, so figure out the delta. |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 420 | SkVector originShift = SkPoint{x, y} - fInitialOrigin; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 421 | |
| 422 | for (const auto& pathGlyph : subRun.fPaths) { |
| 423 | SkMatrix ctm{viewMatrix}; |
| 424 | SkMatrix pathMatrix = SkMatrix::MakeScale(subRun.fStrikeSpec.strikeToSourceRatio()); |
| 425 | // Shift the original glyph location in source space to the position of the new |
| 426 | // blob. |
| 427 | pathMatrix.postTranslate(originShift.x() + pathGlyph.fOrigin.x(), |
| 428 | originShift.y() + pathGlyph.fOrigin.y()); |
Herb Derby | dac1ed5 | 2018-09-12 17:04:21 -0400 | [diff] [blame] | 429 | |
| 430 | // TmpPath must be in the same scope as GrShape shape below. |
Robert Phillips | 137ca52 | 2018-08-15 10:14:33 -0400 | [diff] [blame] | 431 | SkTLazy<SkPath> tmpPath; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 432 | const SkPath* path = &pathGlyph.fPath; |
Herb Derby | 2984d26 | 2019-11-20 14:40:39 -0500 | [diff] [blame] | 433 | if (!scalePath) { |
| 434 | // Scale can be applied to CTM -- no effects. |
Herb Derby | 2984d26 | 2019-11-20 14:40:39 -0500 | [diff] [blame] | 435 | ctm.preConcat(pathMatrix); |
Robert Phillips | d20d261 | 2018-08-28 10:09:01 -0400 | [diff] [blame] | 436 | } else { |
Herb Derby | 2984d26 | 2019-11-20 14:40:39 -0500 | [diff] [blame] | 437 | // Scale the outline into source space. |
Herb Derby | dac1ed5 | 2018-09-12 17:04:21 -0400 | [diff] [blame] | 438 | |
Herb Derby | 2984d26 | 2019-11-20 14:40:39 -0500 | [diff] [blame] | 439 | // Transform the path form the normalized outline to source space. This |
| 440 | // way the CTM will remain the same so it can be used by the effects. |
| 441 | SkPath* sourceOutline = tmpPath.init(); |
| 442 | path->transform(pathMatrix, sourceOutline); |
| 443 | sourceOutline->setIsVolatile(true); |
| 444 | path = sourceOutline; |
Robert Phillips | 137ca52 | 2018-08-15 10:14:33 -0400 | [diff] [blame] | 445 | } |
| 446 | |
Robert Phillips | 46a1338 | 2018-08-23 13:53:01 -0400 | [diff] [blame] | 447 | // TODO: we are losing the mutability of the path here |
| 448 | GrShape shape(*path, paint); |
Herb Derby | dac1ed5 | 2018-09-12 17:04:21 -0400 | [diff] [blame] | 449 | target->drawShape(clip, runPaint, ctm, shape); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 450 | } |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 451 | } else { |
| 452 | int glyphCount = subRun.glyphCount(); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 453 | if (0 == glyphCount) { |
| 454 | continue; |
| 455 | } |
| 456 | |
| 457 | bool skipClip = false; |
| 458 | bool submitOp = true; |
| 459 | SkIRect clipRect = SkIRect::MakeEmpty(); |
| 460 | SkRect rtBounds = SkRect::MakeWH(target->width(), target->height()); |
| 461 | SkRRect clipRRect; |
| 462 | GrAA aa; |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 463 | // We can clip geometrically if we're not using SDFs or transformed glyphs, |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 464 | // and we have an axis-aligned rectangular non-AA clip |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 465 | if (!subRun.drawAsDistanceFields() && !subRun.needsTransform() && |
Jim Van Verth | cf838c7 | 2018-03-05 14:40:36 -0500 | [diff] [blame] | 466 | clip.isRRect(rtBounds, &clipRRect, &aa) && |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 467 | clipRRect.isRect() && GrAA::kNo == aa) { |
| 468 | skipClip = true; |
| 469 | // We only need to do clipping work if the subrun isn't contained by the clip |
| 470 | SkRect subRunBounds; |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 471 | this->computeSubRunBounds(&subRunBounds, subRun, viewMatrix, x, y, false); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 472 | if (!clipRRect.getBounds().contains(subRunBounds)) { |
| 473 | // If the subrun is completely outside, don't add an op for it |
| 474 | if (!clipRRect.getBounds().intersects(subRunBounds)) { |
| 475 | submitOp = false; |
| 476 | } |
| 477 | else { |
| 478 | clipRRect.getBounds().round(&clipRect); |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | if (submitOp) { |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 484 | auto op = this->makeOp(subRun, glyphCount, viewMatrix, x, y, |
Herb Derby | bc6f9c9 | 2018-08-08 13:58:45 -0400 | [diff] [blame] | 485 | clipRect, paint, filteredColor, props, distanceAdjustTable, |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 486 | target); |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 487 | if (op) { |
| 488 | if (skipClip) { |
| 489 | target->addDrawOp(GrNoClip(), std::move(op)); |
| 490 | } |
| 491 | else { |
| 492 | target->addDrawOp(clip, std::move(op)); |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | } |
Jim Van Verth | 89737de | 2018-02-06 21:30:20 +0000 | [diff] [blame] | 497 | } |
Jim Van Verth | 89737de | 2018-02-06 21:30:20 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 500 | void GrTextBlob::computeSubRunBounds(SkRect* outBounds, const GrTextBlob::SubRun& subRun, |
| 501 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y, |
| 502 | bool needsGlyphTransform) { |
| 503 | // We don't yet position distance field text on the cpu, so we have to map the vertex bounds |
| 504 | // into device space. |
| 505 | // We handle vertex bounds differently for distance field text and bitmap text because |
| 506 | // the vertex bounds of bitmap text are in device space. If we are flushing multiple runs |
| 507 | // from one blob then we are going to pay the price here of mapping the rect for each run. |
| 508 | *outBounds = subRun.vertexBounds(); |
| 509 | if (needsGlyphTransform) { |
| 510 | // Distance field text is positioned with the (X,Y) as part of the glyph position, |
| 511 | // and currently the view matrix is applied on the GPU |
| 512 | outBounds->offset(SkPoint{x, y} - fInitialOrigin); |
| 513 | viewMatrix.mapRect(outBounds); |
| 514 | } else { |
| 515 | // Bitmap text is fully positioned on the CPU, and offset by an (X,Y) translate in |
| 516 | // device space. |
| 517 | SkMatrix boundsMatrix = fInitialViewMatrixInverse; |
| 518 | |
| 519 | boundsMatrix.postTranslate(-fInitialOrigin.x(), -fInitialOrigin.y()); |
| 520 | |
| 521 | boundsMatrix.postTranslate(x, y); |
| 522 | |
| 523 | boundsMatrix.postConcat(viewMatrix); |
| 524 | boundsMatrix.mapRect(outBounds); |
| 525 | |
| 526 | // Due to floating point numerical inaccuracies, we have to round out here |
| 527 | outBounds->roundOut(outBounds); |
| 528 | } |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 529 | } |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 530 | |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 531 | void GrTextBlob::AssertEqual(const GrTextBlob& l, const GrTextBlob& r) { |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 532 | SkASSERT_RELEASE(l.fSize == r.fSize); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 533 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 534 | SkASSERT_RELEASE(l.fBlurRec.fSigma == r.fBlurRec.fSigma); |
| 535 | SkASSERT_RELEASE(l.fBlurRec.fStyle == r.fBlurRec.fStyle); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 536 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 537 | SkASSERT_RELEASE(l.fStrokeInfo.fFrameWidth == r.fStrokeInfo.fFrameWidth); |
| 538 | SkASSERT_RELEASE(l.fStrokeInfo.fMiterLimit == r.fStrokeInfo.fMiterLimit); |
| 539 | SkASSERT_RELEASE(l.fStrokeInfo.fJoin == r.fStrokeInfo.fJoin); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 540 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 541 | SkASSERT_RELEASE(l.fKey == r.fKey); |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 542 | //SkASSERT_RELEASE(l.fPaintColor == r.fPaintColor); // Colors might not actually be identical |
| 543 | SkASSERT_RELEASE(l.fMaxMinScale == r.fMaxMinScale); |
| 544 | SkASSERT_RELEASE(l.fMinMaxScale == r.fMinMaxScale); |
| 545 | SkASSERT_RELEASE(l.fTextType == r.fTextType); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 546 | |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 547 | for(auto t : SkMakeZip(l.fSubRuns, r.fSubRuns)) { |
| 548 | const SubRun& lSubRun = std::get<0>(t); |
| 549 | const SubRun& rSubRun = std::get<1>(t); |
| 550 | SkASSERT(lSubRun.drawAsPaths() == rSubRun.drawAsPaths()); |
| 551 | if (!lSubRun.drawAsPaths()) { |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 552 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 553 | // TODO we can do this check, but we have to apply the VM to the old vertex bounds |
| 554 | //SkASSERT_RELEASE(lSubRun.vertexBounds() == rSubRun.vertexBounds()); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 555 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 556 | if (lSubRun.strike()) { |
| 557 | SkASSERT_RELEASE(rSubRun.strike()); |
Robert Phillips | caf1ebb | 2018-03-01 14:28:44 -0500 | [diff] [blame] | 558 | SkASSERT_RELEASE(GrTextStrike::GetKey(*lSubRun.strike()) == |
| 559 | GrTextStrike::GetKey(*rSubRun.strike())); |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 560 | |
| 561 | } else { |
| 562 | SkASSERT_RELEASE(!rSubRun.strike()); |
| 563 | } |
| 564 | |
| 565 | SkASSERT_RELEASE(lSubRun.vertexStartIndex() == rSubRun.vertexStartIndex()); |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 566 | SkASSERT_RELEASE(lSubRun.glyphStartIndex() == rSubRun.glyphStartIndex()); |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 567 | SkASSERT_RELEASE(lSubRun.maskFormat() == rSubRun.maskFormat()); |
| 568 | SkASSERT_RELEASE(lSubRun.drawAsDistanceFields() == rSubRun.drawAsDistanceFields()); |
| 569 | SkASSERT_RELEASE(lSubRun.hasUseLCDText() == rSubRun.hasUseLCDText()); |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 570 | } else { |
| 571 | SkASSERT_RELEASE(lSubRun.fPaths.size() == rSubRun.fPaths.size()); |
| 572 | for(auto p : SkMakeZip(lSubRun.fPaths, rSubRun.fPaths)) { |
| 573 | const PathGlyph& lPath = std::get<0>(p); |
| 574 | const PathGlyph& rPath = std::get<1>(p); |
| 575 | SkASSERT_RELEASE(lPath.fPath == rPath.fPath); |
| 576 | // We can't assert that these have the same translations |
| 577 | } |
Jim Van Verth | 54d9c88 | 2018-02-08 16:14:48 -0500 | [diff] [blame] | 578 | } |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 579 | } |
| 580 | } |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 581 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 582 | void GrTextBlob::initReusableBlob(SkColor luminanceColor) { |
| 583 | fLuminanceColor = luminanceColor; |
| 584 | } |
| 585 | |
| 586 | const GrTextBlob::Key& GrTextBlob::key() const { return fKey; } |
| 587 | size_t GrTextBlob::size() const { return fSize; } |
| 588 | |
| 589 | std::unique_ptr<GrDrawOp> GrTextBlob::test_makeOp( |
| 590 | int glyphCount, const SkMatrix& viewMatrix, |
| 591 | SkScalar x, SkScalar y, const SkPaint& paint, const SkPMColor4f& filteredColor, |
| 592 | const SkSurfaceProps& props, const GrDistanceFieldAdjustTable* distanceAdjustTable, |
| 593 | GrTextTarget* target) { |
| 594 | GrTextBlob::SubRun& info = fSubRuns[0]; |
| 595 | SkIRect emptyRect = SkIRect::MakeEmpty(); |
| 596 | return this->makeOp(info, glyphCount, viewMatrix, x, y, emptyRect, |
| 597 | paint, filteredColor, props, distanceAdjustTable, target); |
| 598 | } |
| 599 | |
| 600 | bool GrTextBlob::hasW(GrTextBlob::SubRunType type) const { |
| 601 | if (type == kTransformedSDFT) { |
| 602 | return this->hasPerspective() || fForceWForDistanceFields; |
| 603 | } else if (type == kTransformedMask || type == kTransformedPath) { |
| 604 | return this->hasPerspective(); |
Herb Derby | e9f691d | 2019-12-04 12:11:13 -0500 | [diff] [blame] | 605 | } |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 606 | |
| 607 | // The viewMatrix is implicitly SkMatrix::I when drawing kDirectMask, because it is not |
| 608 | // used. |
| 609 | return false; |
| 610 | } |
| 611 | |
| 612 | GrTextBlob::SubRun* GrTextBlob::makeSubRun(SubRunType type, |
| 613 | const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 614 | const SkStrikeSpec& strikeSpec, |
| 615 | GrMaskFormat format) { |
| 616 | bool hasW = this->hasW(type); |
| 617 | uint32_t glyphsStart = fGlyphsCursor; |
| 618 | fGlyphsCursor += drawables.size(); |
| 619 | uint32_t glyphsEnd = fGlyphsCursor; |
| 620 | size_t verticesStart = fVerticesCursor; |
| 621 | fVerticesCursor += drawables.size() * GetVertexStride(format, hasW) * kVerticesPerGlyph; |
| 622 | size_t verticesEnd = fVerticesCursor; |
| 623 | |
| 624 | SubRunBufferSpec bufferSpec = std::make_tuple( |
| 625 | glyphsStart, glyphsEnd, verticesStart, verticesEnd); |
| 626 | |
| 627 | sk_sp<GrTextStrike> grStrike = strikeSpec.findOrCreateGrStrike(fStrikeCache); |
| 628 | |
| 629 | SubRun& subRun = fSubRuns.emplace_back( |
| 630 | type, this, strikeSpec, format, bufferSpec, std::move(grStrike)); |
| 631 | |
| 632 | subRun.appendGlyphs(drawables); |
| 633 | |
| 634 | return &subRun; |
| 635 | } |
| 636 | |
| 637 | void GrTextBlob::addSingleMaskFormat( |
| 638 | SubRunType type, |
| 639 | const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 640 | const SkStrikeSpec& strikeSpec, |
| 641 | GrMaskFormat format) { |
| 642 | this->makeSubRun(type, drawables, strikeSpec, format); |
| 643 | } |
| 644 | |
| 645 | void GrTextBlob::addMultiMaskFormat( |
| 646 | SubRunType type, |
| 647 | const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 648 | const SkStrikeSpec& strikeSpec) { |
| 649 | this->setHasBitmap(); |
| 650 | if (drawables.empty()) { return; } |
| 651 | |
| 652 | auto glyphSpan = drawables.get<0>(); |
| 653 | SkGlyph* glyph = glyphSpan[0]; |
| 654 | GrMaskFormat format = GrGlyph::FormatFromSkGlyph(glyph->maskFormat()); |
| 655 | size_t startIndex = 0; |
| 656 | for (size_t i = 1; i < drawables.size(); i++) { |
| 657 | glyph = glyphSpan[i]; |
| 658 | GrMaskFormat nextFormat = GrGlyph::FormatFromSkGlyph(glyph->maskFormat()); |
| 659 | if (format != nextFormat) { |
| 660 | auto sameFormat = drawables.subspan(startIndex, i - startIndex); |
| 661 | this->addSingleMaskFormat(type, sameFormat, strikeSpec, format); |
| 662 | format = nextFormat; |
| 663 | startIndex = i; |
| 664 | } |
| 665 | } |
| 666 | auto sameFormat = drawables.last(drawables.size() - startIndex); |
| 667 | this->addSingleMaskFormat(type, sameFormat, strikeSpec, format); |
| 668 | } |
| 669 | |
| 670 | void GrTextBlob::addSDFT(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 671 | const SkStrikeSpec& strikeSpec, |
| 672 | const SkFont& runFont, |
| 673 | SkScalar minScale, |
| 674 | SkScalar maxScale) { |
| 675 | this->setHasDistanceField(); |
| 676 | this->setMinAndMaxScale(minScale, maxScale); |
| 677 | |
| 678 | SubRun* subRun = this->makeSubRun(kTransformedSDFT, drawables, strikeSpec, kA8_GrMaskFormat); |
| 679 | subRun->setUseLCDText(runFont.getEdging() == SkFont::Edging::kSubpixelAntiAlias); |
| 680 | subRun->setAntiAliased(runFont.hasSomeAntiAliasing()); |
Herb Derby | e9f691d | 2019-12-04 12:11:13 -0500 | [diff] [blame] | 681 | } |
| 682 | |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 683 | GrTextBlob::GrTextBlob(size_t size, |
| 684 | GrStrikeCache* strikeCache, |
Herb Derby | e9f691d | 2019-12-04 12:11:13 -0500 | [diff] [blame] | 685 | const SkMatrix& viewMatrix, |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 686 | SkPoint origin, |
| 687 | GrColor color, |
Herb Derby | 00ae959 | 2019-12-03 15:55:56 -0500 | [diff] [blame] | 688 | bool forceWForDistanceFields) |
| 689 | : fSize{size} |
| 690 | , fStrikeCache{strikeCache} |
Herb Derby | e9f691d | 2019-12-04 12:11:13 -0500 | [diff] [blame] | 691 | , fInitialViewMatrix{viewMatrix} |
| 692 | , fInitialViewMatrixInverse{make_inverse(viewMatrix)} |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 693 | , fInitialOrigin{origin} |
Herb Derby | 00ae959 | 2019-12-03 15:55:56 -0500 | [diff] [blame] | 694 | , fForceWForDistanceFields{forceWForDistanceFields} |
| 695 | , fColor{color} { } |
| 696 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 697 | inline std::unique_ptr<GrAtlasTextOp> GrTextBlob::makeOp( |
| 698 | SubRun& info, int glyphCount, |
| 699 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipRect, |
| 700 | const SkPaint& paint, const SkPMColor4f& filteredColor, const SkSurfaceProps& props, |
| 701 | const GrDistanceFieldAdjustTable* distanceAdjustTable, GrTextTarget* target) { |
| 702 | GrMaskFormat format = info.maskFormat(); |
| 703 | |
| 704 | GrPaint grPaint; |
| 705 | target->makeGrPaint(info.maskFormat(), paint, viewMatrix, &grPaint); |
| 706 | std::unique_ptr<GrAtlasTextOp> op; |
| 707 | if (info.drawAsDistanceFields()) { |
| 708 | // TODO: Can we be even smarter based on the dest transfer function? |
| 709 | op = GrAtlasTextOp::MakeDistanceField( |
| 710 | target->getContext(), std::move(grPaint), glyphCount, distanceAdjustTable, |
| 711 | target->colorInfo().isLinearlyBlended(), SkPaintPriv::ComputeLuminanceColor(paint), |
| 712 | props, info.isAntiAliased(), info.hasUseLCDText()); |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 713 | } else { |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 714 | op = GrAtlasTextOp::MakeBitmap(target->getContext(), std::move(grPaint), format, glyphCount, |
| 715 | info.needsTransform()); |
| 716 | } |
| 717 | GrAtlasTextOp::Geometry& geometry = op->geometry(); |
| 718 | geometry.fViewMatrix = viewMatrix; |
| 719 | geometry.fClipRect = clipRect; |
| 720 | geometry.fBlob = SkRef(this); |
| 721 | geometry.fSubRunPtr = &info; |
| 722 | geometry.fColor = info.maskFormat() == kARGB_GrMaskFormat ? SK_PMColor4fWHITE : filteredColor; |
| 723 | geometry.fX = x; |
| 724 | geometry.fY = y; |
| 725 | op->init(); |
| 726 | return op; |
| 727 | } |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 728 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 729 | void GrTextBlob::processDeviceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 730 | const SkStrikeSpec& strikeSpec) { |
| 731 | this->addMultiMaskFormat(kDirectMask, drawables, strikeSpec); |
| 732 | } |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 733 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 734 | void GrTextBlob::processSourcePaths(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 735 | const SkFont& runFont, |
| 736 | const SkStrikeSpec& strikeSpec) { |
| 737 | this->setHasBitmap(); |
| 738 | SubRun& subRun = fSubRuns.emplace_back(this, strikeSpec); |
| 739 | subRun.setAntiAliased(runFont.hasSomeAntiAliasing()); |
| 740 | for (auto [variant, pos] : drawables) { |
| 741 | subRun.fPaths.emplace_back(*variant.path(), pos); |
Herb Derby | eba195f | 2019-12-03 16:44:47 -0500 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 745 | void GrTextBlob::processSourceSDFT(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 746 | const SkStrikeSpec& strikeSpec, |
| 747 | const SkFont& runFont, |
| 748 | SkScalar minScale, |
| 749 | SkScalar maxScale) { |
| 750 | this->addSDFT(drawables, strikeSpec, runFont, minScale, maxScale); |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 751 | } |
Herb Derby | a904764 | 2019-12-06 12:12:11 -0500 | [diff] [blame] | 752 | |
| 753 | void GrTextBlob::processSourceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables, |
| 754 | const SkStrikeSpec& strikeSpec) { |
| 755 | this->addMultiMaskFormat(kTransformedMask, drawables, strikeSpec); |
| 756 | } |
| 757 | |
| 758 | // -- GrTextBlob::VertexRegenerator ---------------------------------------------------------------- |
| 759 | enum RegenMask { |
| 760 | kNoRegen = 0x0, |
| 761 | kRegenPos = 0x1, |
| 762 | kRegenCol = 0x2, |
| 763 | kRegenTex = 0x4, |
| 764 | kRegenGlyph = 0x8, |
| 765 | }; |
| 766 | |
| 767 | static void regen_positions(char* vertex, size_t vertexStride, SkScalar transX, SkScalar transY) { |
| 768 | SkPoint* point = reinterpret_cast<SkPoint*>(vertex); |
| 769 | for (int i = 0; i < 4; ++i) { |
| 770 | point->fX += transX; |
| 771 | point->fY += transY; |
| 772 | point = SkTAddOffset<SkPoint>(point, vertexStride); |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | static void regen_colors(char* vertex, size_t vertexStride, GrColor color) { |
| 777 | // This is a bit wonky, but sometimes we have LCD text, in which case we won't have color |
| 778 | // vertices, hence vertexStride - sizeof(SkIPoint16) |
| 779 | size_t colorOffset = vertexStride - sizeof(SkIPoint16) - sizeof(GrColor); |
| 780 | GrColor* vcolor = reinterpret_cast<GrColor*>(vertex + colorOffset); |
| 781 | for (int i = 0; i < 4; ++i) { |
| 782 | *vcolor = color; |
| 783 | vcolor = SkTAddOffset<GrColor>(vcolor, vertexStride); |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | static void regen_texcoords(char* vertex, size_t vertexStride, const GrGlyph* glyph, |
| 788 | bool useDistanceFields) { |
| 789 | // This is a bit wonky, but sometimes we have LCD text, in which case we won't have color |
| 790 | // vertices, hence vertexStride - sizeof(SkIPoint16) |
| 791 | size_t texCoordOffset = vertexStride - sizeof(SkIPoint16); |
| 792 | |
| 793 | uint16_t u0, v0, u1, v1; |
| 794 | SkASSERT(glyph); |
| 795 | int width = glyph->fBounds.width(); |
| 796 | int height = glyph->fBounds.height(); |
| 797 | |
| 798 | if (useDistanceFields) { |
| 799 | u0 = glyph->fAtlasLocation.fX + SK_DistanceFieldInset; |
| 800 | v0 = glyph->fAtlasLocation.fY + SK_DistanceFieldInset; |
| 801 | u1 = u0 + width - 2 * SK_DistanceFieldInset; |
| 802 | v1 = v0 + height - 2 * SK_DistanceFieldInset; |
| 803 | } else { |
| 804 | u0 = glyph->fAtlasLocation.fX; |
| 805 | v0 = glyph->fAtlasLocation.fY; |
| 806 | u1 = u0 + width; |
| 807 | v1 = v0 + height; |
| 808 | } |
| 809 | // We pack the 2bit page index in the low bit of the u and v texture coords |
| 810 | uint32_t pageIndex = glyph->pageIndex(); |
| 811 | SkASSERT(pageIndex < 4); |
| 812 | uint16_t uBit = (pageIndex >> 1) & 0x1; |
| 813 | uint16_t vBit = pageIndex & 0x1; |
| 814 | u0 <<= 1; |
| 815 | u0 |= uBit; |
| 816 | v0 <<= 1; |
| 817 | v0 |= vBit; |
| 818 | u1 <<= 1; |
| 819 | u1 |= uBit; |
| 820 | v1 <<= 1; |
| 821 | v1 |= vBit; |
| 822 | |
| 823 | uint16_t* textureCoords = reinterpret_cast<uint16_t*>(vertex + texCoordOffset); |
| 824 | textureCoords[0] = u0; |
| 825 | textureCoords[1] = v0; |
| 826 | textureCoords = SkTAddOffset<uint16_t>(textureCoords, vertexStride); |
| 827 | textureCoords[0] = u0; |
| 828 | textureCoords[1] = v1; |
| 829 | textureCoords = SkTAddOffset<uint16_t>(textureCoords, vertexStride); |
| 830 | textureCoords[0] = u1; |
| 831 | textureCoords[1] = v0; |
| 832 | textureCoords = SkTAddOffset<uint16_t>(textureCoords, vertexStride); |
| 833 | textureCoords[0] = u1; |
| 834 | textureCoords[1] = v1; |
| 835 | |
| 836 | #ifdef DISPLAY_PAGE_INDEX |
| 837 | // Enable this to visualize the page from which each glyph is being drawn. |
| 838 | // Green Red Magenta Cyan -> 0 1 2 3; Black -> error |
| 839 | GrColor hackColor; |
| 840 | switch (pageIndex) { |
| 841 | case 0: |
| 842 | hackColor = GrColorPackRGBA(0, 255, 0, 255); |
| 843 | break; |
| 844 | case 1: |
| 845 | hackColor = GrColorPackRGBA(255, 0, 0, 255);; |
| 846 | break; |
| 847 | case 2: |
| 848 | hackColor = GrColorPackRGBA(255, 0, 255, 255); |
| 849 | break; |
| 850 | case 3: |
| 851 | hackColor = GrColorPackRGBA(0, 255, 255, 255); |
| 852 | break; |
| 853 | default: |
| 854 | hackColor = GrColorPackRGBA(0, 0, 0, 255); |
| 855 | break; |
| 856 | } |
| 857 | regen_colors(vertex, vertexStride, hackColor); |
| 858 | #endif |
| 859 | } |
| 860 | |
| 861 | GrTextBlob::VertexRegenerator::VertexRegenerator(GrResourceProvider* resourceProvider, |
| 862 | GrTextBlob* blob, |
| 863 | GrTextBlob::SubRun* subRun, |
| 864 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y, |
| 865 | GrColor color, |
| 866 | GrDeferredUploadTarget* uploadTarget, |
| 867 | GrStrikeCache* grStrikeCache, |
| 868 | GrAtlasManager* fullAtlasManager) |
| 869 | : fResourceProvider(resourceProvider) |
| 870 | , fViewMatrix(viewMatrix) |
| 871 | , fBlob(blob) |
| 872 | , fUploadTarget(uploadTarget) |
| 873 | , fGrStrikeCache(grStrikeCache) |
| 874 | , fFullAtlasManager(fullAtlasManager) |
| 875 | , fSubRun(subRun) |
| 876 | , fColor(color) { |
| 877 | // Compute translation if any |
| 878 | fSubRun->computeTranslation(fViewMatrix, x, y, &fTransX, &fTransY); |
| 879 | |
| 880 | // Because the GrStrikeCache may evict the strike a blob depends on using for |
| 881 | // generating its texture coords, we have to track whether or not the strike has |
| 882 | // been abandoned. If it hasn't been abandoned, then we can use the GrGlyph*s as is |
| 883 | // otherwise we have to get the new strike, and use that to get the correct glyphs. |
| 884 | // Because we do not have the packed ids, and thus can't look up our glyphs in the |
| 885 | // new strike, we instead keep our ref to the old strike and use the packed ids from |
| 886 | // it. These ids will still be valid as long as we hold the ref. When we are done |
| 887 | // updating our cache of the GrGlyph*s, we drop our ref on the old strike |
| 888 | if (fSubRun->strike()->isAbandoned()) { |
| 889 | fRegenFlags |= kRegenGlyph; |
| 890 | fRegenFlags |= kRegenTex; |
| 891 | } |
| 892 | if (kARGB_GrMaskFormat != fSubRun->maskFormat() && fSubRun->color() != color) { |
| 893 | fRegenFlags |= kRegenCol; |
| 894 | } |
| 895 | if (0.f != fTransX || 0.f != fTransY) { |
| 896 | fRegenFlags |= kRegenPos; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | bool GrTextBlob::VertexRegenerator::doRegen(GrTextBlob::VertexRegenerator::Result* result, |
| 901 | bool regenPos, bool regenCol, bool regenTexCoords, |
| 902 | bool regenGlyphs) { |
| 903 | SkASSERT(!regenGlyphs || regenTexCoords); |
| 904 | if (regenTexCoords) { |
| 905 | fSubRun->resetBulkUseToken(); |
| 906 | |
| 907 | const SkStrikeSpec& strikeSpec = fSubRun->strikeSpec(); |
| 908 | |
| 909 | if (!fMetricsAndImages.isValid() |
| 910 | || fMetricsAndImages->descriptor() != strikeSpec.descriptor()) { |
| 911 | fMetricsAndImages.init(strikeSpec); |
| 912 | } |
| 913 | |
| 914 | if (regenGlyphs) { |
| 915 | // Take the glyphs from the old strike, and translate them a new strike. |
| 916 | sk_sp<GrTextStrike> newStrike = strikeSpec.findOrCreateGrStrike(fGrStrikeCache); |
| 917 | |
| 918 | // Start this batch at the start of the subRun plus any glyphs that were previously |
| 919 | // processed. |
| 920 | size_t glyphStart = fSubRun->glyphStartIndex() + fCurrGlyph; |
| 921 | SkSpan<GrGlyph*> glyphs{&(fBlob->fGlyphs[glyphStart]), |
| 922 | fSubRun->glyphCount() - fCurrGlyph}; |
| 923 | |
| 924 | // Convert old glyphs to newStrike. |
| 925 | for (auto& glyph : glyphs) { |
| 926 | SkPackedGlyphID id = glyph->fPackedID; |
| 927 | glyph = newStrike->getGlyph(id, fMetricsAndImages.get()); |
| 928 | SkASSERT(id == glyph->fPackedID); |
| 929 | } |
| 930 | |
| 931 | fSubRun->setStrike(newStrike); |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | sk_sp<GrTextStrike> grStrike = fSubRun->refStrike(); |
| 936 | bool hasW = fSubRun->hasW(); |
| 937 | auto vertexStride = GetVertexStride(fSubRun->maskFormat(), hasW); |
| 938 | char* currVertex = fBlob->fVertices + fSubRun->vertexStartIndex() + |
| 939 | fCurrGlyph * kVerticesPerGlyph * vertexStride; |
| 940 | result->fFirstVertex = currVertex; |
| 941 | |
| 942 | for (int glyphIdx = fCurrGlyph; glyphIdx < (int)fSubRun->glyphCount(); glyphIdx++) { |
| 943 | GrGlyph* glyph = nullptr; |
| 944 | if (regenTexCoords) { |
| 945 | size_t glyphOffset = glyphIdx + fSubRun->glyphStartIndex(); |
| 946 | glyph = fBlob->fGlyphs[glyphOffset]; |
| 947 | SkASSERT(glyph && glyph->fMaskFormat == fSubRun->maskFormat()); |
| 948 | |
| 949 | if (!fFullAtlasManager->hasGlyph(glyph)) { |
| 950 | GrDrawOpAtlas::ErrorCode code; |
| 951 | code = grStrike->addGlyphToAtlas(fResourceProvider, fUploadTarget, fGrStrikeCache, |
| 952 | fFullAtlasManager, glyph, |
| 953 | fMetricsAndImages.get(), fSubRun->maskFormat(), |
| 954 | fSubRun->needsTransform()); |
| 955 | if (GrDrawOpAtlas::ErrorCode::kError == code) { |
| 956 | // Something horrible has happened - drop the op |
| 957 | return false; |
| 958 | } |
| 959 | else if (GrDrawOpAtlas::ErrorCode::kTryAgain == code) { |
| 960 | fBrokenRun = glyphIdx > 0; |
| 961 | result->fFinished = false; |
| 962 | return true; |
| 963 | } |
| 964 | } |
| 965 | auto tokenTracker = fUploadTarget->tokenTracker(); |
| 966 | fFullAtlasManager->addGlyphToBulkAndSetUseToken(fSubRun->bulkUseToken(), glyph, |
| 967 | tokenTracker->nextDrawToken()); |
| 968 | } |
| 969 | |
| 970 | if (regenPos) { |
| 971 | regen_positions(currVertex, vertexStride, fTransX, fTransY); |
| 972 | } |
| 973 | if (regenCol) { |
| 974 | regen_colors(currVertex, vertexStride, fColor); |
| 975 | } |
| 976 | if (regenTexCoords) { |
| 977 | regen_texcoords(currVertex, vertexStride, glyph, fSubRun->drawAsDistanceFields()); |
| 978 | } |
| 979 | |
| 980 | currVertex += vertexStride * GrAtlasTextOp::kVerticesPerGlyph; |
| 981 | ++result->fGlyphsRegenerated; |
| 982 | ++fCurrGlyph; |
| 983 | } |
| 984 | |
| 985 | // We may have changed the color so update it here |
| 986 | fSubRun->setColor(fColor); |
| 987 | if (regenTexCoords) { |
| 988 | fSubRun->setAtlasGeneration(fBrokenRun |
| 989 | ? GrDrawOpAtlas::kInvalidAtlasGeneration |
| 990 | : fFullAtlasManager->atlasGeneration(fSubRun->maskFormat())); |
| 991 | } else { |
| 992 | // For the non-texCoords case we need to ensure that we update the associated use tokens |
| 993 | fFullAtlasManager->setUseTokenBulk(*fSubRun->bulkUseToken(), |
| 994 | fUploadTarget->tokenTracker()->nextDrawToken(), |
| 995 | fSubRun->maskFormat()); |
| 996 | } |
| 997 | return true; |
| 998 | } |
| 999 | |
| 1000 | bool GrTextBlob::VertexRegenerator::regenerate(GrTextBlob::VertexRegenerator::Result* result) { |
| 1001 | uint64_t currentAtlasGen = fFullAtlasManager->atlasGeneration(fSubRun->maskFormat()); |
| 1002 | // If regenerate() is called multiple times then the atlas gen may have changed. So we check |
| 1003 | // this each time. |
| 1004 | if (fSubRun->atlasGeneration() != currentAtlasGen) { |
| 1005 | fRegenFlags |= kRegenTex; |
| 1006 | } |
| 1007 | |
| 1008 | if (fRegenFlags) { |
| 1009 | return this->doRegen(result, |
| 1010 | fRegenFlags & kRegenPos, |
| 1011 | fRegenFlags & kRegenCol, |
| 1012 | fRegenFlags & kRegenTex, |
| 1013 | fRegenFlags & kRegenGlyph); |
| 1014 | } else { |
| 1015 | bool hasW = fSubRun->hasW(); |
| 1016 | auto vertexStride = GetVertexStride(fSubRun->maskFormat(), hasW); |
| 1017 | result->fFinished = true; |
| 1018 | result->fGlyphsRegenerated = fSubRun->glyphCount() - fCurrGlyph; |
| 1019 | result->fFirstVertex = fBlob->fVertices + fSubRun->vertexStartIndex() + |
| 1020 | fCurrGlyph * kVerticesPerGlyph * vertexStride; |
| 1021 | fCurrGlyph = fSubRun->glyphCount(); |
| 1022 | |
| 1023 | // set use tokens for all of the glyphs in our subrun. This is only valid if we |
| 1024 | // have a valid atlas generation |
| 1025 | fFullAtlasManager->setUseTokenBulk(*fSubRun->bulkUseToken(), |
| 1026 | fUploadTarget->tokenTracker()->nextDrawToken(), |
| 1027 | fSubRun->maskFormat()); |
| 1028 | return true; |
| 1029 | } |
| 1030 | SK_ABORT("Should not get here"); |
| 1031 | } |
| 1032 | |
| 1033 | |
| 1034 | |
| 1035 | |