| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 156 } |
| 157 | 157 |
| 158 GrBatchTextStrike::~GrBatchTextStrike() { | 158 GrBatchTextStrike::~GrBatchTextStrike() { |
| 159 SkTDynamicHash<GrGlyph, GrGlyph::PackedID>::Iter iter(&fCache); | 159 SkTDynamicHash<GrGlyph, GrGlyph::PackedID>::Iter iter(&fCache); |
| 160 while (!iter.done()) { | 160 while (!iter.done()) { |
| 161 (*iter).free(); | 161 (*iter).free(); |
| 162 ++iter; | 162 ++iter; |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 GrGlyph* GrBatchTextStrike::generateGlyph(GrGlyph::PackedID packed, | 166 GrGlyph* GrBatchTextStrike::generateGlyph(const SkGlyph& skGlyph, GrGlyph::Packe
dID packed, |
| 167 GrFontScaler* scaler) { | 167 GrFontScaler* scaler) { |
| 168 SkIRect bounds; | 168 SkIRect bounds; |
| 169 if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(packed)) { | 169 if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(packed)) { |
| 170 if (!scaler->getPackedGlyphDFBounds(packed, &bounds)) { | 170 if (!scaler->getPackedGlyphDFBounds(skGlyph, &bounds)) { |
| 171 return NULL; | 171 return NULL; |
| 172 } | 172 } |
| 173 } else { | 173 } else { |
| 174 if (!scaler->getPackedGlyphBounds(packed, &bounds)) { | 174 if (!scaler->getPackedGlyphBounds(skGlyph, &bounds)) { |
| 175 return NULL; | 175 return NULL; |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 GrMaskFormat format = scaler->getPackedGlyphMaskFormat(packed); | 178 GrMaskFormat format = scaler->getPackedGlyphMaskFormat(skGlyph); |
| 179 | 179 |
| 180 GrGlyph* glyph = (GrGlyph*)fPool.alloc(sizeof(GrGlyph), SK_MALLOC_THROW); | 180 GrGlyph* glyph = (GrGlyph*)fPool.alloc(sizeof(GrGlyph), SK_MALLOC_THROW); |
| 181 glyph->init(packed, bounds, format); | 181 glyph->init(packed, bounds, format); |
| 182 fCache.add(glyph); | 182 fCache.add(glyph); |
| 183 return glyph; | 183 return glyph; |
| 184 } | 184 } |
| 185 | 185 |
| 186 void GrBatchTextStrike::removeID(GrBatchAtlas::AtlasID id) { | 186 void GrBatchTextStrike::removeID(GrBatchAtlas::AtlasID id) { |
| 187 SkTDynamicHash<GrGlyph, GrGlyph::PackedID>::Iter iter(&fCache); | 187 SkTDynamicHash<GrGlyph, GrGlyph::PackedID>::Iter iter(&fCache); |
| 188 while (!iter.done()) { | 188 while (!iter.done()) { |
| 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) { | 199 GrFontScaler* scaler, const SkGlyph& skG
lyph) { |
| 200 SkASSERT(glyph); | 200 SkASSERT(glyph); |
| 201 SkASSERT(scaler); | 201 SkASSERT(scaler); |
| 202 SkASSERT(fCache.find(glyph->fPackedID)); | 202 SkASSERT(fCache.find(glyph->fPackedID)); |
| 203 SkASSERT(NULL == glyph->fPlot); | 203 SkASSERT(NULL == glyph->fPlot); |
| 204 | 204 |
| 205 SkAutoUnref ar(SkSafeRef(scaler)); | 205 SkAutoUnref ar(SkSafeRef(scaler)); |
| 206 | 206 |
| 207 int bytesPerPixel = GrMaskFormatBytesPerPixel(glyph->fMaskFormat); | 207 int bytesPerPixel = GrMaskFormatBytesPerPixel(glyph->fMaskFormat); |
| 208 | 208 |
| 209 size_t size = glyph->fBounds.area() * bytesPerPixel; | 209 size_t size = glyph->fBounds.area() * bytesPerPixel; |
| 210 SkAutoSMalloc<1024> storage(size); | 210 SkAutoSMalloc<1024> storage(size); |
| 211 | 211 |
| 212 if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(glyph->fPackedI
D)) { | 212 if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(glyph->fPackedI
D)) { |
| 213 if (!scaler->getPackedGlyphDFImage(glyph->fPackedID, glyph->width(), | 213 if (!scaler->getPackedGlyphDFImage(skGlyph, glyph->width(), glyph->heigh
t(), |
| 214 glyph->height(), | |
| 215 storage.get())) { | 214 storage.get())) { |
| 216 return false; | 215 return false; |
| 217 } | 216 } |
| 218 } else { | 217 } else { |
| 219 if (!scaler->getPackedGlyphImage(glyph->fPackedID, glyph->width(), | 218 if (!scaler->getPackedGlyphImage(skGlyph, glyph->width(), glyph->height(
), |
| 220 glyph->height(), | 219 glyph->width() * bytesPerPixel, storage
.get())) { |
| 221 glyph->width() * bytesPerPixel, | |
| 222 storage.get())) { | |
| 223 return false; | 220 return false; |
| 224 } | 221 } |
| 225 } | 222 } |
| 226 | 223 |
| 227 bool success = fBatchFontCache->addToAtlas(this, &glyph->fID, batchTarget, g
lyph->fMaskFormat, | 224 bool success = fBatchFontCache->addToAtlas(this, &glyph->fID, batchTarget, g
lyph->fMaskFormat, |
| 228 glyph->width(), glyph->height(), | 225 glyph->width(), glyph->height(), |
| 229 storage.get(), &glyph->fAtlasLoca
tion); | 226 storage.get(), &glyph->fAtlasLoca
tion); |
| 230 if (success) { | 227 if (success) { |
| 231 fAtlasedGlyphs++; | 228 fAtlasedGlyphs++; |
| 232 } | 229 } |
| 233 return success; | 230 return success; |
| 234 } | 231 } |
| OLD | NEW |