Chromium Code Reviews| 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" | |
| 12 #include "SkGraphics.h" | 13 #include "SkGraphics.h" |
| 13 #include "SkPaint.h" | 14 #include "SkPaint.h" |
| 14 #include "SkPath.h" | 15 #include "SkPath.h" |
| 15 #include "SkTemplates.h" | 16 #include "SkTemplates.h" |
| 16 #include "SkTLS.h" | 17 #include "SkTLS.h" |
| 17 #include "SkTypeface.h" | 18 #include "SkTypeface.h" |
| 18 | 19 |
| 19 //#define SPEW_PURGE_STATUS | 20 //#define SPEW_PURGE_STATUS |
| 20 //#define RECORD_HASH_EFFICIENCY | 21 //#define RECORD_HASH_EFFICIENCY |
| 21 | 22 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 if (glyph.fPath == NULL) { | 352 if (glyph.fPath == NULL) { |
| 352 const_cast<SkGlyph&>(glyph).fPath = SkNEW(SkPath); | 353 const_cast<SkGlyph&>(glyph).fPath = SkNEW(SkPath); |
| 353 fScalerContext->getPath(glyph, glyph.fPath); | 354 fScalerContext->getPath(glyph, glyph.fPath); |
| 354 fMemoryUsed += sizeof(SkPath) + | 355 fMemoryUsed += sizeof(SkPath) + |
| 355 glyph.fPath->countPoints() * sizeof(SkPoint); | 356 glyph.fPath->countPoints() * sizeof(SkPoint); |
| 356 } | 357 } |
| 357 } | 358 } |
| 358 return glyph.fPath; | 359 return glyph.fPath; |
| 359 } | 360 } |
| 360 | 361 |
| 362 const void* SkGlyphCache::findDistanceField(const SkGlyph& glyph) { | |
| 363 if (glyph.fWidth > 0 && glyph.fWidth < kMaxGlyphWidth) { | |
| 364 if (NULL == glyph.fDistanceField) { | |
| 365 size_t size = SkComputeDistanceFieldSize(glyph.fWidth, glyph.fHeigh t); | |
| 366 if (size == 0) { | |
| 367 return NULL; | |
| 368 } | |
|
robertphillips
2014/04/11 14:13:00
this->?
jvanverth1
2014/04/11 17:54:14
Done.
| |
| 369 const void* image = findImage(glyph); | |
| 370 // now generate the distance field | |
|
robertphillips
2014/04/11 14:13:00
NULL != ?
jvanverth1
2014/04/11 17:54:14
Done.
| |
| 371 if (image) { | |
| 372 const_cast<SkGlyph&>(glyph).fDistanceField = fGlyphAlloc.alloc(s ize, | |
| 373 SkChunkAlloc::kReturnNil_AllocFailTy pe); | |
|
robertphillips
2014/04/11 14:13:00
NULL != ?
jvanverth1
2014/04/11 17:54:14
Done.
| |
| 374 if (glyph.fDistanceField) { | |
| 375 SkMask::Format maskFormat = static_cast<SkMask::Format>(glyp h.fMaskFormat); | |
| 376 if (SkMask::kA8_Format == maskFormat) { | |
| 377 // make the distance field from the image | |
| 378 SkGenerateDistanceFieldFromA8Image((unsigned char*)glyph .fDistanceField, | |
| 379 (unsigned char*)glyph .fImage, | |
|
robertphillips
2014/04/11 14:13:00
overlength
jvanverth1
2014/04/11 17:54:14
Done.
| |
| 380 glyph.fWidth, glyph.f Height, glyph.rowBytes()); | |
| 381 fMemoryUsed += size; | |
| 382 } else if (SkMask::kBW_Format == maskFormat) { | |
| 383 // make the distance field from the image | |
| 384 SkGenerateDistanceFieldFromBWImage((unsigned char*)glyph .fDistanceField, | |
| 385 (unsigned char*)glyph .fImage, | |
|
robertphillips
2014/04/11 14:13:00
overlength
jvanverth1
2014/04/11 17:54:14
Done.
| |
| 386 glyph.fWidth, glyph.f Height, glyph.rowBytes()); | |
| 387 fMemoryUsed += size; | |
| 388 } else { | |
| 389 fGlyphAlloc.unalloc(glyph.fDistanceField); | |
| 390 const_cast<SkGlyph&>(glyph).fDistanceField = NULL; | |
| 391 } | |
| 392 } | |
| 393 } | |
| 394 } | |
| 395 } | |
| 396 return glyph.fDistanceField; | |
| 397 } | |
| 398 | |
| 361 /////////////////////////////////////////////////////////////////////////////// | 399 /////////////////////////////////////////////////////////////////////////////// |
| 362 | 400 |
| 363 bool SkGlyphCache::getAuxProcData(void (*proc)(void*), void** dataPtr) const { | 401 bool SkGlyphCache::getAuxProcData(void (*proc)(void*), void** dataPtr) const { |
| 364 const AuxProcRec* rec = fAuxProcList; | 402 const AuxProcRec* rec = fAuxProcList; |
| 365 while (rec) { | 403 while (rec) { |
| 366 if (rec->fProc == proc) { | 404 if (rec->fProc == proc) { |
| 367 if (dataPtr) { | 405 if (dataPtr) { |
| 368 *dataPtr = rec->fData; | 406 *dataPtr = rec->fData; |
| 369 } | 407 } |
| 370 return true; | 408 return true; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 void SkGlyphCache::validate() const { | 680 void SkGlyphCache::validate() const { |
| 643 #ifdef SK_DEBUG_GLYPH_CACHE | 681 #ifdef SK_DEBUG_GLYPH_CACHE |
| 644 int count = fGlyphArray.count(); | 682 int count = fGlyphArray.count(); |
| 645 for (int i = 0; i < count; i++) { | 683 for (int i = 0; i < count; i++) { |
| 646 const SkGlyph* glyph = fGlyphArray[i]; | 684 const SkGlyph* glyph = fGlyphArray[i]; |
| 647 SkASSERT(glyph); | 685 SkASSERT(glyph); |
| 648 SkASSERT(fGlyphAlloc.contains(glyph)); | 686 SkASSERT(fGlyphAlloc.contains(glyph)); |
| 649 if (glyph->fImage) { | 687 if (glyph->fImage) { |
| 650 SkASSERT(fGlyphAlloc.contains(glyph->fImage)); | 688 SkASSERT(fGlyphAlloc.contains(glyph->fImage)); |
| 651 } | 689 } |
| 690 if (glyph->fDistanceField) { | |
| 691 SkASSERT(fGlyphAlloc.contains(glyph->fDistanceField)); | |
| 692 } | |
| 652 } | 693 } |
| 653 #endif | 694 #endif |
| 654 } | 695 } |
| 655 | 696 |
| 656 void SkGlyphCache_Globals::validate() const { | 697 void SkGlyphCache_Globals::validate() const { |
| 657 size_t computedBytes = 0; | 698 size_t computedBytes = 0; |
| 658 int computedCount = 0; | 699 int computedCount = 0; |
| 659 | 700 |
| 660 const SkGlyphCache* head = fHead; | 701 const SkGlyphCache* head = fHead; |
| 661 while (head != NULL) { | 702 while (head != NULL) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 return tls ? tls->getCacheSizeLimit() : 0; | 750 return tls ? tls->getCacheSizeLimit() : 0; |
| 710 } | 751 } |
| 711 | 752 |
| 712 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { | 753 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { |
| 713 if (0 == bytes) { | 754 if (0 == bytes) { |
| 714 SkGlyphCache_Globals::DeleteTLS(); | 755 SkGlyphCache_Globals::DeleteTLS(); |
| 715 } else { | 756 } else { |
| 716 SkGlyphCache_Globals::GetTLS().setCacheSizeLimit(bytes); | 757 SkGlyphCache_Globals::GetTLS().setCacheSizeLimit(bytes); |
| 717 } | 758 } |
| 718 } | 759 } |
| OLD | NEW |