Flutter Engine
The Flutter Engine
TextBlob.h
Go to the documentation of this file.
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
8#ifndef sktext_gpu_TextBlob_DEFINED
9#define sktext_gpu_TextBlob_DEFINED
10
22
23#include <cstddef>
24#include <cstdint>
25#include <tuple>
26
27class SkCanvas;
28struct SkPoint;
30
31namespace sktext {
32class GlyphRunList;
33class StrikeForGPUCacheInterface;
34}
35
36namespace sktext::gpu {
37class Slug;
38
39// -- TextBlob -----------------------------------------------------------------------------------
40// A TextBlob contains a fully processed SkTextBlob, suitable for nearly immediate drawing
41// on the GPU. These are initially created with valid positions and colors, but with invalid
42// texture coordinates.
43//
44// A TextBlob contains a number of SubRuns that are created in the blob's arena. Each SubRun
45// tracks its own glyph and position data.
46//
47// In these classes, I'm trying to follow the convention about matrices and origins.
48// * drawMatrix and drawOrigin - describes transformations for the current draw command.
49// * positionMatrix - is equal to drawMatrix * [drawOrigin-as-translation-matrix]
50// * initial Matrix - describes the combined initial matrix and origin the TextBlob was created
51// with.
52//
53//
54class TextBlob final : public SkRefCnt {
55public:
56 // Key is not used as part of a hash map, so the hash is never taken. It's only used in a
57 // list search using operator =().
58 struct Key {
59 static std::tuple<bool, Key> Make(const GlyphRunList& glyphRunList,
60 const SkPaint& paint,
61 const SkMatrix& drawMatrix,
62 const SkStrikeDeviceInfo& strikeDevice);
63 uint32_t fUniqueID;
64 // Color may affect the gamma of the mask we generate, but in a fairly limited way.
65 // Each color is assigned to on of a fixed number of buckets based on its
66 // luminance. For each luminance bucket there is a "canonical color" that
67 // represents the bucket. This functionality is currently only supported for A8
75 // Below here fields are of size 1 byte.
80
81 bool operator==(const Key& other) const;
82 };
83
85
86 // Make a TextBlob and its sub runs.
87 static sk_sp<TextBlob> Make(const sktext::GlyphRunList& glyphRunList,
88 const SkPaint& paint,
89 const SkMatrix& positionMatrix,
90 SkStrikeDeviceInfo strikeDeviceInfo,
91 StrikeForGPUCacheInterface* strikeCache);
92
95 int totalMemorySize,
96 SkColor initialLuminance);
97
98 ~TextBlob() override;
99
100 // Change memory management to handle the data after TextBlob, but in the same allocation
101 // of memory. Only allow placement new.
102 void operator delete(void* p);
103 void* operator new(size_t);
104 void* operator new(size_t, void* p);
105
106 const Key& key() { return fKey; }
107
108 void addKey(const Key& key);
109
110 bool canReuse(const SkPaint& paint, const SkMatrix& positionMatrix) const;
111
112 const Key& key() const;
113 size_t size() const { return SkTo<size_t>(fSize); }
114
115 void draw(SkCanvas*,
116 SkPoint drawOrigin,
117 const SkPaint& paint,
118 const AtlasDrawDelegate&);
119
120private:
121 friend class TextBlobTools;
122 // The allocator must come first because it needs to be destroyed last. Other fields of this
123 // structure may have pointers into it.
124 SubRunAllocator fAlloc;
125
126 SubRunContainerOwner fSubRuns;
127
128 // Overall size of this struct plus vertices and glyphs at the end.
129 const int fSize;
130
131 const SkColor fInitialLuminance;
132
133 Key fKey;
134};
135
137 const sktext::GlyphRunList& glyphRunList,
138 const SkPaint& paint,
139 SkStrikeDeviceInfo strikeDeviceInfo,
141} // namespace sktext::gpu
142#endif // sktext_gpu_TextBlob_DEFINED
uint32_t SkColor
Definition: SkColor.h:37
SkPixelGeometry
TextBlob(SubRunAllocator &&alloc, SubRunContainerOwner subRuns, int totalMemorySize, SkColor initialLuminance)
Definition: TextBlob.cpp:246
const Key & key()
Definition: TextBlob.h:106
bool canReuse(const SkPaint &paint, const SkMatrix &positionMatrix) const
Definition: TextBlob.cpp:219
size_t size() const
Definition: TextBlob.h:113
void addKey(const Key &key)
Definition: TextBlob.cpp:215
void draw(SkCanvas *, SkPoint drawOrigin, const SkPaint &paint, const AtlasDrawDelegate &)
Definition: TextBlob.cpp:239
static sk_sp< TextBlob > Make(const sktext::GlyphRunList &glyphRunList, const SkPaint &paint, const SkMatrix &positionMatrix, SkStrikeDeviceInfo strikeDeviceInfo, StrikeForGPUCacheInterface *strikeCache)
Definition: TextBlob.cpp:194
SK_DECLARE_INTERNAL_LLIST_INTERFACE(TextBlob)
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
std::unique_ptr< SubRunContainer, SubRunAllocator::Destroyer > SubRunContainerOwner
sk_sp< Slug > MakeSlug(const SkMatrix &drawMatrix, const sktext::GlyphRunList &glyphRunList, const SkPaint &paint, SkStrikeDeviceInfo strikeDeviceInfo, sktext::StrikeForGPUCacheInterface *strikeCache)
Definition: TextBlob.cpp:255
std::function< void(const sktext::gpu::AtlasSubRun *subRun, SkPoint drawOrigin, const SkPaint &paint, sk_sp< SkRefCnt > subRunStorage, sktext::gpu::RendererData)> AtlasDrawDelegate
SkPaint::Join fJoin
Definition: TextBlob.h:79
SkPixelGeometry fPixelGeometry
Definition: TextBlob.h:71
SkPaint::Style fStyle
Definition: TextBlob.h:78
uint32_t fScalerContextFlags
Definition: TextBlob.h:73
static std::tuple< bool, Key > Make(const GlyphRunList &glyphRunList, const SkPaint &paint, const SkMatrix &drawMatrix, const SkStrikeDeviceInfo &strikeDevice)
Definition: TextBlob.cpp:84
SkMaskFilterBase::BlurRec fBlurRec
Definition: TextBlob.h:72
bool operator==(const Key &other) const
Definition: TextBlob.cpp:152