| 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 "SkGraphics.h" | 12 #include "SkGraphics.h" |
| 12 #include "SkPaint.h" | 13 #include "SkPaint.h" |
| 13 #include "SkPath.h" | 14 #include "SkPath.h" |
| 14 #include "SkTemplates.h" | 15 #include "SkTemplates.h" |
| 15 #include "SkTLS.h" | 16 #include "SkTLS.h" |
| 16 #include "SkTypeface.h" | 17 #include "SkTypeface.h" |
| 17 | 18 |
| 18 //#define SPEW_PURGE_STATUS | 19 //#define SPEW_PURGE_STATUS |
| 19 //#define RECORD_HASH_EFFICIENCY | 20 //#define RECORD_HASH_EFFICIENCY |
| 20 | 21 |
| 21 bool gSkSuppressFontCachePurgeSpew; | 22 bool gSkSuppressFontCachePurgeSpew; |
| 22 | 23 |
| 24 // Returns the shared globals |
| 25 static SkGlyphCache_Globals& getSharedGlobals() { |
| 26 // we leak this, so we don't incur any shutdown cost of the destructor |
| 27 static SkGlyphCache_Globals* gGlobals = SkNEW_ARGS(SkGlyphCache_Globals, |
| 28 (SkGlyphCache_Globals::kY
es_UseMutex)); |
| 29 return *gGlobals; |
| 30 } |
| 31 |
| 32 // Returns the TLS globals (if set), or the shared globals |
| 33 static SkGlyphCache_Globals& getGlobals() { |
| 34 SkGlyphCache_Globals* tls = SkGlyphCache_Globals::FindTLS(); |
| 35 return tls ? *tls : getSharedGlobals(); |
| 36 } |
| 37 |
| 23 /////////////////////////////////////////////////////////////////////////////// | 38 /////////////////////////////////////////////////////////////////////////////// |
| 24 | 39 |
| 25 #ifdef RECORD_HASH_EFFICIENCY | 40 #ifdef RECORD_HASH_EFFICIENCY |
| 26 static uint32_t gHashSuccess; | 41 static uint32_t gHashSuccess; |
| 27 static uint32_t gHashCollision; | 42 static uint32_t gHashCollision; |
| 28 | 43 |
| 29 static void RecordHashSuccess() { | 44 static void RecordHashSuccess() { |
| 30 gHashSuccess += 1; | 45 gHashSuccess += 1; |
| 31 } | 46 } |
| 32 | 47 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 rec->fProc(rec->fData); | 405 rec->fProc(rec->fData); |
| 391 AuxProcRec* next = rec->fNext; | 406 AuxProcRec* next = rec->fNext; |
| 392 SkDELETE(rec); | 407 SkDELETE(rec); |
| 393 rec = next; | 408 rec = next; |
| 394 } | 409 } |
| 395 } | 410 } |
| 396 | 411 |
| 397 /////////////////////////////////////////////////////////////////////////////// | 412 /////////////////////////////////////////////////////////////////////////////// |
| 398 /////////////////////////////////////////////////////////////////////////////// | 413 /////////////////////////////////////////////////////////////////////////////// |
| 399 | 414 |
| 400 #ifndef SK_DEFAULT_FONT_CACHE_LIMIT | |
| 401 #define SK_DEFAULT_FONT_CACHE_LIMIT (2 * 1024 * 1024) | |
| 402 #endif | |
| 403 | |
| 404 #include "SkThread.h" | 415 #include "SkThread.h" |
| 405 | 416 |
| 406 class SkGlyphCache_Globals { | 417 size_t SkGlyphCache_Globals::setCacheSizeLimit(size_t newLimit) { |
| 407 public: | |
| 408 enum UseMutex { | |
| 409 kNo_UseMutex, // thread-local cache | |
| 410 kYes_UseMutex // shared cache | |
| 411 }; | |
| 412 | |
| 413 SkGlyphCache_Globals(UseMutex um) { | |
| 414 fHead = NULL; | |
| 415 fTotalMemoryUsed = 0; | |
| 416 fFontCacheLimit = SK_DEFAULT_FONT_CACHE_LIMIT; | |
| 417 fMutex = (kYes_UseMutex == um) ? SkNEW(SkMutex) : NULL; | |
| 418 } | |
| 419 | |
| 420 ~SkGlyphCache_Globals() { | |
| 421 SkGlyphCache* cache = fHead; | |
| 422 while (cache) { | |
| 423 SkGlyphCache* next = cache->fNext; | |
| 424 SkDELETE(cache); | |
| 425 cache = next; | |
| 426 } | |
| 427 | |
| 428 SkDELETE(fMutex); | |
| 429 } | |
| 430 | |
| 431 SkMutex* fMutex; | |
| 432 SkGlyphCache* fHead; | |
| 433 size_t fTotalMemoryUsed; | |
| 434 | |
| 435 #ifdef SK_DEBUG | |
| 436 void validate() const; | |
| 437 #else | |
| 438 void validate() const {} | |
| 439 #endif | |
| 440 | |
| 441 size_t getFontCacheLimit() const { return fFontCacheLimit; } | |
| 442 size_t setFontCacheLimit(size_t limit); | |
| 443 void purgeAll(); // does not change budget | |
| 444 | |
| 445 // can return NULL | |
| 446 static SkGlyphCache_Globals* FindTLS() { | |
| 447 return (SkGlyphCache_Globals*)SkTLS::Find(CreateTLS); | |
| 448 } | |
| 449 | |
| 450 static SkGlyphCache_Globals& GetTLS() { | |
| 451 return *(SkGlyphCache_Globals*)SkTLS::Get(CreateTLS, DeleteTLS); | |
| 452 } | |
| 453 | |
| 454 static void DeleteTLS() { SkTLS::Delete(CreateTLS); } | |
| 455 | |
| 456 private: | |
| 457 size_t fFontCacheLimit; | |
| 458 | |
| 459 static void* CreateTLS() { | |
| 460 return SkNEW_ARGS(SkGlyphCache_Globals, (kNo_UseMutex)); | |
| 461 } | |
| 462 | |
| 463 static void DeleteTLS(void* ptr) { | |
| 464 SkDELETE((SkGlyphCache_Globals*)ptr); | |
| 465 } | |
| 466 }; | |
| 467 | |
| 468 size_t SkGlyphCache_Globals::setFontCacheLimit(size_t newLimit) { | |
| 469 static const size_t minLimit = 256 * 1024; | 418 static const size_t minLimit = 256 * 1024; |
| 470 if (newLimit < minLimit) { | 419 if (newLimit < minLimit) { |
| 471 newLimit = minLimit; | 420 newLimit = minLimit; |
| 472 } | 421 } |
| 422 |
| 423 SkAutoMutexAcquire ac(fMutex); |
| 424 |
| 425 size_t prevLimit = fCacheSizeLimit; |
| 426 fCacheSizeLimit = newLimit; |
| 427 this->internalPurge(); |
| 428 return prevLimit; |
| 429 } |
| 473 | 430 |
| 474 size_t prevLimit = fFontCacheLimit; | 431 int SkGlyphCache_Globals::setCacheCountLimit(int newCount) { |
| 475 fFontCacheLimit = newLimit; | 432 if (newCount < 0) { |
| 476 | 433 newCount = 0; |
| 477 size_t currUsed = fTotalMemoryUsed; | |
| 478 if (currUsed > newLimit) { | |
| 479 SkAutoMutexAcquire ac(fMutex); | |
| 480 SkGlyphCache::InternalFreeCache(this, currUsed - newLimit); | |
| 481 } | 434 } |
| 482 return prevLimit; | 435 |
| 436 SkAutoMutexAcquire ac(fMutex); |
| 437 |
| 438 int prevCount = fCacheCountLimit; |
| 439 fCacheCountLimit = newCount; |
| 440 this->internalPurge(); |
| 441 return prevCount; |
| 483 } | 442 } |
| 484 | 443 |
| 485 void SkGlyphCache_Globals::purgeAll() { | 444 void SkGlyphCache_Globals::purgeAll() { |
| 486 SkAutoMutexAcquire ac(fMutex); | 445 SkAutoMutexAcquire ac(fMutex); |
| 487 SkGlyphCache::InternalFreeCache(this, fTotalMemoryUsed); | 446 this->internalPurge(fTotalMemoryUsed); |
| 488 } | |
| 489 | |
| 490 // Returns the shared globals | |
| 491 static SkGlyphCache_Globals& getSharedGlobals() { | |
| 492 // we leak this, so we don't incur any shutdown cost of the destructor | |
| 493 static SkGlyphCache_Globals* gGlobals = SkNEW_ARGS(SkGlyphCache_Globals, | |
| 494 (SkGlyphCache_Globals::kYes_UseMutex)); | |
| 495 return *gGlobals; | |
| 496 } | |
| 497 | |
| 498 // Returns the TLS globals (if set), or the shared globals | |
| 499 static SkGlyphCache_Globals& getGlobals() { | |
| 500 SkGlyphCache_Globals* tls = SkGlyphCache_Globals::FindTLS(); | |
| 501 return tls ? *tls : getSharedGlobals(); | |
| 502 } | 447 } |
| 503 | 448 |
| 504 void SkGlyphCache::VisitAllCaches(bool (*proc)(SkGlyphCache*, void*), | 449 void SkGlyphCache::VisitAllCaches(bool (*proc)(SkGlyphCache*, void*), |
| 505 void* context) { | 450 void* context) { |
| 506 SkGlyphCache_Globals& globals = getGlobals(); | 451 SkGlyphCache_Globals& globals = getGlobals(); |
| 507 SkAutoMutexAcquire ac(globals.fMutex); | 452 SkAutoMutexAcquire ac(globals.fMutex); |
| 508 SkGlyphCache* cache; | 453 SkGlyphCache* cache; |
| 509 | 454 |
| 510 globals.validate(); | 455 globals.validate(); |
| 511 | 456 |
| 512 for (cache = globals.fHead; cache != NULL; cache = cache->fNext) { | 457 for (cache = globals.internalGetHead(); cache != NULL; cache = cache->fNext)
{ |
| 513 if (proc(cache, context)) { | 458 if (proc(cache, context)) { |
| 514 break; | 459 break; |
| 515 } | 460 } |
| 516 } | 461 } |
| 517 | 462 |
| 518 globals.validate(); | 463 globals.validate(); |
| 519 } | 464 } |
| 520 | 465 |
| 521 /* This guy calls the visitor from within the mutext lock, so the visitor | 466 /* This guy calls the visitor from within the mutext lock, so the visitor |
| 522 cannot: | 467 cannot: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 533 } | 478 } |
| 534 SkASSERT(desc); | 479 SkASSERT(desc); |
| 535 | 480 |
| 536 SkGlyphCache_Globals& globals = getGlobals(); | 481 SkGlyphCache_Globals& globals = getGlobals(); |
| 537 SkAutoMutexAcquire ac(globals.fMutex); | 482 SkAutoMutexAcquire ac(globals.fMutex); |
| 538 SkGlyphCache* cache; | 483 SkGlyphCache* cache; |
| 539 bool insideMutex = true; | 484 bool insideMutex = true; |
| 540 | 485 |
| 541 globals.validate(); | 486 globals.validate(); |
| 542 | 487 |
| 543 for (cache = globals.fHead; cache != NULL; cache = cache->fNext) { | 488 for (cache = globals.internalGetHead(); cache != NULL; cache = cache->fNext)
{ |
| 544 if (cache->fDesc->equals(*desc)) { | 489 if (cache->fDesc->equals(*desc)) { |
| 545 cache->detach(&globals.fHead); | 490 globals.internalDetachCache(cache); |
| 546 goto FOUND_IT; | 491 goto FOUND_IT; |
| 547 } | 492 } |
| 548 } | 493 } |
| 549 | 494 |
| 550 /* Release the mutex now, before we create a new entry (which might have | 495 /* Release the mutex now, before we create a new entry (which might have |
| 551 side-effects like trying to access the cache/mutex (yikes!) | 496 side-effects like trying to access the cache/mutex (yikes!) |
| 552 */ | 497 */ |
| 553 ac.release(); // release the mutex now | 498 ac.release(); // release the mutex now |
| 554 insideMutex = false; // can't use globals anymore | 499 insideMutex = false; // can't use globals anymore |
| 555 | 500 |
| 556 // Check if we can create a scaler-context before creating the glyphcache. | 501 // Check if we can create a scaler-context before creating the glyphcache. |
| 557 // If not, we may have exhausted OS/font resources, so try purging the | 502 // If not, we may have exhausted OS/font resources, so try purging the |
| 558 // cache once and try again. | 503 // cache once and try again. |
| 559 { | 504 { |
| 560 // pass true the first time, to notice if the scalercontext failed, | 505 // pass true the first time, to notice if the scalercontext failed, |
| 561 // so we can try the purge. | 506 // so we can try the purge. |
| 562 SkScalerContext* ctx = typeface->createScalerContext(desc, true); | 507 SkScalerContext* ctx = typeface->createScalerContext(desc, true); |
| 563 if (!ctx) { | 508 if (!ctx) { |
| 564 getSharedGlobals().purgeAll(); | 509 getSharedGlobals().purgeAll(); |
| 565 ctx = typeface->createScalerContext(desc, false); | 510 ctx = typeface->createScalerContext(desc, false); |
| 566 SkASSERT(ctx); | 511 SkASSERT(ctx); |
| 567 } | 512 } |
| 568 cache = SkNEW_ARGS(SkGlyphCache, (typeface, desc, ctx)); | 513 cache = SkNEW_ARGS(SkGlyphCache, (typeface, desc, ctx)); |
| 569 } | 514 } |
| 570 | 515 |
| 571 FOUND_IT: | 516 FOUND_IT: |
| 572 | 517 |
| 573 AutoValidate av(cache); | 518 AutoValidate av(cache); |
| 574 | 519 |
| 575 if (proc(cache, context)) { // stay detached | 520 if (!proc(cache, context)) { // need to reattach |
| 576 if (insideMutex) { | 521 if (insideMutex) { |
| 577 SkASSERT(globals.fTotalMemoryUsed >= cache->fMemoryUsed); | 522 globals.internalAttachCacheToHead(cache); |
| 578 globals.fTotalMemoryUsed -= cache->fMemoryUsed; | |
| 579 } | |
| 580 } else { // reattach | |
| 581 if (insideMutex) { | |
| 582 cache->attachToHead(&globals.fHead); | |
| 583 } else { | 523 } else { |
| 584 AttachCache(cache); | 524 globals.attachCacheToHead(cache); |
| 585 } | 525 } |
| 586 cache = NULL; | 526 cache = NULL; |
| 587 } | 527 } |
| 588 return cache; | 528 return cache; |
| 589 } | 529 } |
| 590 | 530 |
| 591 void SkGlyphCache::AttachCache(SkGlyphCache* cache) { | 531 void SkGlyphCache::AttachCache(SkGlyphCache* cache) { |
| 592 SkASSERT(cache); | 532 SkASSERT(cache); |
| 593 SkASSERT(cache->fNext == NULL); | 533 SkASSERT(cache->fNext == NULL); |
| 594 | 534 |
| 595 SkGlyphCache_Globals& globals = getGlobals(); | 535 getGlobals().attachCacheToHead(cache); |
| 596 SkAutoMutexAcquire ac(globals.fMutex); | |
| 597 | |
| 598 globals.validate(); | |
| 599 cache->validate(); | |
| 600 | |
| 601 // if we have a fixed budget for our cache, do a purge here | |
| 602 { | |
| 603 size_t allocated = globals.fTotalMemoryUsed + cache->fMemoryUsed; | |
| 604 size_t budgeted = globals.getFontCacheLimit(); | |
| 605 if (allocated > budgeted) { | |
| 606 (void)InternalFreeCache(&globals, allocated - budgeted); | |
| 607 } | |
| 608 } | |
| 609 | |
| 610 cache->attachToHead(&globals.fHead); | |
| 611 globals.fTotalMemoryUsed += cache->fMemoryUsed; | |
| 612 | |
| 613 globals.validate(); | |
| 614 } | 536 } |
| 615 | 537 |
| 616 /////////////////////////////////////////////////////////////////////////////// | 538 /////////////////////////////////////////////////////////////////////////////// |
| 617 | 539 |
| 618 SkGlyphCache* SkGlyphCache::FindTail(SkGlyphCache* cache) { | 540 void SkGlyphCache_Globals::attachCacheToHead(SkGlyphCache* cache) { |
| 541 SkAutoMutexAcquire ac(fMutex); |
| 542 |
| 543 this->validate(); |
| 544 cache->validate(); |
| 545 |
| 546 this->internalAttachCacheToHead(cache); |
| 547 this->internalPurge(); |
| 548 } |
| 549 |
| 550 SkGlyphCache* SkGlyphCache_Globals::internalGetTail() const { |
| 551 SkGlyphCache* cache = fHead; |
| 619 if (cache) { | 552 if (cache) { |
| 620 while (cache->fNext) { | 553 while (cache->fNext) { |
| 621 cache = cache->fNext; | 554 cache = cache->fNext; |
| 622 } | 555 } |
| 623 } | 556 } |
| 624 return cache; | 557 return cache; |
| 625 } | 558 } |
| 626 | 559 |
| 627 #ifdef SK_DEBUG | 560 size_t SkGlyphCache_Globals::internalPurge(size_t minBytesNeeded) { |
| 628 void SkGlyphCache_Globals::validate() const { | 561 this->validate(); |
| 629 size_t computed = 0; | |
| 630 | 562 |
| 631 const SkGlyphCache* head = fHead; | 563 size_t bytesNeeded = 0; |
| 632 while (head != NULL) { | 564 if (fTotalMemoryUsed > fCacheSizeLimit) { |
| 633 computed += head->fMemoryUsed; | 565 bytesNeeded = fTotalMemoryUsed - fCacheSizeLimit; |
| 634 head = head->fNext; | 566 } |
| 567 bytesNeeded = SkMax32(bytesNeeded, minBytesNeeded); |
| 568 if (bytesNeeded) { |
| 569 // no small purges! |
| 570 bytesNeeded = SkMax32(bytesNeeded, fTotalMemoryUsed >> 2); |
| 635 } | 571 } |
| 636 | 572 |
| 637 if (fTotalMemoryUsed != computed) { | 573 int countNeeded = 0; |
| 638 printf("total %d, computed %d\n", (int)fTotalMemoryUsed, (int)computed); | 574 if (fCacheCount > fCacheCountLimit) { |
| 575 countNeeded = fCacheCount - fCacheCountLimit; |
| 576 // no small purges! |
| 577 countNeeded = SkMax32(countNeeded, fCacheCount >> 2); |
| 639 } | 578 } |
| 640 SkASSERT(fTotalMemoryUsed == computed); | |
| 641 } | |
| 642 #endif | |
| 643 | 579 |
| 644 size_t SkGlyphCache::InternalFreeCache(SkGlyphCache_Globals* globals, | 580 // early exit |
| 645 size_t bytesNeeded) { | 581 if (!countNeeded && !bytesNeeded) { |
| 646 globals->validate(); | 582 return 0; |
| 583 } |
| 647 | 584 |
| 648 size_t bytesFreed = 0; | 585 size_t bytesFreed = 0; |
| 649 int count = 0; | 586 int countFreed = 0; |
| 650 | 587 |
| 651 // don't do any "small" purges | 588 // we start at the tail and proceed backwards, as the linklist is in LRU |
| 652 size_t minToPurge = globals->fTotalMemoryUsed >> 2; | 589 // order, with unimportant entries at the tail. |
| 653 if (bytesNeeded < minToPurge) | 590 SkGlyphCache* cache = this->internalGetTail(); |
| 654 bytesNeeded = minToPurge; | 591 while (cache != NULL && |
| 655 | 592 (bytesFreed < bytesNeeded || countFreed < countNeeded)) { |
| 656 SkGlyphCache* cache = FindTail(globals->fHead); | |
| 657 while (cache != NULL && bytesFreed < bytesNeeded) { | |
| 658 SkGlyphCache* prev = cache->fPrev; | 593 SkGlyphCache* prev = cache->fPrev; |
| 659 bytesFreed += cache->fMemoryUsed; | 594 bytesFreed += cache->fMemoryUsed; |
| 595 countFreed += 1; |
| 660 | 596 |
| 661 cache->detach(&globals->fHead); | 597 this->internalDetachCache(cache); |
| 662 SkDELETE(cache); | 598 SkDELETE(cache); |
| 663 cache = prev; | 599 cache = prev; |
| 664 count += 1; | |
| 665 } | 600 } |
| 666 | 601 |
| 667 SkASSERT(bytesFreed <= globals->fTotalMemoryUsed); | 602 this->validate(); |
| 668 globals->fTotalMemoryUsed -= bytesFreed; | |
| 669 globals->validate(); | |
| 670 | 603 |
| 671 #ifdef SPEW_PURGE_STATUS | 604 #ifdef SPEW_PURGE_STATUS |
| 672 if (count && !gSkSuppressFontCachePurgeSpew) { | 605 if (countFreed && !gSkSuppressFontCachePurgeSpew) { |
| 673 SkDebugf("purging %dK from font cache [%d entries]\n", | 606 SkDebugf("purging %dK from font cache [%d entries]\n", |
| 674 (int)(bytesFreed >> 10), count); | 607 (int)(bytesFreed >> 10), countFreed); |
| 675 } | 608 } |
| 676 #endif | 609 #endif |
| 677 | 610 |
| 678 return bytesFreed; | 611 return bytesFreed; |
| 679 } | 612 } |
| 680 | 613 |
| 614 void SkGlyphCache_Globals::internalAttachCacheToHead(SkGlyphCache* cache) { |
| 615 SkASSERT(NULL == cache->fPrev && NULL == cache->fNext); |
| 616 if (fHead) { |
| 617 fHead->fPrev = cache; |
| 618 cache->fNext = fHead; |
| 619 } |
| 620 fHead = cache; |
| 621 |
| 622 fCacheCount += 1; |
| 623 fTotalMemoryUsed += cache->fMemoryUsed; |
| 624 } |
| 625 |
| 626 void SkGlyphCache_Globals::internalDetachCache(SkGlyphCache* cache) { |
| 627 SkASSERT(fCacheCount > 0); |
| 628 fCacheCount -= 1; |
| 629 fTotalMemoryUsed -= cache->fMemoryUsed; |
| 630 |
| 631 if (cache->fPrev) { |
| 632 cache->fPrev->fNext = cache->fNext; |
| 633 } else { |
| 634 fHead = cache->fNext; |
| 635 } |
| 636 if (cache->fNext) { |
| 637 cache->fNext->fPrev = cache->fPrev; |
| 638 } |
| 639 cache->fPrev = cache->fNext = NULL; |
| 640 } |
| 641 |
| 681 /////////////////////////////////////////////////////////////////////////////// | 642 /////////////////////////////////////////////////////////////////////////////// |
| 682 | 643 |
| 683 #ifdef SK_DEBUG | 644 #ifdef SK_DEBUG |
| 645 |
| 684 void SkGlyphCache::validate() const { | 646 void SkGlyphCache::validate() const { |
| 685 #ifdef SK_DEBUG_GLYPH_CACHE | 647 #ifdef SK_DEBUG_GLYPH_CACHE |
| 686 int count = fGlyphArray.count(); | 648 int count = fGlyphArray.count(); |
| 687 for (int i = 0; i < count; i++) { | 649 for (int i = 0; i < count; i++) { |
| 688 const SkGlyph* glyph = fGlyphArray[i]; | 650 const SkGlyph* glyph = fGlyphArray[i]; |
| 689 SkASSERT(glyph); | 651 SkASSERT(glyph); |
| 690 SkASSERT(fGlyphAlloc.contains(glyph)); | 652 SkASSERT(fGlyphAlloc.contains(glyph)); |
| 691 if (glyph->fImage) { | 653 if (glyph->fImage) { |
| 692 SkASSERT(fGlyphAlloc.contains(glyph->fImage)); | 654 SkASSERT(fGlyphAlloc.contains(glyph->fImage)); |
| 693 } | 655 } |
| 694 } | 656 } |
| 695 #endif | 657 #endif |
| 696 } | 658 } |
| 659 |
| 660 void SkGlyphCache_Globals::validate() const { |
| 661 size_t computedBytes = 0; |
| 662 int computedCount = 0; |
| 663 |
| 664 const SkGlyphCache* head = fHead; |
| 665 while (head != NULL) { |
| 666 computedBytes += head->fMemoryUsed; |
| 667 computedCount += 1; |
| 668 head = head->fNext; |
| 669 } |
| 670 |
| 671 SkASSERT(fTotalMemoryUsed == computedBytes); |
| 672 SkASSERT(fCacheCount == computedCount); |
| 673 } |
| 674 |
| 697 #endif | 675 #endif |
| 698 | 676 |
| 699 /////////////////////////////////////////////////////////////////////////////// | 677 /////////////////////////////////////////////////////////////////////////////// |
| 700 /////////////////////////////////////////////////////////////////////////////// | 678 /////////////////////////////////////////////////////////////////////////////// |
| 701 | 679 |
| 702 #include "SkTypefaceCache.h" | 680 #include "SkTypefaceCache.h" |
| 703 | 681 |
| 704 size_t SkGraphics::GetFontCacheLimit() { | 682 size_t SkGraphics::GetFontCacheLimit() { |
| 705 return getSharedGlobals().getFontCacheLimit(); | 683 return getSharedGlobals().getCacheSizeLimit(); |
| 706 } | 684 } |
| 707 | 685 |
| 708 size_t SkGraphics::SetFontCacheLimit(size_t bytes) { | 686 size_t SkGraphics::SetFontCacheLimit(size_t bytes) { |
| 709 return getSharedGlobals().setFontCacheLimit(bytes); | 687 return getSharedGlobals().setCacheSizeLimit(bytes); |
| 710 } | 688 } |
| 711 | 689 |
| 712 size_t SkGraphics::GetFontCacheUsed() { | 690 size_t SkGraphics::GetFontCacheUsed() { |
| 713 return getSharedGlobals().fTotalMemoryUsed; | 691 return getSharedGlobals().getTotalMemoryUsed(); |
| 692 } |
| 693 |
| 694 int SkGraphics::GetFontCacheCountLimit() { |
| 695 return getSharedGlobals().getCacheCountLimit(); |
| 696 } |
| 697 |
| 698 int SkGraphics::SetFontCacheCountLimit(int count) { |
| 699 return getSharedGlobals().setCacheCountLimit(count); |
| 700 } |
| 701 |
| 702 int SkGraphics::GetFontCacheCountUsed() { |
| 703 return getSharedGlobals().getCacheCountUsed(); |
| 714 } | 704 } |
| 715 | 705 |
| 716 void SkGraphics::PurgeFontCache() { | 706 void SkGraphics::PurgeFontCache() { |
| 717 getSharedGlobals().purgeAll(); | 707 getSharedGlobals().purgeAll(); |
| 718 SkTypefaceCache::PurgeAll(); | 708 SkTypefaceCache::PurgeAll(); |
| 719 } | 709 } |
| 720 | 710 |
| 721 size_t SkGraphics::GetTLSFontCacheLimit() { | 711 size_t SkGraphics::GetTLSFontCacheLimit() { |
| 722 const SkGlyphCache_Globals* tls = SkGlyphCache_Globals::FindTLS(); | 712 const SkGlyphCache_Globals* tls = SkGlyphCache_Globals::FindTLS(); |
| 723 return tls ? tls->getFontCacheLimit() : 0; | 713 return tls ? tls->getCacheSizeLimit() : 0; |
| 724 } | 714 } |
| 725 | 715 |
| 726 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { | 716 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { |
| 727 if (0 == bytes) { | 717 if (0 == bytes) { |
| 728 SkGlyphCache_Globals::DeleteTLS(); | 718 SkGlyphCache_Globals::DeleteTLS(); |
| 729 } else { | 719 } else { |
| 730 SkGlyphCache_Globals::GetTLS().setFontCacheLimit(bytes); | 720 SkGlyphCache_Globals::GetTLS().setCacheSizeLimit(bytes); |
| 731 } | 721 } |
| 732 } | 722 } |
| OLD | NEW |