OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
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 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 if (curr->fStrong) { | 22 if (curr->fStrong) { |
23 curr->fFace->unref(); | 23 curr->fFace->unref(); |
24 } else { | 24 } else { |
25 curr->fFace->weak_unref(); | 25 curr->fFace->weak_unref(); |
26 } | 26 } |
27 curr += 1; | 27 curr += 1; |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 void SkTypefaceCache::add(SkTypeface* face, | 31 void SkTypefaceCache::add(SkTypeface* face, |
32 SkTypeface::Style requestedStyle, | 32 const SkFontStyle& requestedStyle, |
33 bool strong) { | 33 bool strong) { |
34 if (fArray.count() >= TYPEFACE_CACHE_LIMIT) { | 34 if (fArray.count() >= TYPEFACE_CACHE_LIMIT) { |
35 this->purge(TYPEFACE_CACHE_LIMIT >> 2); | 35 this->purge(TYPEFACE_CACHE_LIMIT >> 2); |
36 } | 36 } |
37 | 37 |
38 Rec* rec = fArray.append(); | 38 Rec* rec = fArray.append(); |
39 rec->fFace = face; | 39 rec->fFace = face; |
40 rec->fRequestedStyle = requestedStyle; | 40 rec->fRequestedStyle = requestedStyle; |
41 rec->fStrong = strong; | 41 rec->fStrong = strong; |
42 if (strong) { | 42 if (strong) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 113 } |
114 | 114 |
115 SkFontID SkTypefaceCache::NewFontID() { | 115 SkFontID SkTypefaceCache::NewFontID() { |
116 static int32_t gFontID; | 116 static int32_t gFontID; |
117 return sk_atomic_inc(&gFontID) + 1; | 117 return sk_atomic_inc(&gFontID) + 1; |
118 } | 118 } |
119 | 119 |
120 SK_DECLARE_STATIC_MUTEX(gMutex); | 120 SK_DECLARE_STATIC_MUTEX(gMutex); |
121 | 121 |
122 void SkTypefaceCache::Add(SkTypeface* face, | 122 void SkTypefaceCache::Add(SkTypeface* face, |
123 SkTypeface::Style requestedStyle, | 123 const SkFontStyle& requestedStyle, |
124 bool strong) { | 124 bool strong) { |
125 SkAutoMutexAcquire ama(gMutex); | 125 SkAutoMutexAcquire ama(gMutex); |
126 Get().add(face, requestedStyle, strong); | 126 Get().add(face, requestedStyle, strong); |
127 } | 127 } |
128 | 128 |
129 SkTypeface* SkTypefaceCache::FindByID(SkFontID fontID) { | 129 SkTypeface* SkTypefaceCache::FindByID(SkFontID fontID) { |
130 SkAutoMutexAcquire ama(gMutex); | 130 SkAutoMutexAcquire ama(gMutex); |
131 return Get().findByID(fontID); | 131 return Get().findByID(fontID); |
132 } | 132 } |
133 | 133 |
134 SkTypeface* SkTypefaceCache::FindByProcAndRef(FindProc proc, void* ctx) { | 134 SkTypeface* SkTypefaceCache::FindByProcAndRef(FindProc proc, void* ctx) { |
135 SkAutoMutexAcquire ama(gMutex); | 135 SkAutoMutexAcquire ama(gMutex); |
136 SkTypeface* typeface = Get().findByProcAndRef(proc, ctx); | 136 SkTypeface* typeface = Get().findByProcAndRef(proc, ctx); |
137 return typeface; | 137 return typeface; |
138 } | 138 } |
139 | 139 |
140 void SkTypefaceCache::PurgeAll() { | 140 void SkTypefaceCache::PurgeAll() { |
141 SkAutoMutexAcquire ama(gMutex); | 141 SkAutoMutexAcquire ama(gMutex); |
142 Get().purgeAll(); | 142 Get().purgeAll(); |
143 } | 143 } |
144 | 144 |
145 /////////////////////////////////////////////////////////////////////////////// | 145 /////////////////////////////////////////////////////////////////////////////// |
146 | 146 |
147 #ifdef SK_DEBUG | 147 #ifdef SK_DEBUG |
148 static bool DumpProc(SkTypeface* face, SkTypeface::Style style, void* ctx) { | 148 static bool DumpProc(SkTypeface* face, const SkFontStyle& s, void* ctx) { |
149 SkDebugf("SkTypefaceCache: face %p fontID %d style %d refcnt %d\n", | 149 SkDebugf("SkTypefaceCache: face %p fontID %d weight %d width %d style %d ref
cnt %d\n", |
150 face, face->uniqueID(), style, face->getRefCnt()); | 150 face, face->uniqueID(), s.weight(), s.width(), s.slant(), face->get
RefCnt()); |
151 return false; | 151 return false; |
152 } | 152 } |
153 #endif | 153 #endif |
154 | 154 |
155 void SkTypefaceCache::Dump() { | 155 void SkTypefaceCache::Dump() { |
156 #ifdef SK_DEBUG | 156 #ifdef SK_DEBUG |
157 SkAutoMutexAcquire ama(gMutex); | 157 SkAutoMutexAcquire ama(gMutex); |
158 (void)Get().findByProcAndRef(DumpProc, NULL); | 158 (void)Get().findByProcAndRef(DumpProc, NULL); |
159 #endif | 159 #endif |
160 } | 160 } |
OLD | NEW |