b=454735 Make gfxFont more tolerant to shutdown of the gfxFontCache r=roc
authorKarl Tomlinson <karlt+@karlt.net>
Mon, 22 Sep 2008 08:41:40 +1200
changeset 19479 33c4f7ef21742d139ff3b075f7af4697b16330fb
parent 19478 6b38ceafa9adb18873fc100f42b5c13dc4344871
child 19480 7bfd2ee7016fcf5886ee0a8bdcd40d3e348a84ac
push id2267
push userktomlinson@mozilla.com
push dateSun, 21 Sep 2008 20:41:52 +0000
treeherdermozilla-central@33c4f7ef2174 [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,43 @@ 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);
+            NotifyReleased();
+            // |this| may have been deleted.
             return 0;
         }
         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 +644,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 +1486,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 {