b=454735 Make gfxFont more tolerant to shutdown of the gfxFontCache r=roc
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 16 Sep 2008 16:35:05 +1200
changeset 19287 f51aad9e6a88703c2d22f8fd525ecea06c96ab34
parent 19286 31585e357fa3fd6a83568539b56ff30a59487c60
child 19288 b3ac8c986c848f5619b57d1a68b6aa16f2663f20
child 19409 118ab5caf67dcf39de83014ca5e95b1a8cd62bdb
push id2093
push userktomlinson@mozilla.com
push dateTue, 16 Sep 2008 04:36:42 +0000
treeherdermozilla-central@f51aad9e6a88 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs454735
milestone1.9.1b1pre
b=454735 Make gfxFont more tolerant to shutdown of the gfxFontCache r=roc
gfx/thebes/public/gfxFont.h
--- a/gfx/thebes/public/gfxFont.h
+++ b/gfx/thebes/public/gfxFont.h
@@ -449,31 +449,41 @@ public:
         NS_LOG_ADDREF(this, mRefCnt, "gfxFont", sizeof(*this));
         return mRefCnt;
     }
     nsrefcnt Release(void) {
         NS_PRECONDITION(0 != mRefCnt, "dup release");
         --mRefCnt;
         NS_LOG_RELEASE(this, mRefCnt, "gfxFont");
         if (mRefCnt == 0) {
-            // Don't delete just yet; return the object to the cache for
-            // possibly recycling within some time limit
-            gfxFontCache::GetCache()->NotifyReleased(this);
-            return 0;
+            NotifyReleased();
         }
         return mRefCnt;
     }
 
     PRInt32 GetRefCount() { return mRefCnt; }
 
 protected:
     nsAutoRefCnt mRefCnt;
 
+    void NotifyReleased() {
+        gfxFontCache *cache = gfxFontCache::GetCache();
+        if (cache) {
+            // Don't delete just yet; return the object to the cache for
+            // possibly recycling within some time limit
+            cache->NotifyReleased(this);
+        } else {
+            // The cache may have already been shut down.
+            delete this;
+        }
+    }
+
+    gfxFont(gfxFontEntry *aFontEntry, const gfxFontStyle *aFontStyle);
+
 public:
-    gfxFont(gfxFontEntry *aFontEntry, const gfxFontStyle *aFontStyle);
     virtual ~gfxFont();
 
     const nsString& GetName() const { return mFontEntry->Name(); }
     const gfxFontStyle *GetStyle() const { return &mStyle; }
 
     virtual nsString GetUniqueName() = 0;
 
     // Font metrics
@@ -632,17 +642,16 @@ public:
         if (!mIsValid)
             return PR_FALSE;
         return mFontEntry->HasCharacter(ch); 
     }
 
 protected:
     nsRefPtr<gfxFontEntry> mFontEntry;
 
-    // The family name of the font
     PRPackedBool               mIsValid;
     nsExpirationState          mExpirationState;
     gfxFontStyle               mStyle;
     nsAutoTArray<gfxGlyphExtents*,1> mGlyphExtentsArray;
 
     // synthetic bolding for environments where this is not supported by the platform
     PRUint32                   mSyntheticBoldOffset;  // number of devunit pixels to offset double-strike, 0 ==> no bolding
 
@@ -1475,19 +1484,20 @@ private:
     nsExpirationState mExpirationState;
     PRUint32          mAppUnitsPerDevUnit;
     PRUint32          mFlags;
     PRUint32          mCharacterCount;
     PRUint32          mHashCode;
 };
 
 class THEBES_API gfxFontGroup : public gfxTextRunFactory {
-public:
+protected:
     gfxFontGroup(const nsAString& aFamilies, const gfxFontStyle *aStyle);
 
+public:
     virtual ~gfxFontGroup() {
         mFonts.Clear();
     }
 
     virtual gfxFont *GetFontAt(PRInt32 i) {
         return static_cast<gfxFont*>(mFonts[i]);
     }
     virtual PRUint32 FontListLength() const {