@@ -74,21 +74,20 @@ static void expand_bits(INT_TYPE* dst,
7474 }
7575}
7676
77- static bool get_packed_glyph_image (const SkGlyph* glyph, int width,
77+ static void get_packed_glyph_image (const SkGlyph* glyph, int width,
7878 int height, int dstRB, GrMaskFormat expectedMaskFormat,
7979 void * dst, const SkMasks& masks) {
8080 SkASSERT (glyph->width () == width);
8181 SkASSERT (glyph->height () == height);
82+
8283 const void * src = glyph->image ();
83- if (src == nullptr ) {
84- return false ;
85- }
84+ SkASSERT (src != nullptr );
8685
87- // Convert if the glyph uses a 565 mask format since it is using LCD text rendering but the
88- // expected format is 8888 (will happen on macOS with Metal since that combination does not
89- // support 565).
9086 if (kA565_GrMaskFormat == GrGlyph::FormatFromSkGlyph (glyph->maskFormat ()) &&
9187 kARGB_GrMaskFormat == expectedMaskFormat) {
88+ // Convert if the glyph uses a 565 mask format since it is using LCD text rendering but the
89+ // expected format is 8888 (will happen on macOS with Metal since that combination does not
90+ // support 565).
9291 const int a565Bpp = GrMaskFormatBytesPerPixel (kA565_GrMaskFormat );
9392 const int argbBpp = GrMaskFormatBytesPerPixel (kARGB_GrMaskFormat );
9493 for (int y = 0 ; y < height; y++) {
@@ -104,53 +103,48 @@ static bool get_packed_glyph_image(const SkGlyph* glyph, int width,
104103 dst = (char *)dst + argbBpp;
105104 }
106105 }
107- return true ;
108- }
109-
110- // crbug:510931
111- // Retrieving the image from the cache can actually change the mask format. This case is very
112- // uncommon so for now we just draw a clear box for these glyphs.
113- if (GrGlyph::FormatFromSkGlyph (glyph->maskFormat ()) != expectedMaskFormat) {
106+ } else if (GrGlyph::FormatFromSkGlyph (glyph->maskFormat ()) != expectedMaskFormat) {
107+ // crbug:510931
108+ // Retrieving the image from the cache can actually change the mask format. This case is
109+ // very uncommon so for now we just draw a clear box for these glyphs.
114110 const int bpp = GrMaskFormatBytesPerPixel (expectedMaskFormat);
115111 for (int y = 0 ; y < height; y++) {
116112 sk_bzero (dst, width * bpp);
117113 dst = (char *)dst + dstRB;
118114 }
119- return true ;
120- }
121-
122- int srcRB = glyph->rowBytes ();
123- // The windows font host sometimes has BW glyphs in a non-BW strike. So it is important here to
124- // check the glyph's format, not the strike's format, and to be able to convert to any of the
125- // GrMaskFormats.
126- if (glyph->maskFormat () == SkMask::kBW_Format ) {
127- // expand bits to our mask type
128- const uint8_t * bits = reinterpret_cast <const uint8_t *>(src);
129- switch (expectedMaskFormat) {
130- case kA8_GrMaskFormat :{
131- uint8_t * bytes = reinterpret_cast <uint8_t *>(dst);
132- expand_bits (bytes, bits, width, height, dstRB, srcRB);
133- break ;
115+ } else {
116+ int srcRB = glyph->rowBytes ();
117+ // The windows font host sometimes has BW glyphs in a non-BW strike. So it is important here
118+ // to check the glyph's format, not the strike's format, and to be able to convert to any
119+ // of the GrMaskFormats.
120+ if (glyph->maskFormat () == SkMask::kBW_Format ) {
121+ // expand bits to our mask type
122+ const uint8_t * bits = reinterpret_cast <const uint8_t *>(src);
123+ switch (expectedMaskFormat) {
124+ case kA8_GrMaskFormat : {
125+ uint8_t * bytes = reinterpret_cast <uint8_t *>(dst);
126+ expand_bits (bytes, bits, width, height, dstRB, srcRB);
127+ break ;
128+ }
129+ case kA565_GrMaskFormat : {
130+ uint16_t * rgb565 = reinterpret_cast <uint16_t *>(dst);
131+ expand_bits (rgb565, bits, width, height, dstRB, srcRB);
132+ break ;
133+ }
134+ default :
135+ SK_ABORT (" Invalid GrMaskFormat" );
134136 }
135- case kA565_GrMaskFormat : {
136- uint16_t * rgb565 = reinterpret_cast <uint16_t *>(dst);
137- expand_bits (rgb565, bits, width, height, dstRB, srcRB);
138- break ;
137+ } else if (srcRB == dstRB) {
138+ memcpy (dst, src, dstRB * height);
139+ } else {
140+ const int bbp = GrMaskFormatBytesPerPixel (expectedMaskFormat);
141+ for (int y = 0 ; y < height; y++) {
142+ memcpy (dst, src, width * bbp);
143+ src = (const char *) src + srcRB;
144+ dst = (char *) dst + dstRB;
139145 }
140- default :
141- SK_ABORT (" Invalid GrMaskFormat" );
142- }
143- } else if (srcRB == dstRB) {
144- memcpy (dst, src, dstRB * height);
145- } else {
146- const int bbp = GrMaskFormatBytesPerPixel (expectedMaskFormat);
147- for (int y = 0 ; y < height; y++) {
148- memcpy (dst, src, width * bbp);
149- src = (const char *)src + srcRB;
150- dst = (char *)dst + dstRB;
151146 }
152147 }
153- return true ;
154148}
155149
156150// /////////////////////////////////////////////////////////////////////////////
@@ -201,6 +195,7 @@ GrDrawOpAtlas::ErrorCode GrTextStrike::addGlyphToAtlas(
201195 size_t size = height * rowBytes;
202196
203197 const SkGlyph* skGlyph = metricsAndImages->glyph (glyph->fPackedID );
198+ if (skGlyph->image () == nullptr ) { return GrDrawOpAtlas::ErrorCode::kError ; }
204199
205200 // Temporary storage for normalizing glyph image.
206201 SkAutoSMalloc<1024 > storage (size);
@@ -210,11 +205,9 @@ GrDrawOpAtlas::ErrorCode GrTextStrike::addGlyphToAtlas(
210205 // Advance in one row and one column.
211206 dataPtr = (char *)(dataPtr) + rowBytes + bytesPerPixel;
212207 }
213- if (!get_packed_glyph_image (skGlyph, glyph->width (), glyph->height (),
214- rowBytes, expectedMaskFormat,
215- dataPtr, glyphCache->getMasks ())) {
216- return GrDrawOpAtlas::ErrorCode::kError ;
217- }
208+
209+ get_packed_glyph_image (skGlyph, glyph->width (), glyph->height (),
210+ rowBytes, expectedMaskFormat, dataPtr, glyphCache->getMasks ());
218211
219212 GrDrawOpAtlas::ErrorCode result = fullAtlasManager->addToAtlas (
220213 resourceProvider, glyphCache, this ,
0 commit comments