Flutter Engine
The Flutter Engine
Namespaces | Typedefs | Functions
GrAtlasManager.cpp File Reference
#include "src/gpu/ganesh/text/GrAtlasManager.h"
#include "include/core/SkColorType.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 31 of file GrAtlasManager.cpp.

◆ MaskFormat

Definition at line 32 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 58 of file GrAtlasManager.cpp.

63 {
64 for (int y = 0; y < height; ++y) {
65 int rowWritesLeft = width;
66 const uint8_t* s = src;
67 INT_TYPE* d = dst;
68 while (rowWritesLeft > 0) {
69 unsigned mask = *s++;
70 for (int x = 7; x >= 0 && rowWritesLeft; --x, --rowWritesLeft) {
71 *d++ = (mask & (1 << x)) ? (INT_TYPE)(~0UL) : 0;
72 }
73 }
74 dst = reinterpret_cast<INT_TYPE*>(reinterpret_cast<intptr_t>(dst) + dstRowBytes);
75 src += srcRowBytes;
76 }
77}
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 79 of file GrAtlasManager.cpp.

80 {
81 const int width = glyph.width();
82 const int height = glyph.height();
83 const void* src = glyph.image();
84 SkASSERT(src != nullptr);
85
87 if (maskFormat == expectedMaskFormat) {
88 int srcRB = glyph.rowBytes();
89 // Notice this comparison is with the glyphs raw mask format, and not its MaskFormat.
90 if (glyph.maskFormat() != SkMask::kBW_Format) {
91 if (srcRB != dstRB) {
92 const int bbp = MaskFormatBytesPerPixel(expectedMaskFormat);
93 for (int y = 0; y < height; y++) {
94 memcpy(dst, src, width * bbp);
95 src = (const char*) src + srcRB;
96 dst = (char*) dst + dstRB;
97 }
98 } else {
99 memcpy(dst, src, dstRB * height);
100 }
101 } else {
102 // Handle 8-bit format by expanding the mask to the expected format.
103 const uint8_t* bits = reinterpret_cast<const uint8_t*>(src);
104 switch (expectedMaskFormat) {
105 case MaskFormat::kA8: {
106 uint8_t* bytes = reinterpret_cast<uint8_t*>(dst);
107 expand_bits(bytes, bits, width, height, dstRB, srcRB);
108 break;
109 }
110 case MaskFormat::kA565: {
111 uint16_t* rgb565 = reinterpret_cast<uint16_t*>(dst);
112 expand_bits(rgb565, bits, width, height, dstRB, srcRB);
113 break;
114 }
115 default:
116 SK_ABORT("Invalid MaskFormat");
117 }
118 }
119 } else if (maskFormat == MaskFormat::kA565 &&
120 expectedMaskFormat == MaskFormat::kARGB) {
121 // Convert if the glyph uses a 565 mask format since it is using LCD text rendering
122 // but the expected format is 8888 (will happen on macOS with Metal since that
123 // combination does not support 565).
124 static constexpr SkMasks masks{
125 {0b1111'1000'0000'0000, 11, 5}, // Red
126 {0b0000'0111'1110'0000, 5, 6}, // Green
127 {0b0000'0000'0001'1111, 0, 5}, // Blue
128 {0, 0, 0} // Alpha
129 };
130 constexpr int a565Bpp = MaskFormatBytesPerPixel(MaskFormat::kA565);
131 constexpr int argbBpp = MaskFormatBytesPerPixel(MaskFormat::kARGB);
132 constexpr bool kBGRAIsNative = kN32_SkColorType == kBGRA_8888_SkColorType;
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 color8888;
140 // On Windows (and possibly others), font data is stored as BGR.
141 // So we need to swizzle the data to reflect that.
142 if (kBGRAIsNative) {
143 color8888 = GrColorPackRGBA(masks.getBlue(color565),
144 masks.getGreen(color565),
145 masks.getRed(color565),
146 0xFF);
147 } else {
148 color8888 = GrColorPackRGBA(masks.getRed(color565),
149 masks.getGreen(color565),
150 masks.getBlue(color565),
151 0xFF);
152 }
153 memcpy(dst, &color8888, argbBpp);
154 src = (const char*)src + a565Bpp;
155 dst = (char*)dst + argbBpp;
156 }
157 dstRow += dstRB;
158 }
159 } else {
161 }
162}
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
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
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
MaskFormat
Definition: AtlasTypes.h:98
@ kBW_Format
1bit per pixel mask (e.g. monochrome)
Definition: SkMask.h:27