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

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

Issue 1333003002: Correct a possible free after use. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: move purge code. Created 5 years, 3 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 | « no previous file | src/core/SkGlyphCache_Globals.h » ('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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // pass true the first time, to notice if the scalercontext failed, 421 // pass true the first time, to notice if the scalercontext failed,
422 // so we can try the purge. 422 // so we can try the purge.
423 SkScalerContext* ctx = typeface->createScalerContext(desc, true); 423 SkScalerContext* ctx = typeface->createScalerContext(desc, true);
424 if (nullptr == ctx) { 424 if (nullptr == ctx) {
425 get_globals().purgeAll(); 425 get_globals().purgeAll();
426 ctx = typeface->createScalerContext(desc, false); 426 ctx = typeface->createScalerContext(desc, false);
427 SkASSERT(ctx); 427 SkASSERT(ctx);
428 } 428 }
429 429
430 cache = new SkGlyphCache(typeface, desc, ctx); 430 cache = new SkGlyphCache(typeface, desc, ctx);
431
432 globals.attachCacheToHead(cache);
433 } 431 }
434 432
435 AutoValidate av(cache);
436 AutoAcquire ac(globals.fLock); 433 AutoAcquire ac(globals.fLock);
mtklein 2015/09/10 20:35:47 Does this make sense? // Do not lock globals.fLoc
434 globals.internalAttachCacheToHead(cache);
437 435
438 cache->fMapMutex.acquireShared(); 436 cache->fMapMutex.acquireShared();
439 if (!proc(cache, context)) { // need to reattach 437 if (!proc(cache, context)) { // need to reattach
440 cache->fMapMutex.releaseShared(); 438 cache->fMapMutex.releaseShared();
441 return nullptr; 439 return nullptr;
442 } 440 }
443 // The caller will take reference on this SkGlyphCache, and the correspondin g 441 // The caller will take reference on this SkGlyphCache, and the correspondin g
444 // Attach call will decrement the reference. 442 // Attach call will decrement the reference.
445 cache->fRefCount += 1; 443 cache->fRefCount += 1;
446 return cache; 444 return cache;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 525
528 globals.validate(); 526 globals.validate();
529 527
530 for (cache = globals.internalGetHead(); cache != nullptr; cache = cache->fNe xt) { 528 for (cache = globals.internalGetHead(); cache != nullptr; cache = cache->fNe xt) {
531 visitor(*cache, context); 529 visitor(*cache, context);
532 } 530 }
533 } 531 }
534 532
535 /////////////////////////////////////////////////////////////////////////////// 533 ///////////////////////////////////////////////////////////////////////////////
536 534
537 void SkGlyphCache_Globals::attachCacheToHead(SkGlyphCache* cache) { 535 void SkGlyphCache_Globals::internalAttachCacheToHead(SkGlyphCache* cache) {
538 AutoAcquire ac(fLock); 536 this->internalPurge();
539
540 fCacheCount += 1; 537 fCacheCount += 1;
541 cache->fRefCount += 1; 538 cache->fRefCount += 1;
542 // Access to cache->fMemoryUsed is single threaded until internalMoveToHead. 539 // Access to cache->fMemoryUsed is single threaded until internalMoveToHead.
543 fTotalMemoryUsed.fetch_add(cache->fMemoryUsed); 540 fTotalMemoryUsed.fetch_add(cache->fMemoryUsed);
544 541
545 this->internalMoveToHead(cache); 542 this->internalMoveToHead(cache);
546 543
547 this->validate(); 544 this->validate();
548 cache->validate(); 545 cache->validate();
549
550 this->internalPurge();
551 } 546 }
552 547
553 SkGlyphCache* SkGlyphCache_Globals::internalGetTail() const { 548 SkGlyphCache* SkGlyphCache_Globals::internalGetTail() const {
554 SkGlyphCache* cache = fHead; 549 SkGlyphCache* cache = fHead;
555 if (cache) { 550 if (cache) {
556 while (cache->fNext) { 551 while (cache->fNext) {
557 cache = cache->fNext; 552 cache = cache->fNext;
558 } 553 }
559 } 554 }
560 return cache; 555 return cache;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 } 716 }
722 717
723 void SkGraphics::PurgeFontCache() { 718 void SkGraphics::PurgeFontCache() {
724 get_globals().purgeAll(); 719 get_globals().purgeAll();
725 SkTypefaceCache::PurgeAll(); 720 SkTypefaceCache::PurgeAll();
726 } 721 }
727 722
728 // TODO(herb): clean up TLS apis. 723 // TODO(herb): clean up TLS apis.
729 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } 724 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; }
730 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } 725 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { }
OLDNEW
« no previous file with comments | « no previous file | src/core/SkGlyphCache_Globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698