Bug 1257121 part 5 - Make nsDeviceContext::mFontCache a RefPtr. r=jfkthame
authorXidorn Quan <quanxunzhen@gmail.com>
Thu, 17 Mar 2016 18:10:03 +0800
changeset 289639 c8b6ae5094f8733a2071a49d8590d341c5988a27
parent 289638 8ae38f8e1def584f4d76413e48534ec0827dee55
child 289640 f835f8fde27da0129710d264584a2530c1118abf
push id30108
push usercbook@mozilla.com
push dateTue, 22 Mar 2016 11:14:31 +0000
treeherdermozilla-central@ea6298e1b4f7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1257121
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1257121 part 5 - Make nsDeviceContext::mFontCache a RefPtr. r=jfkthame MozReview-Commit-ID: JaVobbNX9eS
gfx/src/nsDeviceContext.cpp
gfx/src/nsDeviceContext.h
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -198,40 +198,34 @@ nsFontCache::Flush()
     }
     mFontMetrics.Clear();
 }
 
 nsDeviceContext::nsDeviceContext()
     : mWidth(0), mHeight(0), mDepth(0),
       mAppUnitsPerDevPixel(-1), mAppUnitsPerDevPixelAtUnitFullZoom(-1),
       mAppUnitsPerPhysicalInch(-1),
-      mFullZoom(1.0f), mPrintingScale(1.0f),
-      mFontCache(nullptr)
+      mFullZoom(1.0f), mPrintingScale(1.0f)
 {
     MOZ_ASSERT(NS_IsMainThread(), "nsDeviceContext created off main thread");
 }
 
-// Note: we use a bare pointer for mFontCache so that nsFontCache
-// can be an incomplete type in nsDeviceContext.h.
-// Therefore we have to do all the refcounting by hand.
 nsDeviceContext::~nsDeviceContext()
 {
     if (mFontCache) {
         mFontCache->Destroy();
-        NS_RELEASE(mFontCache);
     }
 }
 
 already_AddRefed<nsFontMetrics>
 nsDeviceContext::GetMetricsFor(const nsFont& aFont,
                                const nsFontMetrics::Params& aParams)
 {
     if (!mFontCache) {
         mFontCache = new nsFontCache();
-        NS_ADDREF(mFontCache);
         mFontCache->Init(this);
     }
 
     return mFontCache->GetMetricsFor(aFont, aParams);
 }
 
 nsresult
 nsDeviceContext::FlushFontCache(void)
--- a/gfx/src/nsDeviceContext.h
+++ b/gfx/src/nsDeviceContext.h
@@ -262,17 +262,17 @@ private:
     nscoord  mHeight;
     uint32_t mDepth;
     int32_t  mAppUnitsPerDevPixel;
     int32_t  mAppUnitsPerDevPixelAtUnitFullZoom;
     int32_t  mAppUnitsPerPhysicalInch;
     float    mFullZoom;
     float    mPrintingScale;
 
-    nsFontCache*                   mFontCache;
+    RefPtr<nsFontCache>            mFontCache;
     nsCOMPtr<nsIWidget>            mWidget;
     nsCOMPtr<nsIScreenManager>     mScreenManager;
     nsCOMPtr<nsIDeviceContextSpec> mDeviceContextSpec;
     RefPtr<gfxASurface>          mPrintingSurface;
 #ifdef XP_MACOSX
     RefPtr<gfxASurface>          mCachedPrintingSurface;
 #endif
 };