aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-10-24 10:43:15 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-24 10:43:15 -0700
commit60b6e9dbbc492f987a5b887dff60aec107ab70d0 (patch)
tree1bfd910f9357522fd1ebd94c72cb348b665bd2a5
parent06cddec8570cbf29f89e89736afb0487b5b95abd (diff)
Remove a pointless use of SkWeakRefCnt.
Can't quite get rid of SkWeakRefCnt yet... SkFontMgr_indirect uses it to cache SkTypefaces, and I don't quite understand it enough yet to cut out the weak refs. BUG=skia:3065 Review URL: https://codereview.chromium.org/664173003
-rw-r--r--src/core/SkTypefaceCache.cpp42
-rw-r--r--src/core/SkTypefaceCache.h7
-rwxr-xr-xsrc/ports/SkFontHost_win.cpp5
-rw-r--r--src/ports/SkFontMgr_fontconfig.cpp2
-rw-r--r--src/ports/SkFontMgr_win_dw.cpp2
5 files changed, 14 insertions, 44 deletions
diff --git a/src/core/SkTypefaceCache.cpp b/src/core/SkTypefaceCache.cpp
index cfa301ef39..8adffe6a3a 100644
--- a/src/core/SkTypefaceCache.cpp
+++ b/src/core/SkTypefaceCache.cpp
@@ -19,31 +19,19 @@ SkTypefaceCache::~SkTypefaceCache() {
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 {
@@ -64,14 +52,7 @@ SkTypeface* SkTypefaceCache::findByProcAndRef(FindProc proc, void* ctx) 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;
}
@@ -83,13 +64,8 @@ void SkTypefaceCache::purge(int numToPurge) {
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) {
@@ -119,11 +95,9 @@ SkFontID SkTypefaceCache::NewFontID() {
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) {
diff --git a/src/core/SkTypefaceCache.h b/src/core/SkTypefaceCache.h
index ba851ee0b6..c6b433dead 100644
--- a/src/core/SkTypefaceCache.h
+++ b/src/core/SkTypefaceCache.h
@@ -39,7 +39,7 @@ public:
* 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).
@@ -72,9 +72,7 @@ public:
// 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();
@@ -91,7 +89,6 @@ private:
struct Rec {
SkTypeface* fFace;
- bool fStrong;
SkFontStyle fRequestedStyle;
};
SkTDArray<Rec> fArray;
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index 348246b893..89bac5daf4 100755
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -338,9 +338,8 @@ SkTypeface* SkCreateTypefaceFromLOGFONT(const LOGFONT& origLF) {
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);
}
/**
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index 6ec5604af4..d7570d9354 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -583,7 +583,7 @@ class SkFontMgr_fontconfig : public SkFontMgr {
FcPatternReference(pattern);
face = SkTypeface_fontconfig::Create(pattern);
if (face) {
- fTFCache.add(face, SkFontStyle(), true);
+ fTFCache.add(face, SkFontStyle());
}
}
return face;
diff --git a/src/ports/SkFontMgr_win_dw.cpp b/src/ports/SkFontMgr_win_dw.cpp
index e9d494f514..f5bf85d3ae 100644
--- a/src/ports/SkFontMgr_win_dw.cpp
+++ b/src/ports/SkFontMgr_win_dw.cpp
@@ -435,7 +435,7 @@ SkTypeface* SkFontMgr_DirectWrite::createTypefaceFromDWriteFont(
if (NULL == face) {
face = DWriteFontTypeface::Create(fFactory.get(), fontFace, font, fontFamily);
if (face) {
- fTFCache.add(face, get_style(font), true);
+ fTFCache.add(face, get_style(font));
}
}
return face;