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 | 9 |
10 #include "GrTemplates.h" | 10 #include "GrTemplates.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 const GrFontDescKey* GrFontScaler::getKey() { | 79 const GrFontDescKey* GrFontScaler::getKey() { |
80 if (NULL == fKey) { | 80 if (NULL == fKey) { |
81 fKey = SkNEW_ARGS(GrFontDescKey, (fStrike->getDescriptor())); | 81 fKey = SkNEW_ARGS(GrFontDescKey, (fStrike->getDescriptor())); |
82 } | 82 } |
83 return fKey; | 83 return fKey; |
84 } | 84 } |
85 | 85 |
86 GrMaskFormat GrFontScaler::getPackedGlyphMaskFormat(GrGlyph::PackedID packed) co
nst { | 86 GrMaskFormat GrFontScaler::getPackedGlyphMaskFormat(const SkGlyph& glyph) const
{ |
87 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), | |
88 GrGlyph::UnpackFixedX(pack
ed), | |
89 GrGlyph::UnpackFixedY(pack
ed)); | |
90 SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat); | 87 SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat); |
91 switch (format) { | 88 switch (format) { |
92 case SkMask::kBW_Format: | 89 case SkMask::kBW_Format: |
93 // fall through to kA8 -- we store BW glyphs in our 8-bit cache | 90 // fall through to kA8 -- we store BW glyphs in our 8-bit cache |
94 case SkMask::kA8_Format: | 91 case SkMask::kA8_Format: |
95 return kA8_GrMaskFormat; | 92 return kA8_GrMaskFormat; |
96 case SkMask::kLCD16_Format: | 93 case SkMask::kLCD16_Format: |
97 return kA565_GrMaskFormat; | 94 return kA565_GrMaskFormat; |
98 case SkMask::kARGB32_Format: | 95 case SkMask::kARGB32_Format: |
99 return kARGB_GrMaskFormat; | 96 return kARGB_GrMaskFormat; |
100 default: | 97 default: |
101 SkDEBUGFAIL("unsupported SkMask::Format"); | 98 SkDEBUGFAIL("unsupported SkMask::Format"); |
102 return kA8_GrMaskFormat; | 99 return kA8_GrMaskFormat; |
103 } | 100 } |
104 } | 101 } |
105 | 102 |
106 bool GrFontScaler::getPackedGlyphBounds(GrGlyph::PackedID packed, SkIRect* bound
s) { | 103 bool GrFontScaler::getPackedGlyphBounds(const SkGlyph& glyph, SkIRect* bounds) { |
107 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), | 104 #if 1 |
108 GrGlyph::UnpackFixedX(pack
ed), | 105 // crbug:510931 |
109 GrGlyph::UnpackFixedY(pack
ed)); | 106 // Retrieving the image from the cache can actually change the mask format. |
| 107 fStrike->findImage(glyph); |
| 108 #endif |
110 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight); | 109 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight); |
111 | 110 |
112 return true; | 111 return true; |
113 } | 112 } |
114 | 113 |
115 bool GrFontScaler::getPackedGlyphDFBounds(GrGlyph::PackedID packed, SkIRect* bou
nds) { | 114 bool GrFontScaler::getPackedGlyphDFBounds(const SkGlyph& glyph, SkIRect* bounds)
{ |
116 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), | 115 #if 1 |
117 GrGlyph::UnpackFixedX(pack
ed), | 116 // crbug:510931 |
118 GrGlyph::UnpackFixedY(pack
ed)); | 117 // Retrieving the image from the cache can actually change the mask format. |
| 118 fStrike->findImage(glyph); |
| 119 #endif |
119 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight); | 120 bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight); |
120 bounds->outset(SK_DistanceFieldPad, SK_DistanceFieldPad); | 121 bounds->outset(SK_DistanceFieldPad, SK_DistanceFieldPad); |
121 | 122 |
122 return true; | 123 return true; |
123 } | 124 } |
124 | 125 |
125 namespace { | 126 namespace { |
126 // expands each bit in a bitmask to 0 or ~0 of type INT_TYPE. Used to expand a B
W glyph mask to | 127 // expands each bit in a bitmask to 0 or ~0 of type INT_TYPE. Used to expand a B
W glyph mask to |
127 // A8, RGB565, or RGBA8888. | 128 // A8, RGB565, or RGBA8888. |
128 template <typename INT_TYPE> | 129 template <typename INT_TYPE> |
(...skipping 12 matching lines...) Expand all Loading... |
141 for (int i = 7; i >= 0 && rowWritesLeft; --i, --rowWritesLeft) { | 142 for (int i = 7; i >= 0 && rowWritesLeft; --i, --rowWritesLeft) { |
142 *d++ = (mask & (1 << i)) ? (INT_TYPE)(~0UL) : 0; | 143 *d++ = (mask & (1 << i)) ? (INT_TYPE)(~0UL) : 0; |
143 } | 144 } |
144 } | 145 } |
145 dst = reinterpret_cast<INT_TYPE*>(reinterpret_cast<intptr_t>(dst) + dstR
owBytes); | 146 dst = reinterpret_cast<INT_TYPE*>(reinterpret_cast<intptr_t>(dst) + dstR
owBytes); |
146 src += srcRowBytes; | 147 src += srcRowBytes; |
147 } | 148 } |
148 } | 149 } |
149 } | 150 } |
150 | 151 |
151 bool GrFontScaler::getPackedGlyphImage(GrGlyph::PackedID packed, | 152 bool GrFontScaler::getPackedGlyphImage(const SkGlyph& glyph, int width, int heig
ht, int dstRB, |
152 int width, int height, | 153 GrMaskFormat expectedMaskFormat, void* ds
t) { |
153 int dstRB, void* dst) { | |
154 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), | |
155 GrGlyph::UnpackFixedX(pack
ed), | |
156 GrGlyph::UnpackFixedY(pack
ed)); | |
157 SkASSERT(glyph.fWidth == width); | 154 SkASSERT(glyph.fWidth == width); |
158 SkASSERT(glyph.fHeight == height); | 155 SkASSERT(glyph.fHeight == height); |
159 const void* src = fStrike->findImage(glyph); | 156 const void* src = fStrike->findImage(glyph); |
160 if (NULL == src) { | 157 if (NULL == src) { |
161 return false; | 158 return false; |
162 } | 159 } |
163 | 160 |
| 161 // crbug:510931 |
| 162 // Retrieving the image from the cache can actually change the mask format.
This case is very |
| 163 // uncommon so for now we just draw a clear box for these glyphs. |
| 164 if (getPackedGlyphMaskFormat(glyph) != expectedMaskFormat) { |
| 165 const int bpp = GrMaskFormatBytesPerPixel(expectedMaskFormat); |
| 166 for (int y = 0; y < height; y++) { |
| 167 sk_bzero(dst, width * bpp); |
| 168 dst = (char*)dst + dstRB; |
| 169 } |
| 170 return true; |
| 171 } |
| 172 |
164 int srcRB = glyph.rowBytes(); | 173 int srcRB = glyph.rowBytes(); |
165 // The windows font host sometimes has BW glyphs in a non-BW strike. So it i
s important here to | 174 // The windows font host sometimes has BW glyphs in a non-BW strike. So it i
s important here to |
166 // check the glyph's format, not the strike's format, and to be able to conv
ert to any of the | 175 // check the glyph's format, not the strike's format, and to be able to conv
ert to any of the |
167 // GrMaskFormats. | 176 // GrMaskFormats. |
168 if (SkMask::kBW_Format == glyph.fMaskFormat) { | 177 if (SkMask::kBW_Format == glyph.fMaskFormat) { |
169 // expand bits to our mask type | 178 // expand bits to our mask type |
170 const uint8_t* bits = reinterpret_cast<const uint8_t*>(src); | 179 const uint8_t* bits = reinterpret_cast<const uint8_t*>(src); |
171 switch (this->getMaskFormat()) { | 180 switch (expectedMaskFormat) { |
172 case kA8_GrMaskFormat:{ | 181 case kA8_GrMaskFormat:{ |
173 uint8_t* bytes = reinterpret_cast<uint8_t*>(dst); | 182 uint8_t* bytes = reinterpret_cast<uint8_t*>(dst); |
174 expand_bits(bytes, bits, width, height, dstRB, srcRB); | 183 expand_bits(bytes, bits, width, height, dstRB, srcRB); |
175 break; | 184 break; |
176 } | 185 } |
177 case kA565_GrMaskFormat: { | 186 case kA565_GrMaskFormat: { |
178 uint16_t* rgb565 = reinterpret_cast<uint16_t*>(dst); | 187 uint16_t* rgb565 = reinterpret_cast<uint16_t*>(dst); |
179 expand_bits(rgb565, bits, width, height, dstRB, srcRB); | 188 expand_bits(rgb565, bits, width, height, dstRB, srcRB); |
180 break; | 189 break; |
181 } | 190 } |
182 default: | 191 default: |
183 SkFAIL("Invalid GrMaskFormat"); | 192 SkFAIL("Invalid GrMaskFormat"); |
184 } | 193 } |
185 } else if (srcRB == dstRB) { | 194 } else if (srcRB == dstRB) { |
186 memcpy(dst, src, dstRB * height); | 195 memcpy(dst, src, dstRB * height); |
187 } else { | 196 } else { |
188 const int bbp = GrMaskFormatBytesPerPixel(this->getMaskFormat()); | 197 const int bbp = GrMaskFormatBytesPerPixel(expectedMaskFormat); |
189 for (int y = 0; y < height; y++) { | 198 for (int y = 0; y < height; y++) { |
190 memcpy(dst, src, width * bbp); | 199 memcpy(dst, src, width * bbp); |
191 src = (const char*)src + srcRB; | 200 src = (const char*)src + srcRB; |
192 dst = (char*)dst + dstRB; | 201 dst = (char*)dst + dstRB; |
193 } | 202 } |
194 } | 203 } |
195 return true; | 204 return true; |
196 } | 205 } |
197 | 206 |
198 bool GrFontScaler::getPackedGlyphDFImage(GrGlyph::PackedID packed, | 207 bool GrFontScaler::getPackedGlyphDFImage(const SkGlyph& glyph, int width, int he
ight, void* dst) { |
199 int width, int height, | |
200 void* dst) { | |
201 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), | |
202 GrGlyph::UnpackFixedX(pack
ed), | |
203 GrGlyph::UnpackFixedY(pack
ed)); | |
204 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); | 208 SkASSERT(glyph.fWidth + 2*SK_DistanceFieldPad == width); |
205 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); | 209 SkASSERT(glyph.fHeight + 2*SK_DistanceFieldPad == height); |
206 const void* image = fStrike->findImage(glyph); | 210 const void* image = fStrike->findImage(glyph); |
207 if (NULL == image) { | 211 if (NULL == image) { |
208 return false; | 212 return false; |
209 } | 213 } |
210 // now generate the distance field | 214 // now generate the distance field |
211 SkASSERT(dst); | 215 SkASSERT(dst); |
212 SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); | 216 SkMask::Format maskFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); |
213 if (SkMask::kA8_Format == maskFormat) { | 217 if (SkMask::kA8_Format == maskFormat) { |
214 // make the distance field from the image | 218 // make the distance field from the image |
215 SkGenerateDistanceFieldFromA8Image((unsigned char*)dst, | 219 SkGenerateDistanceFieldFromA8Image((unsigned char*)dst, |
216 (unsigned char*)image, | 220 (unsigned char*)image, |
217 glyph.fWidth, glyph.fHeight, | 221 glyph.fWidth, glyph.fHeight, |
218 glyph.rowBytes()); | 222 glyph.rowBytes()); |
219 } else if (SkMask::kBW_Format == maskFormat) { | 223 } else if (SkMask::kBW_Format == maskFormat) { |
220 // make the distance field from the image | 224 // make the distance field from the image |
221 SkGenerateDistanceFieldFromBWImage((unsigned char*)dst, | 225 SkGenerateDistanceFieldFromBWImage((unsigned char*)dst, |
222 (unsigned char*)image, | 226 (unsigned char*)image, |
223 glyph.fWidth, glyph.fHeight, | 227 glyph.fWidth, glyph.fHeight, |
224 glyph.rowBytes()); | 228 glyph.rowBytes()); |
225 } else { | 229 } else { |
226 return false; | 230 return false; |
227 } | 231 } |
228 | 232 |
229 return true; | 233 return true; |
230 } | 234 } |
231 | 235 |
232 // we should just return const SkPath* (NULL means false) | 236 const SkPath* GrFontScaler::getGlyphPath(const SkGlyph& glyph) { |
233 bool GrFontScaler::getGlyphPath(uint16_t glyphID, SkPath* path) { | 237 return fStrike->findPath(glyph); |
| 238 } |
234 | 239 |
235 const SkGlyph& glyph = fStrike->getGlyphIDMetrics(glyphID); | 240 const SkGlyph& GrFontScaler::grToSkGlyph(GrGlyph::PackedID id) { |
236 const SkPath* skPath = fStrike->findPath(glyph); | 241 return fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(id), |
237 if (skPath) { | 242 GrGlyph::UnpackFixedX(id), |
238 *path = *skPath; | 243 GrGlyph::UnpackFixedY(id)); |
239 return true; | |
240 } | |
241 return false; | |
242 } | 244 } |
OLD | NEW |