const Rec* curr = fArray.begin();
const Rec* stop = fArray.end();
while (curr < stop) {
- if (curr->fStrong) {
- curr->fFace->unref();
- } else {
- curr->fFace->weak_unref();
- }
+ curr->fFace->unref();
curr += 1;
}
}
-void SkTypefaceCache::add(SkTypeface* face,
- const SkFontStyle& requestedStyle,
- bool strong) {
+void SkTypefaceCache::add(SkTypeface* face, const SkFontStyle& requestedStyle) {
if (fArray.count() >= TYPEFACE_CACHE_LIMIT) {
this->purge(TYPEFACE_CACHE_LIMIT >> 2);
}
Rec* rec = fArray.append();
- rec->fFace = face;
+ rec->fFace = SkRef(face);
rec->fRequestedStyle = requestedStyle;
- rec->fStrong = strong;
- if (strong) {
- face->ref();
- } else {
- face->weak_ref();
- }
}
SkTypeface* SkTypefaceCache::findByID(SkFontID fontID) const {
while (curr < stop) {
SkTypeface* currFace = curr->fFace;
if (proc(currFace, curr->fRequestedStyle, ctx)) {
- if (curr->fStrong) {
- currFace->ref();
- return currFace;
- } else if (currFace->try_ref()) {
- return currFace;
- } else {
- //remove currFace from fArray?
- }
+ return SkRef(currFace);
}
curr += 1;
}
int i = 0;
while (i < count) {
SkTypeface* face = fArray[i].fFace;
- bool strong = fArray[i].fStrong;
- if ((strong && face->unique()) || (!strong && face->weak_expired())) {
- if (strong) {
- face->unref();
- } else {
- face->weak_unref();
- }
+ if (face->unique()) {
+ face->unref();
fArray.remove(i);
--count;
if (--numToPurge == 0) {
SK_DECLARE_STATIC_MUTEX(gMutex);
-void SkTypefaceCache::Add(SkTypeface* face,
- const SkFontStyle& requestedStyle,
- bool strong) {
+void SkTypefaceCache::Add(SkTypeface* face, const SkFontStyle& requestedStyle) {
SkAutoMutexAcquire ama(gMutex);
- Get().add(face, requestedStyle, strong);
+ Get().add(face, requestedStyle);
}
SkTypeface* SkTypefaceCache::FindByID(SkFontID fontID) {
* whose refcnt is 1 (meaning only the cache is an owner) will be
* unref()ed.
*/
- void add(SkTypeface*, const SkFontStyle& requested, bool strong = true);
+ void add(SkTypeface*, const SkFontStyle& requested);
/**
* Search the cache for a typeface with the specified fontID (uniqueID).
// These are static wrappers around a global instance of a cache.
- static void Add(SkTypeface*,
- const SkFontStyle& requested,
- bool strong = true);
+ static void Add(SkTypeface*, const SkFontStyle& requested);
static SkTypeface* FindByID(SkFontID fontID);
static SkTypeface* FindByProcAndRef(FindProc proc, void* ctx);
static void PurgeAll();
struct Rec {
SkTypeface* fFace;
- bool fStrong;
SkFontStyle fRequestedStyle;
};
SkTDArray<Rec> fArray;
SkTypeface* SkCreateFontMemResourceTypefaceFromLOGFONT(const LOGFONT& origLF, HANDLE fontMemResource) {
LOGFONT lf = origLF;
make_canonical(&lf);
- FontMemResourceTypeface* face = FontMemResourceTypeface::Create(lf, fontMemResource);
- SkTypefaceCache::Add(face, get_style(lf), false);
- return face;
+ // We'll never get a cache hit, so no point in putting this in SkTypefaceCache.
+ return FontMemResourceTypeface::Create(lf, fontMemResource);
}
/**