Bug 1022821, part 2 - In gfx code, stop returning RefPtr and, where not an out-param, stop using RefPtr arguments. r=Cwiiis
☠☠ backed out by 8b34896e9109 ☠ ☠
authorJonathan Watt <jwatt@jwatt.org>
Thu, 12 Jun 2014 12:33:12 +0100
changeset 202239 cd50c7187a48fe35406c5854800bc85b6e161c44
parent 202238 1b9c61ae1688f8f65437f15a759b96533ebe46b1
child 202240 8b34896e9109d4ac82b50bbd121ab4b071fc78da
push idunknown
push userunknown
push dateunknown
reviewersCwiiis
bugs1022821
milestone33.0a1
Bug 1022821, part 2 - In gfx code, stop returning RefPtr and, where not an out-param, stop using RefPtr arguments. r=Cwiiis
gfx/thebes/gfxPattern.cpp
gfx/thebes/gfxPattern.h
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxUtils.cpp
gfx/thebes/gfxUtils.h
--- a/gfx/thebes/gfxPattern.cpp
+++ b/gfx/thebes/gfxPattern.cpp
@@ -93,17 +93,17 @@ gfxPattern::AddColorStop(gfxFloat offset
                                           cms.r, cms.g, cms.b, c.a);
     }
     else
         cairo_pattern_add_color_stop_rgba(mPattern, offset, c.r, c.g, c.b, c.a);
   }
 }
 
 void
