Bug 1257121 part 5 - Make nsDeviceContext::mFontCache a RefPtr.
MozReview-Commit-ID: JaVobbNX9eS
--- 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
};