1 /* 2 * Copyright 2022 Google LLC 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 8 #ifndef GrGlyphVector_DEFINED 9 #define GrGlyphVector_DEFINED 10 11 #include "include/core/SkSpan.h" 12 #include "src/core/SkGlyph.h" 13 #include "src/core/SkGlyphBuffer.h" 14 #include "src/gpu/GrGlyph.h" 15 #include "src/gpu/GrMeshDrawTarget.h" 16 #include "src/gpu/GrSubRunAllocator.h" 17 #include "src/gpu/text/GrStrikeCache.h" 18 19 // -- GlyphVector ---------------------------------------------------------------------------------- 20 // GlyphVector provides a way to delay the lookup of GrGlyphs until the code is running on the 21 // GPU in single threaded mode. The GlyphVector is created in a multi-threaded environment, but 22 // the GrStrikeCache is only single threaded (and must be single threaded because of the atlas). 23 class GrGlyphVector { 24 public: 25 union Variant { 26 // Initially, filled with packed id, but changed to GrGlyph* in the onPrepare stage. 27 SkPackedGlyphID packedGlyphID; 28 GrGlyph* grGlyph; 29 // Add ctors to help SkArenaAlloc create arrays. Variant()30 Variant() : grGlyph{nullptr} {} Variant(SkPackedGlyphID id)31 Variant(SkPackedGlyphID id) : packedGlyphID{id} {} 32 }; 33 34 GrGlyphVector(sk_sp<SkStrike>&& strike, SkSpan<Variant> glyphs); 35 36 static GrGlyphVector Make( 37 sk_sp<SkStrike>&& strike, SkSpan<SkGlyphVariant> glyphs, GrSubRunAllocator* alloc); 38 SkSpan<const GrGlyph*> glyphs() const; 39 40 static std::optional<GrGlyphVector> MakeFromBuffer(SkReadBuffer& buffer, 41 GrSubRunAllocator* alloc); 42 void flatten(SkWriteBuffer& buffer); 43 44 // This doesn't need to include sizeof(GrGlyphVector) because this is embedded in each of 45 // the sub runs. unflattenSize()46 int unflattenSize() const { return GlyphVectorSize(fGlyphs.size()); } 47 48 void packedGlyphIDToGrGlyph(GrStrikeCache* cache); 49 50 std::tuple<bool, int> regenerateAtlas( 51 int begin, int end, 52 GrMaskFormat maskFormat, 53 int srcPadding, 54 GrMeshDrawTarget *, 55 bool bilerpPadding = false); 56 GlyphVectorSize(size_t count)57 static size_t GlyphVectorSize(size_t count) { 58 return sizeof(Variant) * count; 59 } 60 61 private: 62 friend class TestingPeer; 63 sk_sp<SkStrike> fStrike; 64 SkSpan<Variant> fGlyphs; 65 sk_sp<GrTextStrike> fGrStrike{nullptr}; 66 uint64_t fAtlasGeneration{GrDrawOpAtlas::kInvalidAtlasGeneration}; 67 GrDrawOpAtlas::BulkUseTokenUpdater fBulkUseToken; 68 }; 69 #endif // GrGlyphVector_DEFINED 70