36 size_t maxTextureBytes,
38 bool supportBilerpAtlas)
39 : fAllowMultitexturing{allowMultitexturing}
40 , fSupportBilerpAtlas{supportBilerpAtlas}
41 , fProxyProvider{proxyProvider}
42 , fCaps{fProxyProvider->refCaps()}
43 , fAtlasConfig{fCaps->maxTextureSize(), maxTextureBytes} { }
49 fAtlases[i] =
nullptr;
58template <
typename INT_TYPE>
66 int rowWritesLeft =
width;
67 const uint8_t*
s = src;
69 while (rowWritesLeft > 0) {
71 for (
int x = 7;
x >= 0 && rowWritesLeft; --
x, --rowWritesLeft) {
72 *
d++ = (mask & (1 <<
x)) ? (INT_TYPE)(~0UL) : 0;
75 dst =
reinterpret_cast<INT_TYPE*
>(
reinterpret_cast<intptr_t
>(dst) + dstRowBytes);
84 const void* src = glyph.
image();
88 if (maskFormat == expectedMaskFormat) {
93 const int bbp = MaskFormatBytesPerPixel(expectedMaskFormat);
95 memcpy(dst, src,
width * bbp);
96 src = (
const char*) src + srcRB;
97 dst = (
char*) dst + dstRB;
100 memcpy(dst, src, dstRB *
height);
104 const uint8_t* bits =
reinterpret_cast<const uint8_t*
>(src);
105 switch (expectedMaskFormat) {
106 case MaskFormat::kA8: {
107 uint8_t* bytes =
reinterpret_cast<uint8_t*
>(dst);
111 case MaskFormat::kA565: {
112 uint16_t*
rgb565 =
reinterpret_cast<uint16_t*
>(dst);
120 }
else if (maskFormat == MaskFormat::kA565 &&
121 expectedMaskFormat == MaskFormat::kARGB) {
125 static constexpr SkMasks masks{
126 {0b1111'1000'0000'0000, 11, 5},
127 {0b0000'0111'1110'0000, 5, 6},
128 {0b0000'0000'0001'1111, 0, 5},
131 constexpr int a565Bpp = MaskFormatBytesPerPixel(MaskFormat::kA565);
132 constexpr int argbBpp = MaskFormatBytesPerPixel(MaskFormat::kARGB);
133 char* dstRow = (
char*)dst;
137 uint16_t color565 = 0;
138 memcpy(&color565, src, a565Bpp);
140 masks.getGreen(color565),
141 masks.getBlue(color565),
143 memcpy(dst, &colorRGBA, argbBpp);
144 src = (
const char*)src + a565Bpp;
145 dst = (
char*)dst + argbBpp;
160#if !defined(SK_DISABLE_SDF_TEXT)
166 if (skGlyph.
image() ==
nullptr) {
172 MaskFormat expectedMaskFormat = this->resolveMaskFormat(glyphFormat);
173 int bytesPerPixel = MaskFormatBytesPerPixel(expectedMaskFormat);
176 switch (srcPadding) {
180 if (fSupportBilerpAtlas) {
190#if !defined(SK_DISABLE_SDF_TEXT)
204 const int width = skGlyph.
width() + 2*padding;
206 int rowBytes =
width * bytesPerPixel;
207 size_t size =
height * rowBytes;
211 void* dataPtr = storage.
get();
215 dataPtr = (
char*)(dataPtr) + rowBytes + bytesPerPixel;
220 auto errorCode = this->
addToAtlas(resourceProvider,
255 int index = MaskFormatToAtlasIndex(
format);
256 if (fAtlases[index] ==
nullptr) {
271 fAllowMultitexturing,
274 if (!fAtlases[index]) {
285std::tuple<bool, int> GlyphVector::regenerateAtlasForGanesh(
294 if (fAtlasGeneration != currentAtlasGen) {
297 fBulkUseUpdater.
reset();
304 int glyphsPlacedInAtlas = 0;
306 for (
const Variant& variant :
glyphs) {
307 Glyph* gpuGlyph = variant.glyph;
310 if (!atlasManager->
hasGlyph(maskFormat, gpuGlyph)) {
313 skGlyph, gpuGlyph, srcPadding,
target->resourceProvider(), uploadTarget);
320 &fBulkUseUpdater, maskFormat, gpuGlyph,
321 tokenTracker->nextDrawToken());
322 glyphsPlacedInAtlas++;
326 if (success &&
begin + glyphsPlacedInAtlas ==
SkCount(fGlyphs)) {
332 return {success, glyphsPlacedInAtlas};
static void get_packed_glyph_image(const SkGlyph &glyph, int dstRB, MaskFormat expectedMaskFormat, void *dst)
static void expand_bits(INT_TYPE *dst, const uint8_t *src, int width, int height, int dstRowBytes, int srcRowBytes)
static GrColor GrColorPackRGBA(unsigned r, unsigned g, unsigned b, unsigned a)
static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct)
static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct)
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
static const uint16_t rgb565[kNumPixels]
#define SK_ABORT(message,...)
#define SK_DistanceFieldInset
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static void sk_bzero(void *buffer, size_t size)
constexpr int SkCount(const Container &c)
Type::kYUV Type::kRGBA() int(0.7 *637)
void addGlyphToBulkAndSetUseToken(skgpu::BulkUsePlotUpdater *, skgpu::MaskFormat, sktext::gpu::Glyph *, skgpu::AtlasToken)
~GrAtlasManager() override
void setUseTokenBulk(const skgpu::BulkUsePlotUpdater &updater, skgpu::AtlasToken token, skgpu::MaskFormat format)
uint64_t atlasGeneration(skgpu::MaskFormat format) const
bool hasGlyph(skgpu::MaskFormat, sktext::gpu::Glyph *)
GrDrawOpAtlas::ErrorCode addGlyphToAtlas(const SkGlyph &, sktext::gpu::Glyph *, int srcPadding, GrResourceProvider *, GrDeferredUploadTarget *)
GrAtlasManager(GrProxyProvider *, size_t maxTextureBytes, GrDrawOpAtlas::AllowMultitexturing, bool supportBilerpAtlas)
GrDrawOpAtlas::ErrorCode addToAtlas(GrResourceProvider *, GrDeferredUploadTarget *, skgpu::MaskFormat, int width, int height, const void *image, skgpu::AtlasLocator *)
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
virtual const skgpu::TokenTracker * tokenTracker()=0
SkISize atlasDimensions(skgpu::MaskFormat type) const
SkISize plotDimensions(skgpu::MaskFormat type) const
static std::unique_ptr< GrDrawOpAtlas > Make(GrProxyProvider *proxyProvider, const GrBackendFormat &format, SkColorType ct, size_t bpp, int width, int height, int plotWidth, int plotHeight, skgpu::AtlasGenerationCounter *generationCounter, AllowMultitexturing allowMultitexturing, skgpu::PlotEvictionCallback *evictor, std::string_view label)
void setLastUseToken(const skgpu::AtlasLocator &atlasLocator, skgpu::AtlasToken token)
bool hasID(const skgpu::PlotLocator &plotLocator)
ErrorCode addToAtlas(GrResourceProvider *, GrDeferredUploadTarget *, int width, int height, const void *image, skgpu::AtlasLocator *)
virtual sktext::gpu::StrikeCache * strikeCache() const =0
SkMask::Format maskFormat() const
const void * image() const
void insetSrc(int padding)
PlotLocator plotLocator() const
bool add(const skgpu::AtlasLocator &atlasLocator)
AtlasToken nextDrawToken() const
SkSpan< const Glyph * > glyphs() const
void packedGlyphIDToGlyph(StrikeCache *cache)
skgpu::AtlasLocator fAtlasLocator
static skgpu::MaskFormat FormatFromSkGlyph(SkMask::Format format)
const SkPackedGlyphID fPackedID
static const char * begin(const StringSlice &s)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
uint32_t uint32_t * format
static const int kMaskFormatCount
constexpr int32_t width() const
constexpr int32_t height() const
@ kBW_Format
1bit per pixel mask (e.g. monochrome)