Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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,
72 SkIRect clipRect,
73 sk_sp<SkRefCnt>&& supportData,
74 const SkPMColor4f& color)
75 : fSubRun{subRun}
76 , fSupportDataKeepAlive{std::move(supportData)}
77 , fDrawMatrix{drawMatrix}
78 , fDrawOrigin{drawOrigin}
79 , fClipRect{clipRect}
80 , fColor{color} {
82 }
83
84 static Geometry* Make(const sktext::gpu::AtlasSubRun& subRun,
85 const SkMatrix& drawMatrix,
86 SkPoint drawOrigin,
87 SkIRect clipRect,
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 {
125#if !defined(SK_DISABLE_SDF_TEXT)
130
132#else
134#endif
135 };
136 inline static constexpr int kMaskTypeCount = static_cast<int>(MaskType::kLast) + 1;
137
138private:
139 friend class GrOp; // for ctor
140
141 struct FlushInfo {
142 sk_sp<const GrBuffer> fVertexBuffer;
143 sk_sp<const GrBuffer> fIndexBuffer;
146 int fGlyphsToFlush = 0;
147 int fVertexOffset = 0;
148 int fNumDraws = 0;
149 };
150
151 AtlasTextOp(MaskType maskType,
152 bool needsTransform,
153 int glyphCount,
154 SkRect deviceRect,
155 Geometry* geo,
156 const GrColorInfo& dstColorInfo,
157 GrPaint&& paint);
158
159 AtlasTextOp(MaskType maskType,
160 bool needsTransform,
161 int glyphCount,
162 SkRect deviceRect,
163 SkColor luminanceColor,
164 bool useGammaCorrectDistanceTable,
165 uint32_t DFGPFlags,
166 Geometry* geo,
167 GrPaint&& paint);
168
170 // TODO [PI]: implement
171 return nullptr;
172 }
173
174 void addGeometry(Geometry* geometry) {
175 *fTail = geometry;
176 // The geometry may have many entries. Find the end.
177 do {
178 fTail = &(*fTail)->fNext;
179 } while (*fTail != nullptr);
180 }
181
184 const GrSurfaceProxyView& writeView,
185 bool usesMSAASurface,
187 const GrDstProxyView&,
188 GrXferBarrierFlags renderPassXferBarriers,
189 GrLoadOp colorLoadOp) override {
190 // We cannot surface the AtlasTextOp's programInfo at record time. As currently
191 // implemented, the GP is modified at flush time based on the number of pages in the
192 // atlas.
193 }
194
196 const GrSurfaceProxyView& writeView,
198 const GrDstProxyView&,
199 GrXferBarrierFlags renderPassXferBarriers,
200 GrLoadOp colorLoadOp) override {
201 // TODO [PI]: implement
202 }
203
204 void onPrepareDraws(GrMeshDrawTarget*) override;
205 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
206
207#if defined(GR_TEST_UTILS)
208 SkString onDumpInfo() const override;
209#endif
210
211 skgpu::MaskFormat maskFormat() const {
212 switch (this->maskType()) {
214 return skgpu::MaskFormat::kA565;
216 return skgpu::MaskFormat::kARGB;
218#if !defined(SK_DISABLE_SDF_TEXT)
223#endif
224 return skgpu::MaskFormat::kA8;
225 }
226 // SkUNREACHABLE;
227 return skgpu::MaskFormat::kA8;
228 }
229
230#if !defined(SK_DISABLE_SDF_TEXT)
231 bool usesDistanceFields() const {
232 return MaskType::kAliasedDistanceField == this->maskType() ||
233 MaskType::kGrayscaleDistanceField == this->maskType() ||
234 MaskType::kLCDDistanceField == this->maskType() ||
235 MaskType::kLCDBGRDistanceField == this->maskType();
236 }
237
238 bool isLCD() const {
239 return MaskType::kLCDCoverage == this->maskType() ||
240 MaskType::kLCDDistanceField == this->maskType() ||
241 MaskType::kLCDBGRDistanceField == this->maskType();
242 }
243#else
244 bool isLCD() const {
245 return MaskType::kLCDCoverage == this->maskType();
246 }
247#endif
248
249 inline void createDrawForGeneratedGlyphs(
250 GrMeshDrawTarget* target, FlushInfo* flushInfo) const;
251
252 MaskType maskType() const { return static_cast<MaskType>(fMaskType); }
253
254 CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override;
255
256#if !defined(SK_DISABLE_SDF_TEXT)
257 GrGeometryProcessor* setupDfProcessor(SkArenaAlloc*,
258 const GrShaderCaps&,
259 const SkMatrix& localMatrix,
260 const GrSurfaceProxyView* views,
261 unsigned int numActiveViews) const;
262#endif
263
264 GrProcessorSet fProcessors;
265 int fNumGlyphs; // Sum of glyphs in each geometry's subrun
266
267 // All combinable atlas ops have equal bit field values
268 uint32_t fDFGPFlags : 10; // Distance field properties
269 uint32_t fMaskType : 3; // MaskType
270 uint32_t fUsesLocalCoords : 1; // Filled in post processor analysis
271 uint32_t fNeedsGlyphTransform : 1;
272 uint32_t fHasPerspective : 1; // True if perspective affects draw
273 uint32_t fUseGammaCorrectDistanceTable : 1;
274 static_assert(kMaskTypeCount <= 8, "MaskType does not fit in 3 bits");
275#if !defined(SK_DISABLE_SDF_TEXT)
276 static_assert(kInvalid_DistanceFieldEffectFlag <= (1 << 9), "DFGP Flags do not fit in 10 bits");
277#endif
278
279 // Only needed for color emoji
280 sk_sp<GrColorSpaceXform> fColorSpaceXform;
281
282 // Only used for distance fields; per-channel luminance for LCD, or gamma-corrected luminance
283 // for single-channel distance fields.
284 const SkColor fLuminanceColor{0};
285
286 Geometry* fHead{nullptr};
287 Geometry** fTail{&fHead};
288
289 using INHERITED = GrMeshDrawOp;
290};
291
292} // namespace skgpu::ganesh
293
294#endif // skgpu_ganesh_AtlasTextOp_DEFINED
int count
@ kInvalid_DistanceFieldEffectFlag
#define DEFINE_OP_CLASS_ID
Definition GrOp.h:64
GrClampType
std::function< void(GrSurfaceProxy *, skgpu::Mipmapped)> GrVisitProxyFunc
GrLoadOp
GrXferBarrierFlags
SkColor4f color
static float next(float f)
#define SkASSERT(cond)
Definition SkAssert.h:116
uint32_t SkColor
Definition SkColor.h:37
GrGeometryProcessor * fGeometryProcessor
int fVertexOffset
const GrSurfaceProxy ** fPrimProcProxies
FixedFunctionFlags
Definition GrDrawOp.h:104
Definition GrOp.h:70
CombineResult
Definition GrOp.h:99
CombineResult onCombineIfPossible(GrOp *t, SkArenaAlloc *, const GrCaps &caps) override
void onPrePrepareDraws(GrRecordingContext *, const GrSurfaceProxyView &writeView, GrAppliedClip *, const GrDstProxyView &, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp) override
GrProgramInfo * programInfo() override
void onPrepareDraws(GrMeshDrawTarget *) override
DEFINE_OP_CLASS_ID ~AtlasTextOp() override
Definition AtlasTextOp.h:56
void onCreateProgramInfo(const GrCaps *, SkArenaAlloc *, const GrSurfaceProxyView &writeView, bool usesMSAASurface, GrAppliedClip &&, const GrDstProxyView &, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp) override
const char * name() const override
GrProcessorSet::Analysis finalize(const GrCaps &, const GrAppliedClip *, GrClampType) override
static constexpr int kMaskTypeCount
FixedFunctionFlags fixedFunctionFlags() const override
void visitProxies(const GrVisitProxyFunc &) const override
void onExecute(GrOpFlushState *, const SkRect &chainBounds) override
const Paint & paint
static bool b
struct MyStruct s
uint32_t * target
Definition ref_ptr.h:256
Point offset
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