Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: src/core/SkGlyphCache.cpp

Issue 2055023003: Type-erase SkAutoMutexAcquire and SkAutoExclusive. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/private/SkMutex.h ('k') | src/ports/SkScalerContext_win_dw.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkGlyphCache.h" 8 #include "SkGlyphCache.h"
9 #include "SkGlyphCache_Globals.h" 9 #include "SkGlyphCache_Globals.h"
10 #include "SkGraphics.h" 10 #include "SkGraphics.h"
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 rec->fProc(rec->fData); 463 rec->fProc(rec->fData);
464 AuxProcRec* next = rec->fNext; 464 AuxProcRec* next = rec->fNext;
465 delete rec; 465 delete rec;
466 rec = next; 466 rec = next;
467 } 467 }
468 } 468 }
469 469
470 /////////////////////////////////////////////////////////////////////////////// 470 ///////////////////////////////////////////////////////////////////////////////
471 /////////////////////////////////////////////////////////////////////////////// 471 ///////////////////////////////////////////////////////////////////////////////
472 472
473 typedef SkAutoTExclusive<SkSpinlock> Exclusive;
474
475 size_t SkGlyphCache_Globals::setCacheSizeLimit(size_t newLimit) { 473 size_t SkGlyphCache_Globals::setCacheSizeLimit(size_t newLimit) {
476 static const size_t minLimit = 256 * 1024; 474 static const size_t minLimit = 256 * 1024;
477 if (newLimit < minLimit) { 475 if (newLimit < minLimit) {
478 newLimit = minLimit; 476 newLimit = minLimit;
479 } 477 }
480 478
481 Exclusive ac(fLock); 479 SkAutoExclusive ac(fLock);
482 480
483 size_t prevLimit = fCacheSizeLimit; 481 size_t prevLimit = fCacheSizeLimit;
484 fCacheSizeLimit = newLimit; 482 fCacheSizeLimit = newLimit;
485 this->internalPurge(); 483 this->internalPurge();
486 return prevLimit; 484 return prevLimit;
487 } 485 }
488 486
489 int SkGlyphCache_Globals::setCacheCountLimit(int newCount) { 487 int SkGlyphCache_Globals::setCacheCountLimit(int newCount) {
490 if (newCount < 0) { 488 if (newCount < 0) {
491 newCount = 0; 489 newCount = 0;
492 } 490 }
493 491
494 Exclusive ac(fLock); 492 SkAutoExclusive ac(fLock);
495 493
496 int prevCount = fCacheCountLimit; 494 int prevCount = fCacheCountLimit;
497 fCacheCountLimit = newCount; 495 fCacheCountLimit = newCount;
498 this->internalPurge(); 496 this->internalPurge();
499 return prevCount; 497 return prevCount;
500 } 498 }
501 499
502 void SkGlyphCache_Globals::purgeAll() { 500 void SkGlyphCache_Globals::purgeAll() {
503 Exclusive ac(fLock); 501 SkAutoExclusive ac(fLock);
504 this->internalPurge(fTotalMemoryUsed); 502 this->internalPurge(fTotalMemoryUsed);
505 } 503 }
506 504
507 /* This guy calls the visitor from within the mutext lock, so the visitor 505 /* This guy calls the visitor from within the mutext lock, so the visitor
508 cannot: 506 cannot:
509 - take too much time 507 - take too much time
510 - try to acquire the mutext again 508 - try to acquire the mutext again
511 - call a fontscaler (which might call into the cache) 509 - call a fontscaler (which might call into the cache)
512 */ 510 */
513 SkGlyphCache* SkGlyphCache::VisitCache(SkTypeface* typeface, 511 SkGlyphCache* SkGlyphCache::VisitCache(SkTypeface* typeface,
(...skipping 13 matching lines...) Expand all
527 desc->findEntry(kRec_SkDescriptorTag, &length)); 525 desc->findEntry(kRec_SkDescriptorTag, &length));
528 SkASSERT(rec); 526 SkASSERT(rec);
529 SkASSERT(length == sizeof(*rec)); 527 SkASSERT(length == sizeof(*rec));
530 SkASSERT(typeface->uniqueID() == rec->fFontID); 528 SkASSERT(typeface->uniqueID() == rec->fFontID);
531 ) 529 )
532 530
533 SkGlyphCache_Globals& globals = get_globals(); 531 SkGlyphCache_Globals& globals = get_globals();
534 SkGlyphCache* cache; 532 SkGlyphCache* cache;
535 533
536 { 534 {
537 Exclusive ac(globals.fLock); 535 SkAutoExclusive ac(globals.fLock);
538 536
539 globals.validate(); 537 globals.validate();
540 538
541 for (cache = globals.internalGetHead(); cache != nullptr; cache = cache- >fNext) { 539 for (cache = globals.internalGetHead(); cache != nullptr; cache = cache- >fNext) {
542 if (*cache->fDesc == *desc) { 540 if (*cache->fDesc == *desc) {
543 globals.internalDetachCache(cache); 541 globals.internalDetachCache(cache);
544 if (!proc(cache, context)) { 542 if (!proc(cache, context)) {
545 globals.internalAttachCacheToHead(cache); 543 globals.internalAttachCacheToHead(cache);
546 cache = nullptr; 544 cache = nullptr;
547 } 545 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 if (dump->getRequestedDetails() == SkTraceMemoryDump::kLight_LevelOfDetail) { 638 if (dump->getRequestedDetails() == SkTraceMemoryDump::kLight_LevelOfDetail) {
641 dump->setMemoryBacking(gGlyphCacheDumpName, "malloc", nullptr); 639 dump->setMemoryBacking(gGlyphCacheDumpName, "malloc", nullptr);
642 return; 640 return;
643 } 641 }
644 642
645 SkGlyphCache::VisitAll(sk_trace_dump_visitor, dump); 643 SkGlyphCache::VisitAll(sk_trace_dump_visitor, dump);
646 } 644 }
647 645
648 void SkGlyphCache::VisitAll(Visitor visitor, void* context) { 646 void SkGlyphCache::VisitAll(Visitor visitor, void* context) {
649 SkGlyphCache_Globals& globals = get_globals(); 647 SkGlyphCache_Globals& globals = get_globals();
650 Exclusive ac(globals.fLock); 648 SkAutoExclusive ac(globals.fLock);
651 SkGlyphCache* cache; 649 SkGlyphCache* cache;
652 650
653 globals.validate(); 651 globals.validate();
654 652
655 for (cache = globals.internalGetHead(); cache != nullptr; cache = cache->fNe xt) { 653 for (cache = globals.internalGetHead(); cache != nullptr; cache = cache->fNe xt) {
656 visitor(*cache, context); 654 visitor(*cache, context);
657 } 655 }
658 } 656 }
659 657
660 /////////////////////////////////////////////////////////////////////////////// 658 ///////////////////////////////////////////////////////////////////////////////
661 659
662 void SkGlyphCache_Globals::attachCacheToHead(SkGlyphCache* cache) { 660 void SkGlyphCache_Globals::attachCacheToHead(SkGlyphCache* cache) {
663 Exclusive ac(fLock); 661 SkAutoExclusive ac(fLock);
664 662
665 this->validate(); 663 this->validate();
666 cache->validate(); 664 cache->validate();
667 665
668 this->internalAttachCacheToHead(cache); 666 this->internalAttachCacheToHead(cache);
669 this->internalPurge(); 667 this->internalPurge();
670 } 668 }
671 669
672 SkGlyphCache* SkGlyphCache_Globals::internalGetTail() const { 670 SkGlyphCache* SkGlyphCache_Globals::internalGetTail() const {
673 SkGlyphCache* cache = fHead; 671 SkGlyphCache* cache = fHead;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 } 825 }
828 826
829 void SkGraphics::PurgeFontCache() { 827 void SkGraphics::PurgeFontCache() {
830 get_globals().purgeAll(); 828 get_globals().purgeAll();
831 SkTypefaceCache::PurgeAll(); 829 SkTypefaceCache::PurgeAll();
832 } 830 }
833 831
834 // TODO(herb): clean up TLS apis. 832 // TODO(herb): clean up TLS apis.
835 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } 833 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; }
836 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } 834 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { }
OLDNEW
« no previous file with comments | « include/private/SkMutex.h ('k') | src/ports/SkScalerContext_win_dw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698