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 |
11 #include "SkTypefaceCache.h" | 11 #include "SkTypefaceCache.h" |
12 #include "SkThread.h" | 12 #include "SkThread.h" |
13 | 13 |
14 #define TYPEFACE_CACHE_LIMIT 1024 | 14 #define TYPEFACE_CACHE_LIMIT 1024 |
15 | 15 |
| 16 SkTypefaceCache::SkTypefaceCache() {} |
| 17 |
| 18 SkTypefaceCache::~SkTypefaceCache() { |
| 19 const Rec* curr = fArray.begin(); |
| 20 const Rec* stop = fArray.end(); |
| 21 while (curr < stop) { |
| 22 if (curr->fStrong) { |
| 23 curr->fFace->unref(); |
| 24 } else { |
| 25 curr->fFace->weak_unref(); |
| 26 } |
| 27 curr += 1; |
| 28 } |
| 29 } |
| 30 |
16 void SkTypefaceCache::add(SkTypeface* face, | 31 void SkTypefaceCache::add(SkTypeface* face, |
17 SkTypeface::Style requestedStyle, | 32 SkTypeface::Style requestedStyle, |
18 bool strong) { | 33 bool strong) { |
19 if (fArray.count() >= TYPEFACE_CACHE_LIMIT) { | 34 if (fArray.count() >= TYPEFACE_CACHE_LIMIT) { |
20 this->purge(TYPEFACE_CACHE_LIMIT >> 2); | 35 this->purge(TYPEFACE_CACHE_LIMIT >> 2); |
21 } | 36 } |
22 | 37 |
23 Rec* rec = fArray.append(); | 38 Rec* rec = fArray.append(); |
24 rec->fFace = face; | 39 rec->fFace = face; |
25 rec->fRequestedStyle = requestedStyle; | 40 rec->fRequestedStyle = requestedStyle; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 return false; | 151 return false; |
137 } | 152 } |
138 #endif | 153 #endif |
139 | 154 |
140 void SkTypefaceCache::Dump() { | 155 void SkTypefaceCache::Dump() { |
141 #ifdef SK_DEBUG | 156 #ifdef SK_DEBUG |
142 SkAutoMutexAcquire ama(gMutex); | 157 SkAutoMutexAcquire ama(gMutex); |
143 (void)Get().findByProcAndRef(DumpProc, NULL); | 158 (void)Get().findByProcAndRef(DumpProc, NULL); |
144 #endif | 159 #endif |
145 } | 160 } |
OLD | NEW |