OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
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 "SkGlyphCache.h" | 10 #include "SkGlyphCache.h" |
11 #include "SkGlyphCache_Globals.h" | 11 #include "SkGlyphCache_Globals.h" |
12 #include "SkDistanceFieldGen.h" | |
13 #include "SkGraphics.h" | 12 #include "SkGraphics.h" |
14 #include "SkLazyPtr.h" | 13 #include "SkLazyPtr.h" |
15 #include "SkPaint.h" | 14 #include "SkPaint.h" |
16 #include "SkPath.h" | 15 #include "SkPath.h" |
17 #include "SkTemplates.h" | 16 #include "SkTemplates.h" |
18 #include "SkTLS.h" | 17 #include "SkTLS.h" |
19 #include "SkTypeface.h" | 18 #include "SkTypeface.h" |
20 | 19 |
21 //#define SPEW_PURGE_STATUS | 20 //#define SPEW_PURGE_STATUS |
22 //#define RECORD_HASH_EFFICIENCY | 21 //#define RECORD_HASH_EFFICIENCY |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 if (glyph.fPath == NULL) { | 357 if (glyph.fPath == NULL) { |
359 const_cast<SkGlyph&>(glyph).fPath = SkNEW(SkPath); | 358 const_cast<SkGlyph&>(glyph).fPath = SkNEW(SkPath); |
360 fScalerContext->getPath(glyph, glyph.fPath); | 359 fScalerContext->getPath(glyph, glyph.fPath); |
361 fMemoryUsed += sizeof(SkPath) + | 360 fMemoryUsed += sizeof(SkPath) + |
362 glyph.fPath->countPoints() * sizeof(SkPoint); | 361 glyph.fPath->countPoints() * sizeof(SkPoint); |
363 } | 362 } |
364 } | 363 } |
365 return glyph.fPath; | 364 return glyph.fPath; |
366 } | 365 } |
367 | 366 |
368 const void* SkGlyphCache::findDistanceField(const SkGlyph& glyph) { | |
369 if (glyph.fWidth > 0 && glyph.fWidth < kMaxGlyphWidth) { | |
370 if (NULL == glyph.fDistanceField) { | |
371 size_t size = SkComputeDistanceFieldSize(glyph.fWidth, glyph.fHeigh
t); | |
372 if (size == 0) { | |
373 return NULL; | |
374 } | |
375 const void* image = this->findImage(glyph); | |
376 // now generate the distance field | |
377 if (image) { | |
378 const_cast<SkGlyph&>(glyph).fDistanceField = fGlyphAlloc.alloc(s
ize, | |
379 SkChunkAlloc::kReturnNil_AllocFailTy
pe); | |
380 if (glyph.fDistanceField) { | |
381 SkMask::Format maskFormat = static_cast<SkMask::Format>(glyp
h.fMaskFormat); | |
382 if (SkMask::kA8_Format == maskFormat) { | |
383 // make the distance field from the image | |
384 SkGenerateDistanceFieldFromA8Image((unsigned char*)glyph
.fDistanceField, | |
385 (unsigned char*)glyph
.fImage, | |
386 glyph.fWidth, glyph.f
Height, | |
387 glyph.rowBytes()); | |
388 fMemoryUsed += size; | |
389 } else if (SkMask::kBW_Format == maskFormat) { | |
390 // make the distance field from the image | |
391 SkGenerateDistanceFieldFromBWImage((unsigned char*)glyph
.fDistanceField, | |
392 (unsigned char*)glyph
.fImage, | |
393 glyph.fWidth, glyph.f
Height, | |
394 glyph.rowBytes()); | |
395 fMemoryUsed += size; | |
396 } else { | |
397 fGlyphAlloc.unalloc(glyph.fDistanceField); | |
398 const_cast<SkGlyph&>(glyph).fDistanceField = NULL; | |
399 } | |
400 } | |
401 } | |
402 } | |
403 } | |
404 return glyph.fDistanceField; | |
405 } | |
406 | |
407 /////////////////////////////////////////////////////////////////////////////// | 367 /////////////////////////////////////////////////////////////////////////////// |
408 | 368 |
409 bool SkGlyphCache::getAuxProcData(void (*proc)(void*), void** dataPtr) const { | 369 bool SkGlyphCache::getAuxProcData(void (*proc)(void*), void** dataPtr) const { |
410 const AuxProcRec* rec = fAuxProcList; | 370 const AuxProcRec* rec = fAuxProcList; |
411 while (rec) { | 371 while (rec) { |
412 if (rec->fProc == proc) { | 372 if (rec->fProc == proc) { |
413 if (dataPtr) { | 373 if (dataPtr) { |
414 *dataPtr = rec->fData; | 374 *dataPtr = rec->fData; |
415 } | 375 } |
416 return true; | 376 return true; |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 return tls ? tls->getCacheSizeLimit() : 0; | 701 return tls ? tls->getCacheSizeLimit() : 0; |
742 } | 702 } |
743 | 703 |
744 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { | 704 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { |
745 if (0 == bytes) { | 705 if (0 == bytes) { |
746 SkGlyphCache_Globals::DeleteTLS(); | 706 SkGlyphCache_Globals::DeleteTLS(); |
747 } else { | 707 } else { |
748 SkGlyphCache_Globals::GetTLS().setCacheSizeLimit(bytes); | 708 SkGlyphCache_Globals::GetTLS().setCacheSizeLimit(bytes); |
749 } | 709 } |
750 } | 710 } |
OLD | NEW |