Bug 1116622 - Give TemporaryRef a take() method semantically equivalent to already_AddRefed::take(); r=froydnj
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 30 Dec 2014 18:42:48 -0500
changeset 249554 36233e18f670f32db041d77cb795162e07a94890
parent 249553 8afa48feba29925f22cdf4578ccef926c74f7739
child 249555 69c16464fa30692f095e07c727c3aa1f6472a682
push id698
push userjlund@mozilla.com
push dateMon, 23 Mar 2015 22:08:11 +0000
treeherdermozilla-release@b0c0ae7b02a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1116622
milestone37.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 1116622 - Give TemporaryRef a take() method semantically equivalent to already_AddRefed::take(); r=froydnj This is in preparation of removing TemporaryRef. It should help make already_AddRefed a drop-in replacement for it.
dom/base/ImageEncoder.cpp
gfx/2d/DrawTargetCairo.cpp
gfx/layers/ImageContainer.cpp
gfx/layers/ipc/SharedPlanarYCbCrImage.cpp
gfx/layers/ipc/SharedRGBImage.cpp
layout/generic/nsCanvasFrame.cpp
media/webrtc/signaling/test/mediaconduit_unittests.cpp
mfbt/RefPtr.h
widget/cocoa/nsCocoaUtils.mm
--- a/dom/base/ImageEncoder.cpp
+++ b/dom/base/ImageEncoder.cpp
@@ -23,17 +23,17 @@ class SurfaceHelper : public nsRunnable 
 public:
   explicit SurfaceHelper(TemporaryRef<layers::Image> aImage) : mImage(aImage) {}
 
   // It retrieves a SourceSurface reference and convert color format on main
   // thread and passes DataSourceSurface to caller thread.
   NS_IMETHOD Run() {
     // It guarantees the reference will be released on main thread.
     nsCountedRef<nsMainThreadSourceSurfaceRef> surface;
-    surface.own(mImage->GetAsSourceSurface().drop());
+    surface.own(mImage->GetAsSourceSurface().take());
 
     if (surface->GetFormat() == gfx::SurfaceFormat::B8G8R8A8) {
       mDataSourceSurface = surface->GetDataSurface();
     } else {
       mDataSourceSurface = gfxUtils::
         CopySurfaceToDataSourceSurfaceWithFormat(surface,
                                                  gfx::SurfaceFormat::B8G8R8A8);
     }
--- a/gfx/2d/DrawTargetCairo.cpp
+++ b/gfx/2d/DrawTargetCairo.cpp
@@ -389,17 +389,17 @@ GetCairoSurfaceForSourceSurface(SourceSu
       return result;
     }
     data->Unmap();
     return nullptr;
   }
 
   cairo_surface_set_user_data(surf,
                               &surfaceDataKey,
-                              data.forget().drop(),
+                              data.forget().take(),
                               ReleaseData);
   return surf;
 }
 
 // An RAII class to temporarily clear any device offset set
 // on a surface. Note that this does not take a reference to the
 // surface.
 class AutoClearDeviceOffset
