| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrBatchFontCache.h" | 8 #include "GrBatchFontCache.h" |
| 9 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 #include "GrFontAtlasSizes.h" | 10 #include "GrFontAtlasSizes.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 if (id == (*iter).fID) { | 189 if (id == (*iter).fID) { |
| 190 (*iter).fID = GrBatchAtlas::kInvalidAtlasID; | 190 (*iter).fID = GrBatchAtlas::kInvalidAtlasID; |
| 191 fAtlasedGlyphs--; | 191 fAtlasedGlyphs--; |
| 192 SkASSERT(fAtlasedGlyphs >= 0); | 192 SkASSERT(fAtlasedGlyphs >= 0); |
| 193 } | 193 } |
| 194 ++iter; | 194 ++iter; |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 | 197 |
| 198 bool GrBatchTextStrike::addGlyphToAtlas(GrBatchTarget* batchTarget, GrGlyph* gly
ph, | 198 bool GrBatchTextStrike::addGlyphToAtlas(GrBatchTarget* batchTarget, GrGlyph* gly
ph, |
| 199 GrFontScaler* scaler, const SkGlyph& skG
lyph) { | 199 GrFontScaler* scaler, const SkGlyph& skG
lyph, |
| 200 GrMaskFormat expectedMaskFormat) { |
| 200 SkASSERT(glyph); | 201 SkASSERT(glyph); |
| 201 SkASSERT(scaler); | 202 SkASSERT(scaler); |
| 202 SkASSERT(fCache.find(glyph->fPackedID)); | 203 SkASSERT(fCache.find(glyph->fPackedID)); |
| 203 SkASSERT(NULL == glyph->fPlot); | 204 SkASSERT(NULL == glyph->fPlot); |
| 204 | 205 |
| 205 SkAutoUnref ar(SkSafeRef(scaler)); | 206 SkAutoUnref ar(SkSafeRef(scaler)); |
| 206 | 207 |
| 207 int bytesPerPixel = GrMaskFormatBytesPerPixel(glyph->fMaskFormat); | 208 int bytesPerPixel = GrMaskFormatBytesPerPixel(expectedMaskFormat); |
| 208 | 209 |
| 209 size_t size = glyph->fBounds.area() * bytesPerPixel; | 210 size_t size = glyph->fBounds.area() * bytesPerPixel; |
| 210 SkAutoSMalloc<1024> storage(size); | 211 SkAutoSMalloc<1024> storage(size); |
| 211 | 212 |
| 212 if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(glyph->fPackedI
D)) { | 213 if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(glyph->fPackedI
D)) { |
| 213 if (!scaler->getPackedGlyphDFImage(skGlyph, glyph->width(), glyph->heigh
t(), | 214 if (!scaler->getPackedGlyphDFImage(skGlyph, glyph->width(), glyph->heigh
t(), |
| 214 storage.get())) { | 215 storage.get())) { |
| 215 return false; | 216 return false; |
| 216 } | 217 } |
| 217 } else { | 218 } else { |
| 218 if (!scaler->getPackedGlyphImage(skGlyph, glyph->width(), glyph->height(
), | 219 if (!scaler->getPackedGlyphImage(skGlyph, glyph->width(), glyph->height(
), |
| 219 glyph->width() * bytesPerPixel, storage
.get())) { | 220 glyph->width() * bytesPerPixel, expecte
dMaskFormat, |
| 221 storage.get())) { |
| 220 return false; | 222 return false; |
| 221 } | 223 } |
| 222 } | 224 } |
| 223 | 225 |
| 224 bool success = fBatchFontCache->addToAtlas(this, &glyph->fID, batchTarget, g
lyph->fMaskFormat, | 226 bool success = fBatchFontCache->addToAtlas(this, &glyph->fID, batchTarget, e
xpectedMaskFormat, |
| 225 glyph->width(), glyph->height(), | 227 glyph->width(), glyph->height(), |
| 226 storage.get(), &glyph->fAtlasLoca
tion); | 228 storage.get(), &glyph->fAtlasLoca
tion); |
| 227 if (success) { | 229 if (success) { |
| 228 fAtlasedGlyphs++; | 230 fAtlasedGlyphs++; |
| 229 } | 231 } |
| 230 return success; | 232 return success; |
| 231 } | 233 } |
| OLD | NEW |