Bug 1116905 - part 1 - remove dependence on implicit conversion from T* to TemporaryRef<T>, non-gfx changes; r=ehsan
authorNathan Froyd <froydnj@mozilla.com>
Thu, 30 Apr 2015 15:17:08 -0400
changeset 245113 27c4c70a437e92c0d4f1a18ecbfa4081981abdc8
parent 245112 18252e340c73ee8f74cf39ea77047160418a2693
child 245114 43684b88e52e138611f58dfb632305681aa564f9
push id28797
push userryanvm@gmail.com
push dateFri, 22 May 2015 18:02:57 +0000
treeherdermozilla-central@a69094e0f2a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1116905
milestone41.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 1116905 - part 1 - remove dependence on implicit conversion from T* to TemporaryRef<T>, non-gfx changes; r=ehsan
dom/base/ImageEncoder.cpp
dom/canvas/CanvasRenderingContext2D.cpp
dom/media/AudioSink.cpp
dom/media/MediaDecoderStateMachine.h
dom/media/platforms/apple/AppleATDecoder.cpp
dom/media/platforms/apple/AppleVDADecoder.cpp
dom/media/platforms/apple/AppleVTDecoder.cpp
dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp
dom/media/platforms/ffmpeg/FFmpegH264Decoder.cpp
dom/media/platforms/gonk/GonkMediaDataDecoder.cpp
dom/media/platforms/wmf/WMFMediaDataDecoder.cpp
media/mtransport/dtlsidentity.cpp
mfbt/tests/TestRefPtr.cpp
mozglue/linker/ElfLoader.cpp
mozglue/linker/Zip.cpp
--- a/dom/base/ImageEncoder.cpp
+++ b/dom/base/ImageEncoder.cpp
@@ -387,17 +387,18 @@ ImageEncoder::ExtractDataInternal(const 
                                   aSize.width * aSize.height * 4,
                                   aSize.width,
                                   aSize.height,
                                   aSize.width * 4,
                                   imgIEncoder::INPUT_FORMAT_HOSTARGB,
                                   aOptions);
     } else {
       RefPtr<gfx::DataSourceSurface> dataSurface;
-      dataSurface = GetBRGADataSourceSurfaceSync(aImage);
+      RefPtr<layers::Image> image(aImage);
+      dataSurface = GetBRGADataSourceSurfaceSync(image.forget());
 
       DataSourceSurface::MappedSurface map;
       if (!dataSurface->Map(gfx::DataSourceSurface::MapType::READ, &map)) {
         return NS_ERROR_INVALID_ARG;
       }
       rv = aEncoder->InitFromData(map.mData,
                                   aSize.width * aSize.height * 4,
                                   aSize.width,
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -4074,24 +4074,26 @@ bool CanvasRenderingContext2D::IsPointIn
 // relative to the returned surface.
 static TemporaryRef<SourceSurface>
 ExtractSubrect(SourceSurface* aSurface, mgfx::Rect* aSourceRect, DrawTarget* aTargetDT)
 {
   mgfx::Rect roundedOutSourceRect = *aSourceRect;
   roundedOutSourceRect.RoundOut();
   mgfx::IntRect roundedOutSourceRectInt;
   if (!roundedOutSourceRect.ToIntRect(&roundedOutSourceRectInt)) {
-    return aSurface;
+    RefPtr<SourceSurface> surface(aSurface);
+    return surface.forget();
   }
 
   RefPtr<DrawTarget> subrectDT =
     aTargetDT->CreateSimilarDrawTarget(roundedOutSourceRectInt.Size(), SurfaceFormat::B8G8R8A8);
 
   if (!subrectDT) {
-    return aSurface;
+    RefPtr<SourceSurface> surface(aSurface);
+    return surface.forget();
   }
 
   *aSourceRect -= roundedOutSourceRect.TopLeft();
 
   subrectDT->CopySurface(aSurface, roundedOutSourceRectInt, IntPoint());
   return subrectDT->Snapshot();
 }
 
--- a/dom/media/AudioSink.cpp
+++ b/dom/media/AudioSink.cpp
@@ -33,17 +33,18 @@ AudioSink::OnAudioEndTimeUpdateTask::Run
   return NS_OK;
 }
 
 void
 AudioSink::OnAudioEndTimeUpdateTask::Dispatch(int64_t aEndTime) {
   MutexAutoLock lock(mMutex);
   if (mStateMachine) {
     mEndTime = aEndTime;
-    mStateMachine->TaskQueue()->Dispatch(this);
+    nsRefPtr<AudioSink::OnAudioEndTimeUpdateTask> runnable(this);
+    mStateMachine->TaskQueue()->Dispatch(runnable.forget());
   }
 }
 
 void
 AudioSink::OnAudioEndTimeUpdateTask::Cancel() {
   MutexAutoLock lock(mMutex);
   mStateMachine = nullptr;
 }
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -171,17 +171,19 @@ private:
   // constructor immediately after the task queue is created.
   void InitializationTask();
 
   void Shutdown();
 public:
 
   void DispatchShutdown()
   {
-    TaskQueue()->Dispatch(NS_NewRunnableMethod(this, &MediaDecoderStateMachine::Shutdown));
+    nsCOMPtr<nsIRunnable> runnable =
+      NS_NewRunnableMethod(this, &MediaDecoderStateMachine::Shutdown);
+    TaskQueue()->Dispatch(runnable.forget());
   }
 
   void FinishShutdown();
 
   bool IsRealTime() const;
 
   // Called from the main thread to get the duration. The decoder monitor
   // must be obtained before calling this. It is in units of microseconds.
@@ -238,17 +240,19 @@ private:
   // Causes the state machine to switch to buffering state, and to
   // immediately stop playback and buffer downloaded data. Called on
   // the state machine thread.
   void StartBuffering();
 public:
 
   void DispatchStartBuffering()
   {
-    TaskQueue()->Dispatch(NS_NewRunnableMethod(this, &MediaDecoderStateMachine::StartBuffering));
+    nsCOMPtr<nsIRunnable> runnable =
+      NS_NewRunnableMethod(this, &MediaDecoderStateMachine::StartBuffering);
+    TaskQueue()->Dispatch(runnable.forget());
   }
 
   // This is called on the state machine thread and audio thread.
   // The decoder monitor must be obtained before calling this.
   bool HasAudio() const {
     AssertCurrentThreadInMonitor();
     return mInfo.HasAudio();
   }
@@ -740,25 +744,29 @@ public:
 
 private:
   // Called by the AudioSink to signal that all outstanding work is complete
   // and the sink is shutting down.
   void OnAudioSinkComplete();
 public:
   void DispatchOnAudioSinkComplete()
   {
-    TaskQueue()->Dispatch(NS_NewRunnableMethod(this, &MediaDecoderStateMachine::OnAudioSinkComplete));
+    nsCOMPtr<nsIRunnable> runnable =
+      NS_NewRunnableMethod(this, &MediaDecoderStateMachine::OnAudioSinkComplete);
+    TaskQueue()->Dispatch(runnable.forget());
   }
 
   // Called by the AudioSink to signal errors.
   void OnAudioSinkError();
 
   void DispatchOnAudioSinkError()
   {
-    TaskQueue()->Dispatch(NS_NewRunnableMethod(this, &MediaDecoderStateMachine::OnAudioSinkError));
+    nsCOMPtr<nsIRunnable> runnable =
+      NS_NewRunnableMethod(this, &MediaDecoderStateMachine::OnAudioSinkError);
+    TaskQueue()->Dispatch(runnable.forget());
   }
 
   // Return true if the video decoder's decode speed can not catch up the
   // play time.
   bool NeedToSkipToNextKeyframe();
 
   // The decoder object that created this state machine. The state machine
   // holds a strong reference to the decoder to ensure that the decoder stays
--- a/dom/media/platforms/apple/AppleATDecoder.cpp
+++ b/dom/media/platforms/apple/AppleATDecoder.cpp
@@ -67,21 +67,22 @@ AppleATDecoder::Input(MediaRawData* aSam
   LOG("mp4 input sample %p %lld us %lld pts%s %llu bytes audio",
       aSample,
       aSample->mDuration,
       aSample->mTime,
       aSample->mKeyframe ? " keyframe" : "",
       (unsigned long long)aSample->mSize);
 
   // Queue a task to perform the actual decoding on a separate thread.
-  mTaskQueue->Dispatch(
+  nsCOMPtr<nsIRunnable> runnable =
       NS_NewRunnableMethodWithArg<nsRefPtr<MediaRawData>>(
         this,
         &AppleATDecoder::SubmitSample,
-        nsRefPtr<MediaRawData>(aSample)));
+        nsRefPtr<MediaRawData>(aSample));
+  mTaskQueue->Dispatch(runnable.forget());
 
   return NS_OK;
 }
 
 nsresult
 AppleATDecoder::Flush()
 {
   LOG("Flushing AudioToolbox AAC decoder");
--- a/dom/media/platforms/apple/AppleVDADecoder.cpp
+++ b/dom/media/platforms/apple/AppleVDADecoder.cpp
@@ -103,21 +103,22 @@ AppleVDADecoder::Input(MediaRawData* aSa
 {
   LOG("mp4 input sample %p pts %lld duration %lld us%s %d bytes",
       aSample,
       aSample->mTime,
       aSample->mDuration,
       aSample->mKeyframe ? " keyframe" : "",
       aSample->mSize);
 
-  mTaskQueue->Dispatch(
+  nsCOMPtr<nsIRunnable> runnable =
       NS_NewRunnableMethodWithArg<nsRefPtr<MediaRawData>>(
           this,
           &AppleVDADecoder::SubmitFrame,
-          nsRefPtr<MediaRawData>(aSample)));
+          nsRefPtr<MediaRawData>(aSample));
+  mTaskQueue->Dispatch(runnable.forget());
   return NS_OK;
 }
 
 nsresult
 AppleVDADecoder::Flush()
 {
   mTaskQueue->Flush();
   OSStatus rv = VDADecoderFlush(mDecoder, 0 /*dont emit*/);
--- a/dom/media/platforms/apple/AppleVTDecoder.cpp
+++ b/dom/media/platforms/apple/AppleVTDecoder.cpp
@@ -93,21 +93,22 @@ AppleVTDecoder::Input(MediaRawData* aSam
   hash.finish(digest_buf);
   nsAutoCString digest;
   for (size_t i = 0; i < sizeof(digest_buf); i++) {
     digest.AppendPrintf("%02x", digest_buf[i]);
   }
   LOG("    sha1 %s", digest.get());
 #endif // LOG_MEDIA_SHA1
 
-  mTaskQueue->Dispatch(
+  nsCOMPtr<nsIRunnable> runnable =
       NS_NewRunnableMethodWithArg<nsRefPtr<MediaRawData>>(
           this,
           &AppleVTDecoder::SubmitFrame,
-          nsRefPtr<MediaRawData>(aSample)));
+          nsRefPtr<MediaRawData>(aSample));
+  mTaskQueue->Dispatch(runnable.forget());
   return NS_OK;
 }
 
 nsresult
 AppleVTDecoder::Flush()
 {
   mTaskQueue->Flush();
   nsresult rv = WaitForAsynchronousFrames();
--- a/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp
@@ -143,19 +143,19 @@ FFmpegAudioDecoder<LIBAV_VER>::DecodePac
   if (mTaskQueue->IsEmpty()) {
     mCallback->InputExhausted();
   }
 }
 
 nsresult
 FFmpegAudioDecoder<LIBAV_VER>::Input(MediaRawData* aSample)
 {
-  mTaskQueue->Dispatch(NS_NewRunnableMethodWithArg<nsRefPtr<MediaRawData> >(
+  nsCOMPtr<nsIRunnable> runnable(NS_NewRunnableMethodWithArg<nsRefPtr<MediaRawData>>(
     this, &FFmpegAudioDecoder::DecodePacket, nsRefPtr<MediaRawData>(aSample)));
-
+  mTaskQueue->Dispatch(runnable.forget());
   return NS_OK;
 }
 
 nsresult
 FFmpegAudioDecoder<LIBAV_VER>::Drain()
 {
   mTaskQueue->AwaitIdle();
   mCallback->DrainComplete();
--- a/dom/media/platforms/ffmpeg/FFmpegH264Decoder.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegH264Decoder.cpp
@@ -237,38 +237,40 @@ FFmpegH264Decoder<LIBAV_VER>::AllocateYU
   aFrame->opaque = static_cast<void*>(image.forget().take());
 
   return 0;
 }
 
 nsresult
 FFmpegH264Decoder<LIBAV_VER>::Input(MediaRawData* aSample)
 {
-  mTaskQueue->Dispatch(
+  nsCOMPtr<nsIRunnable> runnable(
     NS_NewRunnableMethodWithArg<nsRefPtr<MediaRawData>>(
       this, &FFmpegH264Decoder<LIBAV_VER>::DecodeFrame,
       nsRefPtr<MediaRawData>(aSample)));
+  mTaskQueue->Dispatch(runnable.forget());
 
   return NS_OK;
 }
 
 void
 FFmpegH264Decoder<LIBAV_VER>::DoDrain()
 {
   nsRefPtr<MediaRawData> empty(new MediaRawData());
   while (DoDecodeFrame(empty) == DecodeResult::DECODE_FRAME) {
   }
   mCallback->DrainComplete();
 }
 
 nsresult
 FFmpegH264Decoder<LIBAV_VER>::Drain()
 {
-  mTaskQueue->Dispatch(
+  nsCOMPtr<nsIRunnable> runnable(
     NS_NewRunnableMethod(this, &FFmpegH264Decoder<LIBAV_VER>::DoDrain));
+  mTaskQueue->Dispatch(runnable.forget());
 
   return NS_OK;
 }
 
 nsresult
 FFmpegH264Decoder<LIBAV_VER>::Flush()
 {
   nsresult rv = FFmpegDataDecoder::Flush();
--- a/dom/media/platforms/gonk/GonkMediaDataDecoder.cpp
+++ b/dom/media/platforms/gonk/GonkMediaDataDecoder.cpp
@@ -60,21 +60,22 @@ GonkMediaDataDecoder::Shutdown()
   mDecoder = nullptr;
   return NS_OK;
 }
 
 // Inserts data into the decoder's pipeline.
 nsresult
 GonkMediaDataDecoder::Input(MediaRawData* aSample)
 {
-  mTaskQueue->Dispatch(
+  nsCOMPtr<nsIRunnable> runnable(
     NS_NewRunnableMethodWithArg<nsRefPtr<MediaRawData>>(
       this,
       &GonkMediaDataDecoder::ProcessDecode,
       nsRefPtr<MediaRawData>(aSample)));
+  mTaskQueue->Dispatch(runnable.forget());
   return NS_OK;
 }
 
 void
 GonkMediaDataDecoder::ProcessDecode(MediaRawData* aSample)
 {
   nsresult rv = mManager->Input(aSample);
   if (rv != NS_OK) {
@@ -156,13 +157,15 @@ GonkMediaDataDecoder::ProcessDrain()
   ProcessDecode(nullptr);
   mSignaledEOS = true;
   ProcessOutput();
 }
 
 nsresult
 GonkMediaDataDecoder::Drain()
 {
-  mTaskQueue->Dispatch(NS_NewRunnableMethod(this, &GonkMediaDataDecoder::ProcessDrain));
+  nsCOMPtr<nsIRunnable> runnable =
+    NS_NewRunnableMethod(this, &GonkMediaDataDecoder::ProcessDrain);
+  mTaskQueue->Dispatch(runnable.forget());
   return NS_OK;
 }
 
 } // namespace mozilla
--- a/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp
+++ b/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp
@@ -79,18 +79,19 @@ SendTelemetry(HRESULT hr)
 }
 
 nsresult
 WMFMediaDataDecoder::Shutdown()
 {
   MOZ_DIAGNOSTIC_ASSERT(!mIsShutDown);
 
   if (mTaskQueue) {
-    mTaskQueue->Dispatch(
-      NS_NewRunnableMethod(this, &WMFMediaDataDecoder::ProcessShutdown));
+    nsCOMPtr<nsIRunnable> runnable =
+      NS_NewRunnableMethod(this, &WMFMediaDataDecoder::ProcessShutdown);
+    mTaskQueue->Dispatch(runnable.forget());
   } else {
     ProcessShutdown();
   }
   mIsShutDown = true;
   return NS_OK;
 }
 
 void
@@ -221,17 +222,19 @@ WMFMediaDataDecoder::ProcessDrain()
 }
 
 nsresult
 WMFMediaDataDecoder::Drain()
 {
   MOZ_ASSERT(mCallback->OnReaderTaskQueue());
   MOZ_DIAGNOSTIC_ASSERT(!mIsShutDown);
 
-  mTaskQueue->Dispatch(NS_NewRunnableMethod(this, &WMFMediaDataDecoder::ProcessDrain));
+  nsCOMPtr<nsIRunnable> runnable =
+    NS_NewRunnableMethod(this, &WMFMediaDataDecoder::ProcessDrain);
+  mTaskQueue->Dispatch(runnable.forget());
   return NS_OK;
 }
 
 bool
 WMFMediaDataDecoder::IsHardwareAccelerated() const {
   MOZ_ASSERT(!mIsShutDown);
 
   return mMFTManager && mMFTManager->IsHardwareAccelerated();
--- a/media/mtransport/dtlsidentity.cpp
+++ b/media/mtransport/dtlsidentity.cpp
@@ -145,17 +145,19 @@ TemporaryRef<DtlsIdentity> DtlsIdentity:
   rv = SEC_DerSignData(arena, signedCert, innerDER.data, innerDER.len,
                        private_key,
                        SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION);
   if (rv != SECSuccess) {
     return nullptr;
   }
   certificate->derCert = *signedCert;
 
-  return new DtlsIdentity(private_key.forget(), certificate.forget());
+  RefPtr<DtlsIdentity> identity =
+    new DtlsIdentity(private_key.forget(), certificate.forget());
+  return identity.forget();
 }
 
 
 nsresult DtlsIdentity::ComputeFingerprint(const std::string algorithm,
                                           unsigned char *digest,
                                           std::size_t size,
                                           std::size_t *digest_length) {
   MOZ_ASSERT(cert_);
--- a/mfbt/tests/TestRefPtr.cpp
+++ b/mfbt/tests/TestRefPtr.cpp
@@ -37,17 +37,18 @@ TemporaryRef<Foo>
 NewFoo()
 {
   return RefPtr<Foo>(new Foo());
 }
 
 TemporaryRef<Foo>
 NewBar()
 {
-  return new Bar();
+  RefPtr<Bar> bar = new Bar();
+  return bar.forget();
 }
 
 void
 GetNewFoo(Foo** aFoo)
 {
   *aFoo = new Bar();
   // Kids, don't try this at home
   (*aFoo)->AddRef();
--- a/mozglue/linker/ElfLoader.cpp
+++ b/mozglue/linker/ElfLoader.cpp
@@ -263,17 +263,18 @@ SystemElf::Load(const char *path, int fl
   }
 
   void *handle = dlopen(path, flags);
   DEBUG_LOG("dlopen(\"%s\", 0x%x) = %p", path, flags, handle);
   ElfLoader::Singleton.lastError = dlerror();
   if (handle) {
     SystemElf *elf = new SystemElf(path, handle);
     ElfLoader::Singleton.Register(elf);
-    return elf;
+    RefPtr<LibHandle> lib(elf);
+    return lib.forget();
   }
   return nullptr;
 }
 
 SystemElf::~SystemElf()
 {
   if (!dlhandle)
     return;
@@ -350,22 +351,26 @@ ElfLoader::Load(const char *path, int fl
 
   /* TODO: Handle relative paths correctly */
   const char *name = LeafName(path);
 
   /* Search the list of handles we already have for a match. When the given
    * path is not absolute, compare file names, otherwise compare full paths. */
   if (name == path) {
     for (LibHandleList::iterator it = handles.begin(); it < handles.end(); ++it)
-      if ((*it)->GetName() && (strcmp((*it)->GetName(), name) == 0))
-        return *it;
+      if ((*it)->GetName() && (strcmp((*it)->GetName(), name) == 0)) {
+        handle = *it;
+        return handle.forget();
+      }
   } else {
     for (LibHandleList::iterator it = handles.begin(); it < handles.end(); ++it)
-      if ((*it)->GetPath() && (strcmp((*it)->GetPath(), path) == 0))
-        return *it;
+      if ((*it)->GetPath() && (strcmp((*it)->GetPath(), path) == 0)) {
+        handle = *it;
+        return handle.forget();
+      }
   }
 
   char *abs_path = nullptr;
   const char *requested_path = path;
 
   /* When the path is not absolute and the library is being loaded for
    * another, first try to load the library from the directory containing
    * that parent library. */
@@ -393,26 +398,28 @@ ElfLoader::Load(const char *path, int fl
   if (!handle && abs_path)
     handle = SystemElf::Load(name, flags);
 
   delete [] abs_path;
   DEBUG_LOG("ElfLoader::Load(\"%s\", 0x%x, %p [\"%s\"]) = %p", requested_path, flags,
             reinterpret_cast<void *>(parent), parent ? parent->GetPath() : "",
             static_cast<void *>(handle));
 
-  return handle;
+  return handle.forget();
 }
 
 mozilla::TemporaryRef<LibHandle>
 ElfLoader::GetHandleByPtr(void *addr)
 {
   /* Scan the list of handles we already have for a match */
   for (LibHandleList::iterator it = handles.begin(); it < handles.end(); ++it) {
-    if ((*it)->Contains(addr))
-      return *it;
+    if ((*it)->Contains(addr)) {
+      RefPtr<LibHandle> lib = *it;
+      return lib.forget();
+    }
   }
   return nullptr;
 }
 
 Mappable *
 ElfLoader::GetMappableFromPath(const char *path)
 {
   const char *name = LeafName(path);
--- a/mozglue/linker/Zip.cpp
+++ b/mozglue/linker/Zip.cpp
@@ -182,18 +182,20 @@ Zip::GetFirstEntry() const
 ZipCollection ZipCollection::Singleton;
 
 mozilla::TemporaryRef<Zip>
 ZipCollection::GetZip(const char *path)
 {
   /* Search the list of Zips we already have for a match */
   for (std::vector<Zip *>::iterator it = Singleton.zips.begin();
        it < Singleton.zips.end(); ++it) {
-    if ((*it)->GetName() && (strcmp((*it)->GetName(), path) == 0))
-      return *it;
+    if ((*it)->GetName() && (strcmp((*it)->GetName(), path) == 0)) {
+      mozilla::RefPtr<Zip> zip = *it;
+      return zip.forget();
+    }
   }
   return Zip::Create(path);
 }
 
 void
 ZipCollection::Register(Zip *zip)
 {
   Singleton.zips.push_back(zip);