-gfxPattern::SetColorStops(mozilla::RefPtr<GradientStops> aStops)
+gfxPattern::SetColorStops(GradientStops* aStops)
 {
   mStops = aStops;
 }
 
 void
 gfxPattern::CacheColorStops(DrawTarget *aDT)
 {
   if (mPattern) {
--- a/gfx/thebes/gfxPattern.h
+++ b/gfx/thebes/gfxPattern.h
@@ -33,17 +33,17 @@ public:
     gfxPattern(gfxFloat x0, gfxFloat y0, gfxFloat x1, gfxFloat y1); // linear
     gfxPattern(gfxFloat cx0, gfxFloat cy0, gfxFloat radius0,
                gfxFloat cx1, gfxFloat cy1, gfxFloat radius1); // radial
     gfxPattern(mozilla::gfx::SourceSurface *aSurface,
                const mozilla::gfx::Matrix &aTransform); // Azure
 
     cairo_pattern_t *CairoPattern();
     void AddColorStop(gfxFloat offset, const gfxRGBA& c);
-    void SetColorStops(mozilla::RefPtr<mozilla::gfx::GradientStops> aStops);
+    void SetColorStops(mozilla::gfx::GradientStops* aStops);
 
     // This should only be called on a cairo pattern that we want to use with
     // Azure. We will read back the color stops from cairo and try to look
     // them up in the cache.
     void CacheColorStops(mozilla::gfx::DrawTarget *aDT);
 
     void SetMatrix(const gfxMatrix& matrix);
     gfxMatrix GetMatrix() const;
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -529,29 +529,29 @@ gfxPlatform::~gfxPlatform()
 #if MOZ_TREE_CAIRO
     cairo_debug_reset_static_data();
 #endif
 #endif
 }
 
 cairo_user_data_key_t kDrawTarget;
 
-RefPtr<DrawTarget>
+TemporaryRef<DrawTarget>
 gfxPlatform::CreateDrawTargetForSurface(gfxASurface *aSurface, const IntSize& aSize)
 {
   SurfaceFormat format = Optimal2DFormatForContent(aSurface->GetContentType());
   RefPtr<DrawTarget> drawTarget = Factory::CreateDrawTargetForCairoSurface(aSurface->CairoSurface(), aSize, &format);
   aSurface->SetData(&kDrawTarget, drawTarget, nullptr);
-  return drawTarget;
+  return drawTarget.forget();
 }
 
 // This is a temporary function used by ContentClient to build a DrawTarget
 // around the gfxASurface. This should eventually be replaced by plumbing
 // the DrawTarget through directly
-RefPtr<DrawTarget>
+TemporaryRef<DrawTarget>
 gfxPlatform::CreateDrawTargetForUpdateSurface(gfxASurface *aSurface, const IntSize& aSize)
 {
 #ifdef XP_MACOSX
   // this is a bit of a hack that assumes that the buffer associated with the CGContext
   // will live around long enough that nothing bad will happen.
   if (aSurface->GetType() == gfxSurfaceType::Quartz) {
     return Factory::CreateDrawTargetForCairoCGContext(static_cast<gfxQuartzSurface*>(aSurface)->GetCGContext(), aSize);
   }
@@ -638,17 +638,17 @@ CopySurface(gfxASurface* aSurface)
   ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
   ctx->Paint();
 
   data->Unmap();
 
   return data;
 }
 
-/* static */ RefPtr<SourceSurface>
+/* static */ TemporaryRef<SourceSurface>
 gfxPlatform::GetSourceSurfaceForSurface(DrawTarget *aTarget, gfxASurface *aSurface)
 {
   if (!aSurface->CairoSurface() || aSurface->CairoStatus()) {
     return nullptr;
   }
 
   if (!aTarget) {
     if (gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget()) {
@@ -704,17 +704,17 @@ gfxPlatform::GetSourceSurfaceForSurface(
     surf.mType = NativeSurfaceType::CAIRO_SURFACE;
     surf.mSurface = aSurface->CairoSurface();
     surf.mSize = ToIntSize(aSurface->GetSize());
     srcBuffer = aTarget->CreateSourceSurfaceFromNativeSurface(surf);
 
     if (srcBuffer) {
       // It's cheap enough to make a new one so we won't keep it around and
       // keeping it creates a cycle.
-      return srcBuffer;
+      return srcBuffer.forget();
     }
   }
 
   if (!srcBuffer) {
     nsRefPtr<gfxImageSurface> imgSurface = aSurface->GetAsImageSurface();
 
     RefPtr<DataSourceSurface> dataSurf;
 
@@ -729,30 +729,30 @@ gfxPlatform::GetSourceSurfaceForSurface(
     }
 
     srcBuffer = aTarget->OptimizeSourceSurface(dataSurf);
 
     if (imgSurface && srcBuffer == dataSurf) {
       // Our wrapping surface will hold a reference to its image surface. We cause
       // a reference cycle if we add it to the cache. And caching it is pretty
       // pointless since we'll just wrap it again next use.
-     return srcBuffer;
+     return srcBuffer.forget();
     }
   }
 
   // Add user data to aSurface so we can cache lookups in the future.
   SourceSurfaceUserData *srcSurfUD = new SourceSurfaceUserData;
   srcSurfUD->mBackendType = aTarget->GetType();
   srcSurfUD->mSrcSurface = srcBuffer;
   aSurface->SetData(&kSourceSurface, srcSurfUD, SourceBufferDestroy);
 
-  return srcBuffer;
+  return srcBuffer.forget();
 }
 
-RefPtr<DataSourceSurface>
+TemporaryRef<DataSourceSurface>
 gfxPlatform::GetWrappedDataSourceSurface(gfxASurface* aSurface)
 {
   nsRefPtr<gfxImageSurface> image = aSurface->GetAsImageSurface();
   if (!image) {
     return nullptr;
   }
   RefPtr<DataSourceSurface> result =
     Factory::CreateWrappingDataSourceSurface(image->Data(),
@@ -765,17 +765,17 @@ gfxPlatform::GetWrappedDataSourceSurface
   }
 
   // If we wrapped the underlying data of aSurface, then we need to add user data
   // to make sure aSurface stays alive until we are done with the data.
   DependentSourceSurfaceUserData *srcSurfUD = new DependentSourceSurfaceUserData;
   srcSurfUD->mSurface = aSurface;
   result->AddUserData(&kThebesSurface, srcSurfUD, SourceSurfaceDestroyed);
 
-  return result;
+  return result.forget();
 }
 
 TemporaryRef<ScaledFont>
 gfxPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont)
 {
   NativeFont nativeFont;
   nativeFont.mType = NativeFontType::CAIRO_FONT_FACE;
   nativeFont.mFont = aFont->GetCairoScaledFont();
@@ -922,17 +922,17 @@ gfxPlatform::GetThebesSurfaceForDrawTarg
   surf->SetData(&kDrawSourceSurface, data.forget().drop(), DataSourceSurfaceDestroy);
   // keep the draw target alive as long as we need its data
   aTarget->AddRef();
   surf->SetData(&kDrawTargetForSurface, aTarget, DataDrawTargetDestroy);
 
   return surf.forget();
 }
 
-RefPtr<DrawTarget>
+TemporaryRef<DrawTarget>
 gfxPlatform::CreateDrawTargetForBackend(BackendType aBackend, const IntSize& aSize, SurfaceFormat aFormat)
 {
   // There is a bunch of knowledge in the gfxPlatform heirarchy about how to
   // create the best offscreen surface for the current system and situation. We
   // can easily take advantage of this for the Cairo backend, so that's what we
   // do.
   // mozilla::gfx::Factory can get away without having all this knowledge for
   // now, but this might need to change in the future (using
@@ -946,37 +946,37 @@ gfxPlatform::CreateDrawTargetForBackend(
     }
 
     return CreateDrawTargetForSurface(surf, aSize);
   } else {
     return Factory::CreateDrawTarget(aBackend, aSize, aFormat);
   }
 }
 
-RefPtr<DrawTarget>
+TemporaryRef<DrawTarget>
 gfxPlatform::CreateOffscreenCanvasDrawTarget(const IntSize& aSize, SurfaceFormat aFormat)
 {
   NS_ASSERTION(mPreferredCanvasBackend != BackendType::NONE, "No backend.");
   RefPtr<DrawTarget> target = CreateDrawTargetForBackend(mPreferredCanvasBackend, aSize, aFormat);
   if (target ||
       mFallbackCanvasBackend == BackendType::NONE) {
-    return target;
+    return target.forget();
   }
 
   return CreateDrawTargetForBackend(mFallbackCanvasBackend, aSize, aFormat);
 }
 
-RefPtr<DrawTarget>
+TemporaryRef<DrawTarget>
 gfxPlatform::CreateOffscreenContentDrawTarget(const IntSize& aSize, SurfaceFormat aFormat)
 {
   NS_ASSERTION(mPreferredCanvasBackend != BackendType::NONE, "No backend.");
   return CreateDrawTargetForBackend(mContentBackend, aSize, aFormat);
 }
 
-RefPtr<DrawTarget>
+TemporaryRef<DrawTarget>
 gfxPlatform::CreateDrawTargetForData(unsigned char* aData, const IntSize& aSize, int32_t aStride, SurfaceFormat aFormat)
 {
   NS_ASSERTION(mContentBackend != BackendType::NONE, "No backend.");
   if (mContentBackend == BackendType::CAIRO) {
     nsRefPtr<gfxImageSurface> image = new gfxImageSurface(aData, gfxIntSize(aSize.width, aSize.height), aStride, SurfaceFormatToImageFormat(aFormat));
     return Factory::CreateDrawTargetForCairoSurface(image->CairoSurface(), aSize);
   }
   return Factory::CreateDrawTargetForData(mContentBackend, aData, aSize, aStride, aFormat);
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -150,17 +150,20 @@ GetBackendName(mozilla::gfx::BackendType
       case mozilla::gfx::BackendType::NONE:
         return "none";
   }
   MOZ_CRASH("Incomplete switch");
 }
 
 class gfxPlatform {
 public:
+    typedef mozilla::gfx::DataSourceSurface DataSourceSurface;
+    typedef mozilla::gfx::DrawTarget DrawTarget;
     typedef mozilla::gfx::IntSize IntSize;
+    typedef mozilla::gfx::SourceSurface SourceSurface;
 
     /**
      * Return a pointer to the current active platform.
      * This is a singleton; it contains mostly convenience
      * functions to obtain platform-specific objects.
      */
     static gfxPlatform *GetPlatform();
 
@@ -182,55 +185,55 @@ public:
     /**
      * Beware that these methods may return DrawTargets which are not fully supported
      * on the current platform and might fail silently in subtle ways. This is a massive
      * potential footgun. You should only use these methods for canvas drawing really.
      * Use extreme caution if you use them for content where you are not 100% sure we
      * support the DrawTarget we get back.
      * See SupportsAzureContentForDrawTarget.
      */
-    virtual mozilla::RefPtr<mozilla::gfx::DrawTarget>
+    virtual mozilla::TemporaryRef<DrawTarget>
       CreateDrawTargetForSurface(gfxASurface *aSurface, const mozilla::gfx::IntSize& aSize);
 
-    virtual mozilla::RefPtr<mozilla::gfx::DrawTarget>
+    virtual mozilla::TemporaryRef<DrawTarget>
       CreateDrawTargetForUpdateSurface(gfxASurface *aSurface, const mozilla::gfx::IntSize& aSize);
 
     /*
      * Creates a SourceSurface for a gfxASurface. This function does no caching,
      * so the caller should cache the gfxASurface if it will be used frequently.
      * The returned surface keeps a reference to aTarget, so it is OK to keep the
      * surface, even if aTarget changes.
      * aTarget should not keep a reference to the returned surface because that
      * will cause a cycle.
      *
      * This function is static so that it can be accessed from
      * PluginInstanceChild (where we can't call gfxPlatform::GetPlatform()
      * because the prefs service can only be accessed from the main process).
      */
-    static mozilla::RefPtr<mozilla::gfx::SourceSurface>
+    static mozilla::TemporaryRef<SourceSurface>
       GetSourceSurfaceForSurface(mozilla::gfx::DrawTarget *aTarget, gfxASurface *aSurface);
 
     static void ClearSourceSurfaceForSurface(gfxASurface *aSurface);
 
-    static mozilla::RefPtr<mozilla::gfx::DataSourceSurface>
+    static mozilla::TemporaryRef<DataSourceSurface>
         GetWrappedDataSourceSurface(gfxASurface *aSurface);
 
     virtual mozilla::TemporaryRef<mozilla::gfx::ScaledFont>
       GetScaledFontForFont(mozilla::gfx::DrawTarget* aTarget, gfxFont *aFont);
 
     virtual already_AddRefed<gfxASurface>
       GetThebesSurfaceForDrawTarget(mozilla::gfx::DrawTarget *aTarget);
 
-    mozilla::RefPtr<mozilla::gfx::DrawTarget>
+    mozilla::TemporaryRef<DrawTarget>
       CreateOffscreenContentDrawTarget(const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat);
 
-    mozilla::RefPtr<mozilla::gfx::DrawTarget>
+    mozilla::TemporaryRef<DrawTarget>
       CreateOffscreenCanvasDrawTarget(const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat);
 
-    virtual mozilla::RefPtr<mozilla::gfx::DrawTarget>
+    virtual mozilla::TemporaryRef<DrawTarget>
       CreateDrawTargetForData(unsigned char* aData, const mozilla::gfx::IntSize& aSize, 
                               int32_t aStride, mozilla::gfx::SurfaceFormat aFormat);
 
     /**
      * Returns true if we should use Azure to render content with aTarget. For
      * example, it is possible that we are using Direct2D for rendering and thus
      * using Azure. But we want to render to a CairoDrawTarget, in which case
      * SupportsAzureContent will return true but SupportsAzureContentForDrawTarget
@@ -552,17 +555,17 @@ protected:
 
     void AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], uint32_t &aLen, 
                             eFontPrefLang aCharLang, eFontPrefLang aPageLang);
 
     /**
      * Helper method, creates a draw target for a specific Azure backend.
      * Used by CreateOffscreenDrawTarget.
      */
-    mozilla::RefPtr<mozilla::gfx::DrawTarget>
+    mozilla::TemporaryRef<DrawTarget>
       CreateDrawTargetForBackend(mozilla::gfx::BackendType aBackend,
                                  const mozilla::gfx::IntSize& aSize,
                                  mozilla::gfx::SurfaceFormat aFormat);
 
     /**
      * Initialise the preferred and fallback canvas backends
      * aBackendBitmask specifies the backends which are acceptable to the caller.
      * The backend used is determined by aBackendBitmask and the order specified
--- a/gfx/thebes/gfxUtils.cpp
+++ b/gfx/thebes/gfxUtils.cpp
@@ -960,43 +960,43 @@ gfxUtils::CopyAsDataURL(DrawTarget* aDT)
   if (surf) {
     surf->CopyAsDataURL();
   } else {
     NS_WARNING("Failed to get Thebes surface!");
   }
 }
 
 /* static */ void
-gfxUtils::WriteAsPNG(RefPtr<gfx::SourceSurface> aSourceSurface, const char* aFile)
+gfxUtils::WriteAsPNG(gfx::SourceSurface* aSourceSurface, const char* aFile)
 {
   RefPtr<gfx::DataSourceSurface> dataSurface = aSourceSurface->GetDataSurface();
   RefPtr<gfx::DrawTarget> dt
             = gfxPlatform::GetPlatform()
                 ->CreateDrawTargetForData(dataSurface->GetData(),
                                           dataSurface->GetSize(),
                                           dataSurface->Stride(),
                                           aSourceSurface->GetFormat());
   gfxUtils::WriteAsPNG(dt.get(), aFile);
 }
 
 /* static */ void
-gfxUtils::DumpAsDataURL(RefPtr<gfx::SourceSurface> aSourceSurface)
+gfxUtils::DumpAsDataURL(gfx::SourceSurface* aSourceSurface)
 {
   RefPtr<gfx::DataSourceSurface> dataSurface = aSourceSurface->GetDataSurface();
   RefPtr<gfx::DrawTarget> dt
             = gfxPlatform::GetPlatform()
                 ->CreateDrawTargetForData(dataSurface->GetData(),
                                           dataSurface->GetSize(),
                                           dataSurface->Stride(),
                                           aSourceSurface->GetFormat());
   gfxUtils::DumpAsDataURL(dt.get());
 }
 
 /* static */ void
-gfxUtils::CopyAsDataURL(RefPtr<gfx::SourceSurface> aSourceSurface)
+gfxUtils::CopyAsDataURL(gfx::SourceSurface* aSourceSurface)
 {
   RefPtr<gfx::DataSourceSurface> dataSurface = aSourceSurface->GetDataSurface();
   RefPtr<gfx::DrawTarget> dt
             = gfxPlatform::GetPlatform()
                 ->CreateDrawTargetForData(dataSurface->GetData(),
                                           dataSurface->GetSize(),
                                           dataSurface->Stride(),
                                           aSourceSurface->GetFormat());
--- a/gfx/thebes/gfxUtils.h
+++ b/gfx/thebes/gfxUtils.h
@@ -235,29 +235,29 @@ public:
     static bool sDumpPainting;
     static bool sDumpPaintingToFile;
     static FILE* sDumpPaintFile;
 
     /**
      * Writes a binary PNG file.
      * Expensive. Creates a DataSourceSurface, then a DrawTarget, then passes to DrawTarget overloads
      */
-    static void WriteAsPNG(mozilla::RefPtr<mozilla::gfx::SourceSurface> aSourceSurface, const char* aFile);
+    static void WriteAsPNG(mozilla::gfx::SourceSurface* aSourceSurface, const char* aFile);
 
     /**
      * Write as a PNG encoded Data URL to stdout.
      * Expensive. Creates a DataSourceSurface, then a DrawTarget, then passes to DrawTarget overloads
      */
-    static void DumpAsDataURL(mozilla::RefPtr<mozilla::gfx::SourceSurface> aSourceSurface);
+    static void DumpAsDataURL(mozilla::gfx::SourceSurface* aSourceSurface);
 
     /**
      * Copy a PNG encoded Data URL to the clipboard.
      * Expensive. Creates a DataSourceSurface, then a DrawTarget, then passes to DrawTarget overloads
      */
-    static void CopyAsDataURL(mozilla::RefPtr<mozilla::gfx::SourceSurface> aSourceSurface);
+    static void CopyAsDataURL(mozilla::gfx::SourceSurface* aSourceSurface);
 #endif
 };
 
 namespace mozilla {
 namespace gfx {
 
 
 /* These techniques are suggested by "Bit Twiddling Hacks"