Bug 666414 - Part 2: Reference count the ANPTypeface type explicitly instead of piggybacking on nsRefPtr; r=dougt
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 26 Sep 2011 16:10:47 -0400
changeset 78895 35196c69cb12f5996d5681e6a8a577d7c3480546
parent 78894 489f9e746213f7d4ae2ac51b3a0fb672e211c462
child 78896 f2da319b3f6a660527bd3e7d45540af777ca523f
child 78921 2b866e479765e90a7217347657e64313683cb844
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdougt
bugs666414
milestone9.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 666414 - Part 2: Reference count the ANPTypeface type explicitly instead of piggybacking on nsRefPtr; r=dougt
dom/plugins/base/android/ANPBase.h
dom/plugins/base/android/ANPTypeface.cpp
--- a/dom/plugins/base/android/ANPBase.h
+++ b/dom/plugins/base/android/ANPBase.h
@@ -35,16 +35,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "android_npapi.h"
 #include <stdlib.h>
 #include "nsAutoPtr.h"
 #include "gfxFont.h"
+#include "nsISupportsImpl.h"
 
 #define NOT_IMPLEMENTED_FATAL() do {                                    \
     __android_log_print(ANDROID_LOG_ERROR, "GeckoPlugins",              \
                         "%s not implemented %s, %d",                    \
                         __PRETTY_FUNCTION__, __FILE__, __LINE__);       \
     abort();                                                            \
   } while(0)
 
@@ -64,17 +65,18 @@ void InitMatrixInterface(ANPMatrixInterf
 void InitPaintInterface(ANPPaintInterfaceV0 *i);
 void InitPathInterface(ANPPathInterfaceV0 *i);
 void InitSurfaceInterface(ANPSurfaceInterfaceV0 *i);
 void InitSystemInterface(ANPSystemInterfaceV0 *i);
 void InitTypeFaceInterface(ANPTypefaceInterfaceV0 *i);
 void InitWindowInterface(ANPWindowInterfaceV0 *i);
 
 struct ANPTypeface {
-  nsRefPtr<gfxFont> mFont;
+  gfxFont* mFont;
+  nsAutoRefCnt mRefCnt;
 };
 
 
 typedef struct {
   ANPMatrixFlag flags;
   ANPColor color;
   ANPPaintStyle style;
   float strokeWidth;
--- a/dom/plugins/base/android/ANPTypeface.cpp
+++ b/dom/plugins/base/android/ANPTypeface.cpp
@@ -56,17 +56,21 @@ anp_typeface_createFromName(const char n
                       16.0,
                       NS_NewPermanentAtom(NS_LITERAL_STRING("en")),
                       0.0,
                       PR_FALSE, PR_FALSE,
                       NS_LITERAL_STRING(""),
                       NS_LITERAL_STRING(""));
   ANPTypeface* tf = new ANPTypeface;
   gfxAndroidPlatform * p = (gfxAndroidPlatform*)gfxPlatform::GetPlatform();
-  tf->mFont = gfxFT2Font::GetOrMakeFont(NS_ConvertASCIItoUTF16(name), &style);
+  nsRefPtr<gfxFont> font = gfxFT2Font::GetOrMakeFont(NS_ConvertASCIItoUTF16(name), &style);
+  tf->mFont = font.forget();
+  if (tf->mFont) {
+    ++tf->mRefCnt;
+  }
   return tf;
 }
 
 ANPTypeface*
 anp_typeface_createFromTypeface(const ANPTypeface* family,
                                 ANPTypefaceStyle)
 {
   NOT_IMPLEMENTED();
@@ -80,26 +84,29 @@ anp_typeface_getRefCount(const ANPTypefa
   return 0;
 }
 
 void
 anp_typeface_ref(ANPTypeface* tf)
 {
   LOG("%s\n", __PRETTY_FUNCTION__);
   if (tf->mFont)
-    tf->mFont->AddRef();
+    ++tf->mRefCnt;
 
 }
 
 void
 anp_typeface_unref(ANPTypeface* tf)
 {
   LOG("%s\n", __PRETTY_FUNCTION__);
   if (tf->mFont)
-    tf->mFont->Release();
+    --tf->mRefCnt;
+  if (tf->mRefCnt.get() == 0) {
+    NS_IF_RELEASE(tf->mFont);
+  }
 }
 
 ANPTypefaceStyle
 anp_typeface_getStyle(const ANPTypeface* ft)
 {
   LOG("%s\n", __PRETTY_FUNCTION__);
   return kBold_ANPTypefaceStyle;
 }