Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Namespaces | Typedefs | Functions
GrAtlasManager.cpp File Reference
#include "src/gpu/ganesh/text/GrAtlasManager.h"
#include "include/core/SkSize.h"
#include "include/core/SkSpan.h"
#include "include/private/base/SkMalloc.h"
#include "include/private/base/SkTLogic.h"
#include "src/base/SkAutoMalloc.h"
#include "src/core/SkDistanceFieldGen.h"
#include "src/core/SkGlyph.h"
#include "src/core/SkMask.h"
#include "src/core/SkMasks.h"
#include "src/core/SkStrikeSpec.h"
#include "src/gpu/ganesh/GrColor.h"
#include "src/gpu/ganesh/GrDeferredUpload.h"
#include "src/gpu/ganesh/GrMeshDrawTarget.h"
#include "src/text/gpu/Glyph.h"
#include "src/text/gpu/GlyphVector.h"
#include "src/text/gpu/StrikeCache.h"
#include <cstring>
#include <tuple>

Go to the source code of this file.

Namespaces

namespace  sktext
 
namespace  sktext::gpu
 

Typedefs

using Glyph = sktext::gpu::Glyph
 
using MaskFormat = skgpu::MaskFormat
 

Functions

template<typename INT_TYPE >
static void expand_bits (INT_TYPE *dst, const uint8_t *src, int width, int height, int dstRowBytes, int srcRowBytes)
 
static void get_packed_glyph_image (const SkGlyph &glyph, int dstRB, MaskFormat expectedMaskFormat, void *dst)
 

Typedef Documentation

◆ Glyph

Definition at line 32 of file GrAtlasManager.cpp.

◆ MaskFormat

Definition at line 33 of file GrAtlasManager.cpp.

Function Documentation

◆ expand_bits()

template<typename INT_TYPE >
static void expand_bits ( INT_TYPE *  dst,
const uint8_t *  src,
int  width,
int  height,
int  dstRowBytes,
int  srcRowBytes 
)
static

Definition at line 59 of file GrAtlasManager.cpp.

64 {
65 for (int y = 0; y < height; ++y) {
66 int rowWritesLeft = width;
67 const uint8_t* s = src;
68 INT_TYPE* d = dst;
69 while (rowWritesLeft > 0) {
70 unsigned mask = *s++;
71 for (int x = 7; x >= 0 && rowWritesLeft; --x, --rowWritesLeft) {
72 *d++ = (mask & (1 << x)) ? (INT_TYPE)(~0UL) : 0;
73 }
74 }
75 dst = reinterpret_cast<INT_TYPE*>(reinterpret_cast<intptr_t>(dst) + dstRowBytes);
76 src += srcRowBytes;
77 }
78}
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
struct MyStruct s
double y
double x
dst
Definition cp.py:12
int32_t height
int32_t width

◆ get_packed_glyph_image()

static void get_packed_glyph_image ( const SkGlyph glyph,
int  dstRB,
MaskFormat  expectedMaskFormat,
void *  dst 
)
static

Definition at line 80 of file GrAtlasManager.cpp.

81 {
82 const int width = glyph.width();
83 const int height = glyph.height();
84 const void* src = glyph.image();
85 SkASSERT(src != nullptr);
86
88 if (maskFormat == expectedMaskFormat) {
89 int srcRB = glyph.rowBytes();
90 // Notice this comparison is with the glyphs raw mask format, and not its MaskFormat.
91 if (glyph.maskFormat() != SkMask::kBW_Format) {
92 if (srcRB != dstRB) {
93 const int bbp = MaskFormatBytesPerPixel(expectedMaskFormat);
94 for (int y = 0; y < height; y++) {
95 memcpy(dst, src, width * bbp);
96 src = (const char*) src + srcRB;
97 dst = (char*) dst + dstRB;
98 }
99 } else {
100 memcpy(dst, src, dstRB * height);
101 }
102 } else {
103 // Handle 8-bit format by expanding the mask to the expected format.
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);
108 expand_bits(bytes, bits, width, height, dstRB, srcRB);
109 break;
110 }
111 case MaskFormat::kA565: {
112 uint16_t* rgb565 = reinterpret_cast<uint16_t*>(dst);
113 expand_bits(rgb565, bits, width, height, dstRB, srcRB);
114 break;
115 }
116 default:
117 SK_ABORT("Invalid MaskFormat");
118 }
119 }
120 } else if (maskFormat == MaskFormat::kA565 &&
121 expectedMaskFormat == MaskFormat::kARGB) {
122 // Convert if the glyph uses a 565 mask format since it is using LCD text rendering
123 // but the expected format is 8888 (will happen on macOS with Metal since that
124 // combination does not support 565).
125 static constexpr SkMasks masks{
126 {0b1111'1000'0000'0000, 11, 5}, // Red
127 {0b0000'0111'1110'0000, 5, 6}, // Green
128 {0b0000'0000'0001'1111, 0, 5}, // Blue
129 {0, 0, 0} // Alpha
130 };
131 constexpr int a565Bpp = MaskFormatBytesPerPixel(MaskFormat::kA565);
132 constexpr int argbBpp = MaskFormatBytesPerPixel(MaskFormat::kARGB);
133 char* dstRow = (char*)dst;
134 for (int y = 0; y < height; y++) {
135 dst = dstRow;
136 for (int x = 0; x < width; x++) {
137 uint16_t color565 = 0;
138 memcpy(&color565, src, a565Bpp);
139 uint32_t colorRGBA = GrColorPackRGBA(masks.getRed(color565),
140 masks.getGreen(color565),
141 masks.getBlue(color565),
142 0xFF);
143 memcpy(dst, &colorRGBA, argbBpp);
144 src = (const char*)src + a565Bpp;
145 dst = (char*)dst + argbBpp;
146 }
147 dstRow += dstRB;
148 }
149 } else {
151 }
152}
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)
Definition GrColor.h:46
static const uint16_t rgb565[kNumPixels]
#define SkUNREACHABLE
Definition SkAssert.h:135
#define SK_ABORT(message,...)
Definition SkAssert.h:70
#define SkASSERT(cond)
Definition SkAssert.h:116
size_t rowBytes() const
Definition SkGlyph.cpp:233
SkMask::Format maskFormat() const
Definition SkGlyph.h:500
int height() const
Definition SkGlyph.h:513
int width() const
Definition SkGlyph.h:512
const void * image() const
Definition SkGlyph.h:465
static skgpu::MaskFormat FormatFromSkGlyph(SkMask::Format format)
Definition Glyph.h:19
constexpr int MaskFormatBytesPerPixel(MaskFormat format)
Definition AtlasTypes.h:110
@ kBW_Format
1bit per pixel mask (e.g. monochrome)
Definition SkMask.h:27