41#if defined(SK_GAMMA_APPLY_TO_A8)
62static thread_local void*
gCache =
nullptr;
63void* AtlasTextOp::operator
new(
size_t s) {
65 return std::exchange(
gCache,
nullptr);
68 return ::operator
new(
s);
71void AtlasTextOp::operator
delete(
void* bytes)
noexcept {
76 ::operator
delete(bytes);
84AtlasTextOp::AtlasTextOp(MaskType maskType,
93 , fNumGlyphs(glyphCount)
95 , fMaskType(static_cast<uint32_t>(maskType))
96 , fUsesLocalCoords(
false)
97 , fNeedsGlyphTransform(needsTransform)
98 , fHasPerspective(needsTransform && geo->fDrawMatrix.hasPerspective())
99 , fUseGammaCorrectDistanceTable(
false)
101 , fTail{&fHead->
fNext} {
111AtlasTextOp::AtlasTextOp(MaskType maskType,
116 bool useGammaCorrectDistanceTable,
122 , fNumGlyphs(glyphCount)
123 , fDFGPFlags(DFGPFlags)
124 , fMaskType(static_cast<uint32_t>(maskType))
125 , fUsesLocalCoords(
false)
126 , fNeedsGlyphTransform(needsTransform)
127 , fHasPerspective(needsTransform && geo->fDrawMatrix.hasPerspective())
128 , fUseGammaCorrectDistanceTable(useGammaCorrectDistanceTable)
129 , fLuminanceColor(luminanceColor)
131 , fTail{&fHead->
fNext} {
151 std::move(supportData),
164#if defined(GR_TEST_UTILS)
165SkString AtlasTextOp::onDumpInfo()
const {
168 for(Geometry* geom = fHead; geom !=
nullptr; geom = geom->fNext) {
169 str.
appendf(
"%d: Color: 0x%08x Trans: %.2f,%.2f\n",
171 geom->fColor.toBytes_RGBA(),
172 geom->fDrawOrigin.x(),
173 geom->fDrawOrigin.y());
176 str += fProcessors.dumpProcessors();
191 color.setToUnknown();
198 switch (this->maskType()) {
200#if !defined(SK_DISABLE_SDF_TEXT)
207#if !defined(SK_DISABLE_SDF_TEXT)
218 caps, clampType, &fHead->
fColor);
222 fUsesLocalCoords = analysis.usesLocalCoords();
227 auto resourceProvider =
target->resourceProvider();
242 unsigned int numActiveViews;
245 SkDebugf(
"Could not allocate backing texture for atlas\n");
251#if !defined(SK_DISABLE_SDF_TEXT)
256 auto primProcProxies =
target->allocPrimProcProxyPtrs(kMaxTextures);
257 for (
unsigned i = 0;
i < numActiveViews; ++
i) {
258 primProcProxies[
i] = views[
i].
proxy();
261 target->sampledProxyArray()->push_back(views[
i].proxy());
265 flushInfo.fPrimProcProxies = primProcProxies;
266 flushInfo.fIndexBuffer = resourceProvider->refNonAAQuadIndexBuffer();
268#if !defined(SK_DISABLE_SDF_TEXT)
269 if (this->usesDistanceFields()) {
270 flushInfo.fGeometryProcessor = this->setupDfProcessor(
target->allocator(),
271 *
target->caps().shaderCaps(),
272 localMatrix, views, numActiveViews);
282 false, fColorSpaceXform, views, numActiveViews, filter,
283 maskFormat, localMatrix, fHasPerspective);
286 const int vertexStride = (
int)flushInfo.fGeometryProcessor->vertexStride();
291 const int maxQuadsPerBuffer = kMaxVertexBytes / quadSize;
293 int allGlyphsCursor = 0;
294 const int allGlyphsEnd = fNumGlyphs;
299 auto resetVertexBuffer = [&] {
301 quadEnd =
std::min(maxQuadsPerBuffer, allGlyphsEnd - allGlyphsCursor);
303 vertices = (
char*)
target->makeVertexSpace(
306 &flushInfo.fVertexBuffer,
307 &flushInfo.fVertexOffset);
309 if (!vertices || !flushInfo.fVertexBuffer) {
310 SkDebugf(
"Could not allocate vertices\n");
316 if (!resetVertexBuffer()) {
320 for (
const Geometry* geo = fHead; geo !=
nullptr; geo = geo->fNext) {
322 SkASSERTF((
int) subRun.vertexStride(geo->fDrawMatrix) == vertexStride,
323 "subRun stride: %d vertex buffer stride: %d\n",
324 (
int)subRun.vertexStride(geo->fDrawMatrix), vertexStride);
332 return glyphs->regenerateAtlasForGanesh(
begin, end, maskFormat, padding,
target);
334 for (
int subRunCursor = 0; subRunCursor < subRunEnd;) {
337 int regenEnd = subRunCursor +
std::min(subRunEnd - subRunCursor, quadEnd - quadCursor);
345 geo->fillVertexData(vertices + quadCursor * quadSize, subRunCursor, glyphsRegenerated);
347 subRunCursor += glyphsRegenerated;
348 quadCursor += glyphsRegenerated;
349 allGlyphsCursor += glyphsRegenerated;
350 flushInfo.fGlyphsToFlush += glyphsRegenerated;
352 if (quadCursor == quadEnd || subRunCursor < subRunEnd) {
355 if (subRunCursor < subRunEnd) {
358 this->createDrawForGeneratedGlyphs(
target, &flushInfo);
359 if (quadCursor == quadEnd && allGlyphsCursor < allGlyphsEnd) {
362 if(!resetVertexBuffer()) {
373 std::move(fProcessors),
381 FlushInfo* flushInfo)
const {
382 if (!flushInfo->fGlyphsToFlush) {
386 auto atlasManager =
target->atlasManager();
391 unsigned int numActiveViews;
395 if (!views || 0 == numActiveViews) {
402 flushInfo->fPrimProcProxies[
i] = views[
i].
proxy();
405 target->sampledProxyArray()->push_back(views[
i].proxy());
407 for (
int d = 0;
d < flushInfo->fNumDraws; ++
d) {
408 flushInfo->fPrimProcProxies[
i]->ref();
411#if !defined(SK_DISABLE_SDF_TEXT)
412 if (this->usesDistanceFields()) {
428 int maxGlyphsPerDraw =
static_cast<int>(flushInfo->fIndexBuffer->size() /
sizeof(uint16_t) / 6);
432 flushInfo->fVertexOffset);
433 target->recordDraw(flushInfo->fGeometryProcessor,
mesh, 1, flushInfo->fPrimProcProxies,
436 flushInfo->fGlyphsToFlush = 0;
437 ++flushInfo->fNumDraws;
441 auto that = t->
cast<AtlasTextOp>();
443 if (fDFGPFlags != that->fDFGPFlags ||
444 fMaskType != that->fMaskType ||
445 fUsesLocalCoords != that->fUsesLocalCoords ||
446 fNeedsGlyphTransform != that->fNeedsGlyphTransform ||
447 fHasPerspective != that->fHasPerspective ||
448 fUseGammaCorrectDistanceTable != that->fUseGammaCorrectDistanceTable) {
453 if (fProcessors != that->fProcessors) {
457 if (fUsesLocalCoords) {
461 const SkMatrix& thatFirstMatrix = that->fHead->fDrawMatrix;
467#if !defined(SK_DISABLE_SDF_TEXT)
468 if (this->usesDistanceFields()) {
469 SkASSERT(that->usesDistanceFields());
470 if (fLuminanceColor != that->fLuminanceColor) {
477 fHead->
fColor != that->fHead->fColor) {
483 fNumGlyphs += that->fNumGlyphs;
486 this->addGeometry(that->fHead);
487 that->fHead =
nullptr;
491#if !defined(SK_DISABLE_SDF_TEXT)
496 unsigned int numActiveViews)
const {
501 float redCorrection = dfAdjustTable->getAdjustment(
SkColorGetR(fLuminanceColor),
502 fUseGammaCorrectDistanceTable);
503 float greenCorrection = dfAdjustTable->getAdjustment(
SkColorGetG(fLuminanceColor),
504 fUseGammaCorrectDistanceTable);
505 float blueCorrection = dfAdjustTable->getAdjustment(
SkColorGetB(fLuminanceColor),
506 fUseGammaCorrectDistanceTable);
509 redCorrection, greenCorrection, blueCorrection);
512 fDFGPFlags, localMatrix);
514#if defined(SK_GAMMA_APPLY_TO_A8)
515 float correction = 0;
518 correction = dfAdjustTable->getAdjustment(
lum, fUseGammaCorrectDistanceTable);
522 fDFGPFlags, localMatrix);
GrProcessorAnalysisCoverage
std::function< void(GrSurfaceProxy *, skgpu::Mipmapped)> GrVisitProxyFunc
#define SkASSERTF(cond, fmt,...)
#define SkColorGetR(color)
#define SkColorGetG(color)
#define SkColorGetB(color)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static bool ok(int result)
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
#define INHERITED(method,...)
#define ATRACE_ANDROID_FRAMEWORK_ALWAYS(fmt,...)
#define SK_GAMMA_EXPONENT
const GrSurfaceProxyView * getViews(skgpu::MaskFormat format, unsigned int *numActiveProxies)
static GrGeometryProcessor * Make(SkArenaAlloc *arena, const GrShaderCaps &caps, const SkPMColor4f &color, bool wideColor, sk_sp< GrColorSpaceXform > colorSpaceXform, const GrSurfaceProxyView *views, int numActiveViews, GrSamplerState p, skgpu::MaskFormat format, const SkMatrix &localMatrix, bool usesW)
static constexpr int kMaxTextures
static constexpr size_t kDefaultBufferSize
sk_sp< GrColorSpaceXform > refColorSpaceXformFromSRGB() const
static GrGeometryProcessor * Make(SkArenaAlloc *arena, const GrShaderCaps &caps, const GrSurfaceProxyView *views, int numActiveViews, GrSamplerState params, uint32_t flags, const SkMatrix &localMatrixIfUsesLocalCoords)
static constexpr int kMaxTextures
static GrGeometryProcessor * Make(SkArenaAlloc *arena, const GrShaderCaps &caps, const GrSurfaceProxyView *views, int numActiveViews, GrSamplerState params, DistanceAdjust distanceAdjust, uint32_t flags, const SkMatrix &localMatrixIfUsesLocalCoords)
static constexpr int kMaxTextures
int numTextureSamplers() const
void executeDrawsAndUploadsForMeshDrawOp(const GrOp *op, const SkRect &chainBounds, const GrPipeline *, const GrUserStencilSettings *)
void setBounds(const SkRect &newBounds, HasAABloat aabloat, IsHairline zeroArea)
void visitProxies(const GrVisitProxyFunc &) const
Analysis finalize(const GrProcessorAnalysisColor &, const GrProcessorAnalysisCoverage, const GrAppliedClip *, const GrUserStencilSettings *, const GrCaps &, GrClampType, SkPMColor4f *inputColorOverride)
static const GrPipeline * CreatePipeline(const GrCaps *, SkArenaAlloc *, skgpu::Swizzle writeViewSwizzle, GrAppliedClip &&, const GrDstProxyView &, GrProcessorSet &&, GrPipeline::InputFlags pipelineFlags)
GrSurfaceProxy * proxy() const
static U8CPU computeLuminance(SkScalar gamma, SkColor c)
static bool CheapEqual(const SkMatrix &a, const SkMatrix &b)
bool invert(SkMatrix *inverse) const
static const SkMatrix & I()
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
GrProcessorSet::Analysis finalize(const GrCaps &, const GrAppliedClip *, GrClampType) override
FixedFunctionFlags fixedFunctionFlags() const override
void visitProxies(const GrVisitProxyFunc &) const override
@ kGrayscaleDistanceField
virtual std::tuple< bool, int > regenerateAtlas(int begin, int end, RegenerateAtlasDelegate) const =0
virtual int glyphCount() const =0
static const DistanceFieldAdjustTable * Get()
static const char * begin(const StringSlice &s)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
static float lum(float r, float g, float b)
static float min(float r, float g, float b)
clipRect(r.rect, r.opAA.op(), r.opAA.aa())) template<> void Draw
static constexpr int kVerticesPerGlyph
static constexpr int kIndicesPerGlyph
static thread_local void * gCache
static DistanceAdjust Make(SkScalar r, SkScalar g, SkScalar b)
static const GrUserStencilSettings & kUnused
uint32_t toBytes_RGBA() const
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
const SkMatrix fDrawMatrix
const sktext::gpu::AtlasSubRun & fSubRun
const SkPoint fDrawOrigin