OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "GrFontScaler.h" | 9 #include "GrFontScaler.h" |
10 #include "SkDescriptor.h" | 10 #include "SkDescriptor.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 *d++ = (mask & (1 << i)) ? (INT_TYPE)(~0UL) : 0; | 96 *d++ = (mask & (1 << i)) ? (INT_TYPE)(~0UL) : 0; |
97 } | 97 } |
98 } | 98 } |
99 dst = reinterpret_cast<INT_TYPE*>(reinterpret_cast<intptr_t>(dst) + dstR owBytes); | 99 dst = reinterpret_cast<INT_TYPE*>(reinterpret_cast<intptr_t>(dst) + dstR owBytes); |
100 src += srcRowBytes; | 100 src += srcRowBytes; |
101 } | 101 } |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 bool GrFontScaler::getPackedGlyphImage(const SkGlyph& glyph, int width, int heig ht, int dstRB, | 105 bool GrFontScaler::getPackedGlyphImage(const SkGlyph& glyph, int width, int heig ht, int dstRB, |
106 void* dst) { | 106 GrMaskFormat expectedMaskFormat, void* ds t) { |
107 SkASSERT(glyph.fWidth == width); | 107 SkASSERT(glyph.fWidth == width); |
108 SkASSERT(glyph.fHeight == height); | 108 SkASSERT(glyph.fHeight == height); |
109 const void* src = fStrike->findImage(glyph); | 109 const void* src = fStrike->findImage(glyph); |
110 if (NULL == src) { | 110 if (NULL == src) { |
111 return false; | 111 return false; |
112 } | 112 } |
113 | 113 |
114 // crbug:510931 | |
115 // Retrieving the image from the cache can actually change the mask format. This case is very | |
116 // uncommon so for now we just draw a clear box for these glyphs. | |
robertphillips
2015/07/30 14:36:26
this->getPackedGlyphMaskFormat ?
| |
117 if (getPackedGlyphMaskFormat(glyph) != expectedMaskFormat) { | |
118 const int bpp = GrMaskFormatBytesPerPixel(expectedMaskFormat); | |
119 for (int y = 0; y < height; y++) { | |
120 sk_bzero(dst, width * bpp); | |
121 dst = (char*)dst + dstRB; | |
122 } | |
123 return true; | |
124 } | |
125 | |
114 int srcRB = glyph.rowBytes(); | 126 int srcRB = glyph.rowBytes(); |
115 // The windows font host sometimes has BW glyphs in a non-BW strike. So it i s important here to | 127 // The windows font host sometimes has BW glyphs in a non-BW strike. So it i s important here to |
116 // check the glyph's format, not the strike's format, and to be able to conv ert to any of the | 128 // check the glyph's format, not the strike's format, and to be able to conv ert to any of the |
117 // GrMaskFormats. | 129 // GrMaskFormats. |
118 if (SkMask::kBW_Format == glyph.fMaskFormat) { | 130 if (SkMask::kBW_Format == glyph.fMaskFormat) { |
119 // expand bits to our mask type | 131 // expand bits to our mask type |
120 const uint8_t* bits = reinterpret_cast<const uint8_t*>(src); | 132 const uint8_t* bits = reinterpret_cast<const uint8_t*>(src); |
robertphillips
2015/07/30 14:36:26
what happened to the "this->" ?
| |
121 switch (this->getMaskFormat()) { | 133 switch (getMaskFormat()) { |
122 case kA8_GrMaskFormat:{ | 134 case kA8_GrMaskFormat:{ |
123 uint8_t* bytes = reinterpret_cast<uint8_t*>(dst); | 135 uint8_t* bytes = reinterpret_cast<uint8_t*>(dst); |
124 expand_bits(bytes, bits, width, height, dstRB, srcRB); | 136 expand_bits(bytes, bits, width, height, dstRB, srcRB); |
125 break; | 137 break; |
126 } | 138 } |
127 case kA565_GrMaskFormat: { | 139 case kA565_GrMaskFormat: { |
128 uint16_t* rgb565 = reinterpret_cast<uint16_t*>(dst); | 140 uint16_t* rgb565 = reinterpret_cast<uint16_t*>(dst); |
129 expand_bits(rgb565, bits, width, height, dstRB, srcRB); | 141 expand_bits(rgb565, bits, width, height, dstRB, srcRB); |
130 break; | 142 break; |
131 } | 143 } |
132 default: | 144 default: |
133 SkFAIL("Invalid GrMaskFormat"); | 145 SkFAIL("Invalid GrMaskFormat"); |
134 } | 146 } |
135 } else if (srcRB == dstRB) { | 147 } else if (srcRB == dstRB) { |
136 memcpy(dst, src, dstRB * height); | 148 memcpy(dst, src, dstRB * height); |
137 } else { | 149 } else { |
robertphillips
2015/07/30 14:36:26
here too ?
| |
138 const int bbp = GrMaskFormatBytesPerPixel(this->getMaskFormat()); | 150 const int bpp = GrMaskFormatBytesPerPixel(getMaskFormat()); |
139 for (int y = 0; y < height; y++) { | 151 for (int y = 0; y < height; y++) { |
140 memcpy(dst, src, width * bbp); | 152 memcpy(dst, src, width * bpp); |
141 src = (const char*)src + srcRB; | 153 src = (const char*)src + srcRB; |
142 dst = (char*)dst + dstRB; | 154 dst = (char*)dst + dstRB; |
143 } | 155 } |
144 } | 156 } |
145 return true; | 157 return true; |
146 } | 158 } |
147 | 159 |
148 bool GrFontScaler::getPackedGlyphDFImage(const SkGlyph& glyph, int width, int he ight, void* dst) { | 160 bool GrFontScaler::getPackedGlyphDFImage(const SkGlyph& glyph, int width, int he ight, void* dst) { |
149 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); | 161 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); |
150 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); | 162 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); |
151 const void* image = fStrike->findImage(glyph); | 163 const void* image = fStrike->findImage(glyph); |
152 if (NULL == image) { | 164 if (NULL == image) { |
153 return false; | 165 return false; |
154 } | 166 } |
167 | |
155 // now generate the distance field | 168 // now generate the distance field |
156 SkASSERT(dst); | 169 SkASSERT(dst); |
157 SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); | 170 SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); |
158 if (SkMask::kA8_Format == maskFormat) { | 171 if (SkMask::kA8_Format == maskFormat) { |
159 // make the distance field from the image | 172 // make the distance field from the image |
160 SkGenerateDistanceFieldFromA8Image((unsigned char*)dst, | 173 SkGenerateDistanceFieldFromA8Image((unsigned char*)dst, |
161 (unsigned char*)image, | 174 (unsigned char*)image, |
162 glyph.fWidth, glyph.fHeight, | 175 glyph.fWidth, glyph.fHeight, |
163 glyph.rowBytes()); | 176 glyph.rowBytes()); |
164 } else if (SkMask::kBW_Format == maskFormat) { | 177 } else if (SkMask::kBW_Format == maskFormat) { |
(...skipping 11 matching lines...) Expand all Loading... | |
176 | 189 |
177 const SkPath* GrFontScaler::getGlyphPath(const SkGlyph& glyph) { | 190 const SkPath* GrFontScaler::getGlyphPath(const SkGlyph& glyph) { |
178 return fStrike->findPath(glyph); | 191 return fStrike->findPath(glyph); |
179 } | 192 } |
180 | 193 |
181 const SkGlyph& GrFontScaler::grToSkGlyph(GrGlyph::PackedID id) { | 194 const SkGlyph& GrFontScaler::grToSkGlyph(GrGlyph::PackedID id) { |
182 return fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(id), | 195 return fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(id), |
183 GrGlyph::UnpackFixedX(id), | 196 GrGlyph::UnpackFixedX(id), |
184 GrGlyph::UnpackFixedY(id)); | 197 GrGlyph::UnpackFixedY(id)); |
185 } | 198 } |
OLD | NEW |