--- a/gfx/layers/ImageContainer.cpp
+++ b/gfx/layers/ImageContainer.cpp
@@ -141,17 +141,17 @@ ImageContainer::ImageContainer(int flag)
   mImageFactory(new ImageFactory()),
   mRecycleBin(new BufferRecycleBin()),
   mCompositionNotifySink(nullptr),
   mImageClient(nullptr)
 {
   if (flag == ENABLE_ASYNC && ImageBridgeChild::IsCreated()) {
     // the refcount of this ImageClient is 1. we don't use a RefPtr here because the refcount
     // of this class must be done on the ImageBridge thread.
-    mImageClient = ImageBridgeChild::GetSingleton()->CreateImageClient(CompositableType::IMAGE).drop();
+    mImageClient = ImageBridgeChild::GetSingleton()->CreateImageClient(CompositableType::IMAGE).take();
     MOZ_ASSERT(mImageClient);
   }
 }
 
 ImageContainer::~ImageContainer()
 {
   if (IsAsync()) {
     ImageBridgeChild::DispatchReleaseImageClient(mImageClient);
@@ -164,17 +164,17 @@ ImageContainer::CreateImage(ImageFormat 
   ReentrantMonitorAutoEnter mon(mReentrantMonitor);
 
 #ifdef MOZ_WIDGET_GONK
   if (aFormat == ImageFormat::OVERLAY_IMAGE) {
     if (mImageClient && mImageClient->GetTextureInfo().mCompositableType != CompositableType::IMAGE_OVERLAY) {
       // If this ImageContainer is async but the image type mismatch, fix it here
       if (ImageBridgeChild::IsCreated()) {
         ImageBridgeChild::DispatchReleaseImageClient(mImageClient);
-        mImageClient = ImageBridgeChild::GetSingleton()->CreateImageClient(CompositableType::IMAGE_OVERLAY).drop();
+        mImageClient = ImageBridgeChild::GetSingleton()->CreateImageClient(CompositableType::IMAGE_OVERLAY).take();
       }
     }
   }
 #endif
   if (mImageClient) {
     nsRefPtr<Image> img = mImageClient->CreateImage(aFormat);
     if (img) {
       return img.forget();
--- a/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp
+++ b/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp
@@ -32,18 +32,18 @@ SharedPlanarYCbCrImage::SharedPlanarYCbC
   MOZ_COUNT_CTOR(SharedPlanarYCbCrImage);
 }
 
 SharedPlanarYCbCrImage::~SharedPlanarYCbCrImage() {
   MOZ_COUNT_DTOR(SharedPlanarYCbCrImage);
 
   if (mCompositable->GetAsyncID() != 0 &&
       !InImageBridgeChildThread()) {
-    ImageBridgeChild::DispatchReleaseTextureClient(mTextureClient.forget().drop());
-    ImageBridgeChild::DispatchReleaseImageClient(mCompositable.forget().drop());
+    ImageBridgeChild::DispatchReleaseTextureClient(mTextureClient.forget().take());
+    ImageBridgeChild::DispatchReleaseImageClient(mCompositable.forget().take());
   }
 }
 
 size_t
 SharedPlanarYCbCrImage::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
 {
   // NB: Explicitly skipping mTextureClient, the memory is already reported
   //     at time of allocation in GfxMemoryImageReporter.
--- a/gfx/layers/ipc/SharedRGBImage.cpp
+++ b/gfx/layers/ipc/SharedRGBImage.cpp
@@ -65,18 +65,18 @@ SharedRGBImage::SharedRGBImage(ImageClie
 }
 
 SharedRGBImage::~SharedRGBImage()
 {
   MOZ_COUNT_DTOR(SharedRGBImage);
 
   if (mCompositable->GetAsyncID() != 0 &&
       !InImageBridgeChildThread()) {
-    ImageBridgeChild::DispatchReleaseTextureClient(mTextureClient.forget().drop());
-    ImageBridgeChild::DispatchReleaseImageClient(mCompositable.forget().drop());
+    ImageBridgeChild::DispatchReleaseTextureClient(mTextureClient.forget().take());
+    ImageBridgeChild::DispatchReleaseImageClient(mCompositable.forget().take());
   }
 }
 
 bool
 SharedRGBImage::Allocate(gfx::IntSize aSize, gfx::SurfaceFormat aFormat)
 {
   mSize = aSize;
   mTextureClient = mCompositable->CreateBufferTextureClient(aFormat, aSize,
--- a/layout/generic/nsCanvasFrame.cpp
+++ b/layout/generic/nsCanvasFrame.cpp
@@ -341,17 +341,17 @@ nsDisplayCanvasBackgroundImage::Paint(ns
 
   PaintInternal(aBuilder,
                 dt ? &context : aCtx,
                 dt ? bgClipRect: mVisibleRect,
                 &bgClipRect);
 
   if (dt) {
     BlitSurface(dest->GetDrawTarget(), destRect, dt);
-    frame->Properties().Set(nsIFrame::CachedBackgroundImageDT(), dt.forget().drop());
+    frame->Properties().Set(nsIFrame::CachedBackgroundImageDT(), dt.forget().take());
   }
 }
 
 void
 nsDisplayCanvasThemedBackground::Paint(nsDisplayListBuilder* aBuilder,
                                        nsRenderingContext* aCtx)
 {
   nsCanvasFrame* frame = static_cast<nsCanvasFrame*>(mFrame);
--- a/media/webrtc/signaling/test/mediaconduit_unittests.cpp
+++ b/media/webrtc/signaling/test/mediaconduit_unittests.cpp
@@ -778,17 +778,17 @@ class TransportConduitTest : public ::te
     cerr << "    3. Null Codec Parameter  " << endl;
     cerr << "   *************************************************" << endl;
 
     err = videoSession->ConfigureSendMediaCodec(nullptr);
     EXPECT_TRUE(err != mozilla::kMediaConduitNoError);
 
     mozilla::SyncRunnable::DispatchToThread(gMainThread,
                                             WrapRunnable(
-                                                videoSession.forget().drop(),
+                                                videoSession.forget().take(),
                                                 &mozilla::VideoSessionConduit::Release));
   }
 
   void DumpMaxFs(int orig_width, int orig_height, int max_fs,
                  int new_width, int new_height)
   {
     cerr << "Applying max_fs=" << max_fs << " to input resolution " <<
                  orig_width << "x" << orig_height << endl;
--- a/mfbt/RefPtr.h
+++ b/mfbt/RefPtr.h
@@ -230,32 +230,32 @@ class RefPtr
   friend class TemporaryRef<T>;
   friend class OutParamRef<T>;
 
   struct DontRef {};
 
 public:
   RefPtr() : mPtr(0) {}
   RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.mPtr)) {}
-  MOZ_IMPLICIT RefPtr(const TemporaryRef<T>& aOther) : mPtr(aOther.drop()) {}
+  MOZ_IMPLICIT RefPtr(const TemporaryRef<T>& aOther) : mPtr(aOther.take()) {}
   MOZ_IMPLICIT RefPtr(T* aVal) : mPtr(ref(aVal)) {}
 
   template<typename U>
   RefPtr(const RefPtr<U>& aOther) : mPtr(ref(aOther.get())) {}
 
   ~RefPtr() { unref(mPtr); }
 
   RefPtr& operator=(const RefPtr& aOther)
   {
     assign(ref(aOther.mPtr));
     return *this;
   }
   RefPtr& operator=(const TemporaryRef<T>& aOther)
   {
-    assign(aOther.drop());
+    assign(aOther.take());
     return *this;
   }
   RefPtr& operator=(T* aVal)
   {
     assign(ref(aVal));
     return *this;
   }
 
@@ -316,24 +316,24 @@ class TemporaryRef
 {
   // To allow it to construct TemporaryRef from a bare T*
   friend class RefPtr<T>;
 
   typedef typename RefPtr<T>::DontRef DontRef;
 
 public:
   MOZ_IMPLICIT TemporaryRef(T* aVal) : mPtr(RefPtr<T>::ref(aVal)) {}
-  TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.drop()) {}
+  TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.take()) {}
 
   template<typename U>
-  TemporaryRef(const TemporaryRef<U>& aOther) : mPtr(aOther.drop()) {}
+  TemporaryRef(const TemporaryRef<U>& aOther) : mPtr(aOther.take()) {}
 
   ~TemporaryRef() { RefPtr<T>::unref(mPtr); }
 
-  T* drop() const
+  MOZ_WARN_UNUSED_RESULT T* take() const
   {
     T* tmp = mPtr;
     mPtr = nullptr;
     return tmp;
   }
 
 private:
   TemporaryRef(T* aVal, const DontRef&) : mPtr(aVal) {}
--- a/widget/cocoa/nsCocoaUtils.mm
+++ b/widget/cocoa/nsCocoaUtils.mm
@@ -391,17 +391,17 @@ nsresult nsCocoaUtils::CreateCGImageFrom
   if (!dataSurface->Map(DataSourceSurface::MapType::READ, &map)) {
     return NS_ERROR_FAILURE;
   }
   // The Unmap() call happens in data_ss_release_callback
 
   // Create a CGImageRef with the bits from the image, taking into account
   // the alpha ordering and endianness of the machine so we don't have to
   // touch the bits ourselves.
-  CGDataProviderRef dataProvider = ::CGDataProviderCreateWithData(dataSurface.forget().drop(),
+  CGDataProviderRef dataProvider = ::CGDataProviderCreateWithData(dataSurface.forget().take(),
                                                                   map.mData,
                                                                   map.mStride * height,
                                                                   data_ss_release_callback);
   CGColorSpaceRef colorSpace = ::CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
   *aResult = ::CGImageCreate(width,
                              height,
                              8,
                              32,