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: trunk/src/core/SkGlyphCache.cpp

Issue 12706010: Add SkTypeface* parameter to SkScalerContext (and its callers) (Closed) Base URL: http://skia.googlecode.com/svn/
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « trunk/src/core/SkGlyphCache.h ('k') | trunk/src/core/SkPaint.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 /* 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 "SkGraphics.h" 11 #include "SkGraphics.h"
12 #include "SkPaint.h" 12 #include "SkPaint.h"
13 #include "SkPath.h" 13 #include "SkPath.h"
14 #include "SkTemplates.h" 14 #include "SkTemplates.h"
15 #include "SkTLS.h" 15 #include "SkTLS.h"
16 #include "SkTypeface.h"
16 17
17 //#define SPEW_PURGE_STATUS 18 //#define SPEW_PURGE_STATUS
18 //#define USE_CACHE_HASH 19 //#define USE_CACHE_HASH
19 //#define RECORD_HASH_EFFICIENCY 20 //#define RECORD_HASH_EFFICIENCY
20 21
21 bool gSkSuppressFontCachePurgeSpew; 22 bool gSkSuppressFontCachePurgeSpew;
22 23
23 /////////////////////////////////////////////////////////////////////////////// 24 ///////////////////////////////////////////////////////////////////////////////
24 25
25 #ifdef RECORD_HASH_EFFICIENCY 26 #ifdef RECORD_HASH_EFFICIENCY
(...skipping 19 matching lines...) Expand all
45 #endif 46 #endif
46 #define RecordHashCollision() RecordHashCollisionIf(true) 47 #define RecordHashCollision() RecordHashCollisionIf(true)
47 48
48 /////////////////////////////////////////////////////////////////////////////// 49 ///////////////////////////////////////////////////////////////////////////////
49 50
50 #define kMinGlphAlloc (sizeof(SkGlyph) * 64) 51 #define kMinGlphAlloc (sizeof(SkGlyph) * 64)
51 #define kMinImageAlloc (24 * 64) // should be pointsize-dependent 52 #define kMinImageAlloc (24 * 64) // should be pointsize-dependent
52 53
53 #define METRICS_RESERVE_COUNT 128 // so we don't grow this array a lot 54 #define METRICS_RESERVE_COUNT 128 // so we don't grow this array a lot
54 55
55 SkGlyphCache::SkGlyphCache(const SkDescriptor* desc) 56 SkGlyphCache::SkGlyphCache(SkTypeface* typeface, const SkDescriptor* desc)
56 : fGlyphAlloc(kMinGlphAlloc), fImageAlloc(kMinImageAlloc) { 57 : fGlyphAlloc(kMinGlphAlloc)
58 , fImageAlloc(kMinImageAlloc) {
59 SkASSERT(typeface);
60
57 fPrev = fNext = NULL; 61 fPrev = fNext = NULL;
58 62
59 fDesc = desc->copy(); 63 fDesc = desc->copy();
60 fScalerContext = SkScalerContext::Create(desc); 64 fScalerContext = typeface->createScalerContext(desc);
61 fScalerContext->getFontMetrics(NULL, &fFontMetricsY); 65 fScalerContext->getFontMetrics(NULL, &fFontMetricsY);
62 66
63 // init to 0 so that all of the pointers will be null 67 // init to 0 so that all of the pointers will be null
64 memset(fGlyphHash, 0, sizeof(fGlyphHash)); 68 memset(fGlyphHash, 0, sizeof(fGlyphHash));
65 // init with 0xFF so that the charCode field will be -1, which is invalid 69 // init with 0xFF so that the charCode field will be -1, which is invalid
66 memset(fCharToGlyphHash, 0xFF, sizeof(fCharToGlyphHash)); 70 memset(fCharToGlyphHash, 0xFF, sizeof(fCharToGlyphHash));
67 71
68 fMemoryUsed = sizeof(*this) + kMinGlphAlloc + kMinImageAlloc; 72 fMemoryUsed = sizeof(*this) + kMinGlphAlloc + kMinImageAlloc;
69 73
70 fGlyphArray.setReserve(METRICS_RESERVE_COUNT); 74 fGlyphArray.setReserve(METRICS_RESERVE_COUNT);
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 520
517 globals.validate(); 521 globals.validate();
518 } 522 }
519 523
520 /* This guy calls the visitor from within the mutext lock, so the visitor 524 /* This guy calls the visitor from within the mutext lock, so the visitor
521 cannot: 525 cannot:
522 - take too much time 526 - take too much time
523 - try to acquire the mutext again 527 - try to acquire the mutext again
524 - call a fontscaler (which might call into the cache) 528 - call a fontscaler (which might call into the cache)
525 */ 529 */
526 SkGlyphCache* SkGlyphCache::VisitCache(const SkDescriptor* desc, 530 SkGlyphCache* SkGlyphCache::VisitCache(SkTypeface* typeface,
531 const SkDescriptor* desc,
527 bool (*proc)(const SkGlyphCache*, void*), 532 bool (*proc)(const SkGlyphCache*, void*),
528 void* context) { 533 void* context) {
534 if (!typeface) {
535 typeface = SkTypeface::GetDefaultTypeface();
536 }
529 SkASSERT(desc); 537 SkASSERT(desc);
530 538
531 SkGlyphCache_Globals& globals = getGlobals(); 539 SkGlyphCache_Globals& globals = getGlobals();
532 SkAutoMutexAcquire ac(globals.fMutex); 540 SkAutoMutexAcquire ac(globals.fMutex);
533 SkGlyphCache* cache; 541 SkGlyphCache* cache;
534 bool insideMutex = true; 542 bool insideMutex = true;
535 543
536 globals.validate(); 544 globals.validate();
537 545
538 #ifdef USE_CACHE_HASH 546 #ifdef USE_CACHE_HASH
(...skipping 12 matching lines...) Expand all
551 goto FOUND_IT; 559 goto FOUND_IT;
552 } 560 }
553 } 561 }
554 562
555 /* Release the mutex now, before we create a new entry (which might have 563 /* Release the mutex now, before we create a new entry (which might have
556 side-effects like trying to access the cache/mutex (yikes!) 564 side-effects like trying to access the cache/mutex (yikes!)
557 */ 565 */
558 ac.release(); // release the mutex now 566 ac.release(); // release the mutex now
559 insideMutex = false; // can't use globals anymore 567 insideMutex = false; // can't use globals anymore
560 568
561 cache = SkNEW_ARGS(SkGlyphCache, (desc)); 569 cache = SkNEW_ARGS(SkGlyphCache, (typeface, desc));
562 570
563 FOUND_IT: 571 FOUND_IT:
564 572
565 AutoValidate av(cache); 573 AutoValidate av(cache);
566 574
567 if (proc(cache, context)) { // stay detached 575 if (proc(cache, context)) { // stay detached
568 if (insideMutex) { 576 if (insideMutex) {
569 SkASSERT(globals.fTotalMemoryUsed >= cache->fMemoryUsed); 577 SkASSERT(globals.fTotalMemoryUsed >= cache->fMemoryUsed);
570 globals.fTotalMemoryUsed -= cache->fMemoryUsed; 578 globals.fTotalMemoryUsed -= cache->fMemoryUsed;
571 #ifdef USE_CACHE_HASH 579 #ifdef USE_CACHE_HASH
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 return tls ? tls->getFontCacheLimit() : 0; 742 return tls ? tls->getFontCacheLimit() : 0;
735 } 743 }
736 744
737 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { 745 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) {
738 if (0 == bytes) { 746 if (0 == bytes) {
739 SkGlyphCache_Globals::DeleteTLS(); 747 SkGlyphCache_Globals::DeleteTLS();
740 } else { 748 } else {
741 SkGlyphCache_Globals::GetTLS().setFontCacheLimit(bytes); 749 SkGlyphCache_Globals::GetTLS().setFontCacheLimit(bytes);
742 } 750 }
743 } 751 }
OLDNEW
« no previous file with comments | « trunk/src/core/SkGlyphCache.h ('k') | trunk/src/core/SkPaint.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698