Flutter Engine
The Flutter Engine
AtlasTextOp.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 skgpu_ganesh_AtlasTextOp_DEFINED
9#define skgpu_ganesh_AtlasTextOp_DEFINED
10
13#include "include/core/SkRect.h"
20#include "src/gpu/AtlasTypes.h"
30
31#include <cstddef>
32#include <cstdint>
33#include <utility>
34
35class GrDstProxyView;
38class GrOpFlushState;
39class GrPaint;
40class GrProgramInfo;
42class GrSurfaceProxy;
44class SkArenaAlloc;
45enum class GrXferBarrierFlags;
46struct GrShaderCaps;
47
48namespace sktext { namespace gpu { class AtlasSubRun; } }
49
50namespace skgpu::ganesh {
51
52class AtlasTextOp final : public GrMeshDrawOp {
53public:
55
56 ~AtlasTextOp() override {
57 for (const Geometry* g = fHead; g != nullptr;) {
58 const Geometry* next = g->fNext;
59 g->~Geometry();
60 g = next;
61 }
62 }
63
64 void* operator new(size_t s);
65 void operator delete(void* b) noexcept;
66 static void ClearCache();
67
68 struct Geometry {
70 const SkMatrix& drawMatrix,
71 SkPoint drawOrigin,
73 sk_sp<SkRefCnt>&& supportData,
74 const SkPMColor4f& color)
75 : fSubRun{subRun}
76 , fSupportDataKeepAlive{std::move(supportData)}
77 , fDrawMatrix{drawMatrix}
78 , fDrawOrigin{drawOrigin}
80 , fColor{color} {
82 }
83
84 static Geometry* Make(const sktext::gpu::AtlasSubRun& subRun,
85 const SkMatrix& drawMatrix,
86 SkPoint drawOrigin,
88 sk_sp<SkRefCnt>&& supportData,
89 const SkPMColor4f& color,
90 SkArenaAlloc* alloc);
91
92 void fillVertexData(void* dst, int offset, int count) const;
93
95
96 // Keep the TextBlob or Slug alive until the op is deleted.
98
101
102 // fClipRect is only used in the DirectMaskSubRun case to do geometric clipping.
103 // TransformedMaskSubRun, and SDFTSubRun don't use this field, and expect an empty rect.
105
106 // Color is updated after processor analysis if it was determined the shader resolves to
107 // a constant color that we then evaluate on the CPU.
108 // TODO: This can be made const once processor analysis is separated from op creation.
110 Geometry* fNext{nullptr};
111 };
112
113 const char* name() const override { return "AtlasTextOp"; }
114
115 void visitProxies(const GrVisitProxyFunc&) const override;
116
117 FixedFunctionFlags fixedFunctionFlags() const override;
118
120
121 enum class MaskType : uint32_t {
122 kGrayscaleCoverage,
123 kLCDCoverage,
124 kColorBitmap,
125#if !defined(SK_DISABLE_SDF_TEXT)
126 kAliasedDistanceField,
127 kGrayscaleDistanceField,
128 kLCDDistanceField,
129
130 kLast = kLCDDistanceField
131#else
132 kLast = kColorBitmap
133#endif
134 };
135 inline static constexpr int kMaskTypeCount = static_cast<int>(MaskType::kLast) + 1;
136
137private:
138 friend class GrOp; // for ctor
139
140 struct FlushInfo {
145 int fGlyphsToFlush = 0;
146 int fVertexOffset = 0;
147 int fNumDraws = 0;
148 };
149
150 AtlasTextOp(MaskType maskType,
151 bool needsTransform,
152 int glyphCount,
153 SkRect deviceRect,
154 Geometry* geo,
155 const GrColorInfo& dstColorInfo,
156 GrPaint&& paint);
157
158 AtlasTextOp(MaskType maskType,
159 bool needsTransform,
160 int glyphCount,
161 SkRect deviceRect,
162 SkColor luminanceColor,
163 bool useGammaCorrectDistanceTable,
164 uint32_t DFGPFlags,
165 Geometry* geo,
166 GrPaint&& paint);
167
168 GrProgramInfo* programInfo() override {
169 // TODO [PI]: implement
170 return nullptr;
171 }
172
173 void addGeometry(Geometry* geometry) {
174 *fTail = geometry;
175 // The geometry may have many entries. Find the end.
176 do {
177 fTail = &(*fTail)->fNext;
178 } while (*fTail != nullptr);
179 }
180
181 void onCreateProgramInfo(const GrCaps*,
183 const GrSurfaceProxyView& writeView,
184 bool usesMSAASurface,
186 const GrDstProxyView&,
187 GrXferBarrierFlags renderPassXferBarriers,
188 GrLoadOp colorLoadOp) override {
189 // We cannot surface the AtlasTextOp's programInfo at record time. As currently
190 // implemented, the GP is modified at flush time based on the number of pages in the
191 // atlas.
192 }
193
194 void onPrePrepareDraws(GrRecordingContext*,
195 const GrSurfaceProxyView& writeView,
197 const GrDstProxyView&,
198 GrXferBarrierFlags renderPassXferBarriers,
199 GrLoadOp colorLoadOp) override {
200 // TODO [PI]: implement
201 }
202
203 void onPrepareDraws(GrMeshDrawTarget*) override;
204 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
205
206#if defined(GR_TEST_UTILS)
207 SkString onDumpInfo() const override;
208#endif
209
210 skgpu::MaskFormat maskFormat() const {
211 switch (this->maskType()) {
217#if !defined(SK_DISABLE_SDF_TEXT)
221#endif
223 }
224 // SkUNREACHABLE;
226 }
227
228#if !defined(SK_DISABLE_SDF_TEXT)
229 bool usesDistanceFields() const {
230 return MaskType::kAliasedDistanceField == this->maskType() ||
231 MaskType::kGrayscaleDistanceField == this->maskType() ||
232 MaskType::kLCDDistanceField == this->maskType();
233 }
234
235 bool isLCD() const {
236 return MaskType::kLCDCoverage == this->maskType() ||
237 MaskType::kLCDDistanceField == this->maskType();
238 }
239#else
240 bool isLCD() const {
241 return MaskType::kLCDCoverage == this->maskType();
242 }
243#endif
244
245 inline void createDrawForGeneratedGlyphs(
246 GrMeshDrawTarget* target, FlushInfo* flushInfo) const;
247
248 MaskType maskType() const { return static_cast<MaskType>(fMaskType); }
249
250 CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override;
251
252#if !defined(SK_DISABLE_SDF_TEXT)
253 GrGeometryProcessor* setupDfProcessor(SkArenaAlloc*,
254 const GrShaderCaps&,
255 const SkMatrix& localMatrix,
256 const GrSurfaceProxyView* views,
257 unsigned int numActiveViews) const;
258#endif
259
260 GrProcessorSet fProcessors;
261 int fNumGlyphs; // Sum of glyphs in each geometry's subrun
262
263 // All combinable atlas ops have equal bit field values
264 uint32_t fDFGPFlags : 10; // Distance field properties
265 uint32_t fMaskType : 3; // MaskType
266 uint32_t fUsesLocalCoords : 1; // Filled in post processor analysis
267 uint32_t fNeedsGlyphTransform : 1;
268 uint32_t fHasPerspective : 1; // True if perspective affects draw
269 uint32_t fUseGammaCorrectDistanceTable : 1;
270 static_assert(kMaskTypeCount <= 8, "MaskType does not fit in 3 bits");
271#if !defined(SK_DISABLE_SDF_TEXT)
272 static_assert(kInvalid_DistanceFieldEffectFlag <= (1 << 9), "DFGP Flags do not fit in 10 bits");
273#endif
274
275 // Only needed for color emoji
276 sk_sp<GrColorSpaceXform> fColorSpaceXform;
277
278 // Only used for distance fields; per-channel luminance for LCD, or gamma-corrected luminance
279 // for single-channel distance fields.
280 const SkColor fLuminanceColor{0};
281
282 Geometry* fHead{nullptr};
283 Geometry** fTail{&fHead};
284
285 using INHERITED = GrMeshDrawOp;
286};
287
288} // namespace skgpu::ganesh
289
290#endif // skgpu_ganesh_AtlasTextOp_DEFINED
int count
Definition: FontMgrTest.cpp:50
@ kInvalid_DistanceFieldEffectFlag
#define DEFINE_OP_CLASS_ID
Definition: GrOp.h:64
GrClampType
Definition: GrTypesPriv.h:228
std::function< void(GrSurfaceProxy *, skgpu::Mipmapped)> GrVisitProxyFunc
Definition: GrTypesPriv.h:943
GrLoadOp
Definition: GrTypesPriv.h:155
GrXferBarrierFlags
static float next(float f)
#define SkASSERT(cond)
Definition: SkAssert.h:116
uint32_t SkColor
Definition: SkColor.h:37
GrGeometryProcessor * fGeometryProcessor
sk_sp< const GrBuffer > fIndexBuffer
int fVertexOffset
sk_sp< const GrBuffer > fVertexBuffer
const GrSurfaceProxy ** fPrimProcProxies
Definition: GrCaps.h:57
FixedFunctionFlags
Definition: GrDrawOp.h:104
GrMeshDrawOp(uint32_t classID)
Definition: GrOp.h:70
CombineResult
Definition: GrOp.h:99
DEFINE_OP_CLASS_ID ~AtlasTextOp() override
Definition: AtlasTextOp.h:56
const char * name() const override
Definition: AtlasTextOp.h:113
GrProcessorSet::Analysis finalize(const GrCaps &, const GrAppliedClip *, GrClampType) override
static constexpr int kMaskTypeCount
Definition: AtlasTextOp.h:135
FixedFunctionFlags fixedFunctionFlags() const override
void visitProxies(const GrVisitProxyFunc &) const override
const Paint & paint
Definition: color_source.cc:38
DlColor color
static bool b
struct MyStruct s
uint32_t * target
clipRect(r.rect, r.opAA.op(), r.opAA.aa())) template<> void Draw
dst
Definition: cp.py:12
MaskFormat
Definition: AtlasTypes.h:98
@ kA565
2-bytes per pixel, RGB represent 3-channel LCD coverage
@ kA8
1-byte per pixel
@ kARGB
4-bytes per pixel, color format
Definition: ref_ptr.h:256
SeparatedVector2 offset
Definition: SkRect.h:32
static Geometry * Make(const sktext::gpu::AtlasSubRun &subRun, const SkMatrix &drawMatrix, SkPoint drawOrigin, SkIRect clipRect, sk_sp< SkRefCnt > &&supportData, const SkPMColor4f &color, SkArenaAlloc *alloc)
void fillVertexData(void *dst, int offset, int count) const
Geometry(const sktext::gpu::AtlasSubRun &subRun, const SkMatrix &drawMatrix, SkPoint drawOrigin, SkIRect clipRect, sk_sp< SkRefCnt > &&supportData, const SkPMColor4f &color)
Definition: AtlasTextOp.h:69
const sktext::gpu::AtlasSubRun & fSubRun
Definition: AtlasTextOp.h:94
sk_sp< SkRefCnt > fSupportDataKeepAlive
Definition: AtlasTextOp.h:97