Skip to content

Commit

Permalink
Bug 1160485 - remove implicit conversion from RefPtr<T> to TemporaryR…
Browse files Browse the repository at this point in the history
…ef<T>; r=ehsan

Having this implicit conversion means that we can silently do extra
refcounting when it's completely unnecessary.  It's also an obstacle to
making RefPtr more nsRefPtr-like, so let's get rid of it.
  • Loading branch information
froydnj committed May 1, 2015
1 parent 2e9c6d1 commit db188ea
Show file tree
Hide file tree
Showing 77 changed files with 216 additions and 197 deletions.
12 changes: 8 additions & 4 deletions dom/canvas/CanvasRenderingContext2D.cpp
Expand Up @@ -5636,15 +5636,18 @@ CanvasPath::GetPath(const CanvasWindingRule& winding, const DrawTarget* aTarget)
if (mPath &&
(mPath->GetBackendType() == aTarget->GetBackendType()) &&
(mPath->GetFillRule() == fillRule)) {
return mPath;
RefPtr<gfx::Path> path(mPath);
return path.forget();
}

if (!mPath) {
// if there is no path, there must be a pathbuilder
MOZ_ASSERT(mPathBuilder);
mPath = mPathBuilder->Finish();
if (!mPath)
return mPath;
if (!mPath) {
RefPtr<gfx::Path> path(mPath);
return path.forget();
}

mPathBuilder = nullptr;
}
Expand All @@ -5659,7 +5662,8 @@ CanvasPath::GetPath(const CanvasWindingRule& winding, const DrawTarget* aTarget)
mPath = tmpPathBuilder->Finish();
}

return mPath;
RefPtr<gfx::Path> path(mPath);
return path.forget();
}

void
Expand Down
4 changes: 2 additions & 2 deletions dom/media/MediaDecoder.cpp
Expand Up @@ -209,7 +209,7 @@ void MediaDecoder::UpdateDormantState(bool aDormantTimeout, bool aActivity)
mDecoderStateMachine,
&MediaDecoderStateMachine::SetDormant,
true);
mDecoderStateMachine->TaskQueue()->Dispatch(event);
mDecoderStateMachine->TaskQueue()->Dispatch(event.forget());

if (IsEnded()) {
mWasEndedWhenEnteredDormant = true;
Expand All @@ -225,7 +225,7 @@ void MediaDecoder::UpdateDormantState(bool aDormantTimeout, bool aActivity)
mDecoderStateMachine,
&MediaDecoderStateMachine::SetDormant,
false);
mDecoderStateMachine->TaskQueue()->Dispatch(event);
mDecoderStateMachine->TaskQueue()->Dispatch(event.forget());
}
}

Expand Down
4 changes: 2 additions & 2 deletions dom/media/MediaDecoderReader.cpp
Expand Up @@ -277,7 +277,7 @@ MediaDecoderReader::RequestVideoData(bool aSkipToNextKeyframe,
// again. We don't just decode straight in a loop here, as that
// would hog the decode task queue.
RefPtr<nsIRunnable> task(new ReRequestVideoWithSkipTask(this, aTimeThreshold));
mTaskQueue->Dispatch(task);
mTaskQueue->Dispatch(task.forget());
return p;
}
}
Expand Down Expand Up @@ -313,7 +313,7 @@ MediaDecoderReader::RequestAudioData()
// consumed. (|mVideoSinkBufferCount| > 0)
if (AudioQueue().GetSize() == 0 && mTaskQueue) {
RefPtr<nsIRunnable> task(new ReRequestAudioTask(this));
mTaskQueue->Dispatch(task);
mTaskQueue->Dispatch(task.forget());
return p;
}
}
Expand Down
10 changes: 5 additions & 5 deletions dom/media/MediaFormatReader.cpp
Expand Up @@ -1017,7 +1017,7 @@ MediaFormatReader::Output(TrackType aTrack, MediaData* aSample)
RefPtr<nsIRunnable> task =
NS_NewRunnableMethodWithArgs<TrackType, StorensRefPtrPassByPtr<MediaData>>(
this, &MediaFormatReader::NotifyNewOutput, aTrack, aSample);
GetTaskQueue()->Dispatch(task);
GetTaskQueue()->Dispatch(task.forget());
}

void
Expand All @@ -1026,7 +1026,7 @@ MediaFormatReader::DrainComplete(TrackType aTrack)
RefPtr<nsIRunnable> task =
NS_NewRunnableMethodWithArg<TrackType>(
this, &MediaFormatReader::NotifyDrainComplete, aTrack);
GetTaskQueue()->Dispatch(task);
GetTaskQueue()->Dispatch(task.forget());
}

void
Expand All @@ -1035,7 +1035,7 @@ MediaFormatReader::InputExhausted(TrackType aTrack)
RefPtr<nsIRunnable> task =
NS_NewRunnableMethodWithArg<TrackType>(
this, &MediaFormatReader::NotifyInputExhausted, aTrack);
GetTaskQueue()->Dispatch(task);
GetTaskQueue()->Dispatch(task.forget());
}

void
Expand All @@ -1044,7 +1044,7 @@ MediaFormatReader::Error(TrackType aTrack)
RefPtr<nsIRunnable> task =
NS_NewRunnableMethodWithArg<TrackType>(
this, &MediaFormatReader::NotifyError, aTrack);
GetTaskQueue()->Dispatch(task);
GetTaskQueue()->Dispatch(task.forget());
}

void
Expand Down Expand Up @@ -1362,7 +1362,7 @@ MediaFormatReader::NotifyDataArrived(const char* aBuffer, uint32_t aLength, int6
NS_NewRunnableMethodWithArgs<int32_t, uint64_t>(
this, &MediaFormatReader::NotifyDemuxer,
aLength, aOffset);
GetTaskQueue()->Dispatch(task);
GetTaskQueue()->Dispatch(task.forget());
}

} // namespace mozilla
2 changes: 1 addition & 1 deletion dom/media/directshow/AudioSinkInputPin.cpp
Expand Up @@ -139,7 +139,7 @@ AudioSinkInputPin::GetConnectedPinSeeking()
return nullptr;
RefPtr<IMediaSeeking> seeking;
peer->QueryInterface(static_cast<IMediaSeeking**>(byRef(seeking)));
return seeking;
return seeking.forget();
}

HRESULT
Expand Down
2 changes: 1 addition & 1 deletion dom/media/directshow/DirectShowUtils.cpp
Expand Up @@ -298,7 +298,7 @@ GetUnconnectedPin(IBaseFilter* aFilter, PIN_DIRECTION aPinDir)
bool matches = FALSE;
if (SUCCEEDED(MatchUnconnectedPin(pin, aPinDir, &matches)) &&
matches) {
return pin;
return pin.forget();
}
}

Expand Down
4 changes: 2 additions & 2 deletions dom/media/mediasource/TrackBuffer.cpp
Expand Up @@ -551,7 +551,7 @@ TrackBuffer::QueueInitializeDecoder(SourceBufferDecoder* aDecoder)
&TrackBuffer::InitializeDecoder,
aDecoder);
// We need to initialize the reader on its own task queue
aDecoder->GetReader()->GetTaskQueue()->Dispatch(task);
aDecoder->GetReader()->GetTaskQueue()->Dispatch(task.forget());
return true;
}

Expand Down Expand Up @@ -1041,7 +1041,7 @@ TrackBuffer::RemoveDecoder(SourceBufferDecoder* aDecoder)
mInitializedDecoders.RemoveElement(aDecoder);
mDecoders.RemoveElement(aDecoder);
}
aDecoder->GetReader()->GetTaskQueue()->Dispatch(task);
aDecoder->GetReader()->GetTaskQueue()->Dispatch(task.forget());
}

bool
Expand Down
8 changes: 4 additions & 4 deletions dom/media/omx/MediaCodecReader.cpp
Expand Up @@ -334,7 +334,7 @@ MediaCodecReader::DispatchAudioTask()
RefPtr<nsIRunnable> task =
NS_NewRunnableMethod(this,
&MediaCodecReader::DecodeAudioDataTask);
mAudioTrack.mTaskQueue->Dispatch(task);
mAudioTrack.mTaskQueue->Dispatch(task.forget());
}
}

Expand All @@ -346,7 +346,7 @@ MediaCodecReader::DispatchVideoTask(int64_t aTimeThreshold)
NS_NewRunnableMethodWithArg<int64_t>(this,
&MediaCodecReader::DecodeVideoFrameTask,
aTimeThreshold);
mVideoTrack.mTaskQueue->Dispatch(task);
mVideoTrack.mTaskQueue->Dispatch(task.forget());
}
}

Expand Down Expand Up @@ -797,7 +797,7 @@ MediaCodecReader::TextureClientRecycleCallback(TextureClient* aClient)
RefPtr<nsIRunnable> task =
NS_NewRunnableMethod(this,
&MediaCodecReader::WaitFenceAndReleaseOutputBuffer);
mVideoTrack.mReleaseBufferTaskQueue->Dispatch(task);
mVideoTrack.mReleaseBufferTaskQueue->Dispatch(task.forget());
}
}

Expand Down Expand Up @@ -1931,7 +1931,7 @@ MediaCodecReader::VideoCodecCanceled()
if (mVideoTrack.mTaskQueue) {
RefPtr<nsIRunnable> task =
NS_NewRunnableMethod(this, &MediaCodecReader::ReleaseCriticalResources);
mVideoTrack.mTaskQueue->Dispatch(task);
mVideoTrack.mTaskQueue->Dispatch(task.forget());
}
}

Expand Down
6 changes: 3 additions & 3 deletions dom/media/omx/MediaOmxCommonDecoder.cpp
Expand Up @@ -119,7 +119,7 @@ MediaOmxCommonDecoder::PauseStateMachine()
GetStateMachine(),
&MediaDecoderStateMachine::SetDormant,
true);
GetStateMachine()->TaskQueue()->Dispatch(event);
GetStateMachine()->TaskQueue()->Dispatch(event.forget());
}

void
Expand Down Expand Up @@ -148,7 +148,7 @@ MediaOmxCommonDecoder::ResumeStateMachine()
GetStateMachine(),
&MediaDecoderStateMachine::Seek,
target);
GetStateMachine()->TaskQueue()->Dispatch(event);
GetStateMachine()->TaskQueue()->Dispatch(event.forget());

mNextState = mPlayState;
ChangeState(PLAY_STATE_LOADING);
Expand All @@ -158,7 +158,7 @@ MediaOmxCommonDecoder::ResumeStateMachine()
GetStateMachine(),
&MediaDecoderStateMachine::SetDormant,
false);
GetStateMachine()->TaskQueue()->Dispatch(event);
GetStateMachine()->TaskQueue()->Dispatch(event.forget());
UpdateLogicalPosition();
}

Expand Down
2 changes: 1 addition & 1 deletion dom/media/platforms/agnostic/BlankDecoderModule.cpp
Expand Up @@ -69,7 +69,7 @@ class BlankMediaDataDecoder : public MediaDataDecoder {
// with it, so the OutputEvent stores it in an nsAutoPtr and deletes
// it once it's run.
RefPtr<nsIRunnable> r(new OutputEvent(aSample, mCallback, mCreator));
mTaskQueue->Dispatch(r);
mTaskQueue->Dispatch(r.forget());
return NS_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion dom/media/platforms/wmf/MFTDecoder.cpp
Expand Up @@ -74,7 +74,7 @@ MFTDecoder::GetAttributes()
RefPtr<IMFAttributes> attr;
HRESULT hr = mDecoder->GetAttributes(byRef(attr));
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
return attr;
return attr.forget();
}

HRESULT
Expand Down
7 changes: 6 additions & 1 deletion dom/media/webaudio/MediaBufferDecoder.cpp
Expand Up @@ -507,7 +507,12 @@ AsyncDecodeWebAudio(const char* aContentType, uint8_t* aBuffer,
WebAudioDecodeJob::UnknownError);
NS_DispatchToMainThread(event);
} else {
task->Reader()->GetTaskQueue()->Dispatch(task);
// If we did this without a temporary:
// task->Reader()->GetTaskQueue()->Dispatch(task.forget())
// we might evaluate the task.forget() before calling Reader(). Enforce
// a non-crashy order-of-operations.
MediaTaskQueue* taskQueue = task->Reader()->GetTaskQueue();
taskQueue->Dispatch(task.forget());
}
}

Expand Down
4 changes: 2 additions & 2 deletions dom/media/webaudio/blink/HRTFDatabaseLoader.cpp
Expand Up @@ -56,15 +56,15 @@ TemporaryRef<HRTFDatabaseLoader> HRTFDatabaseLoader::createAndLoadAsynchronously
loader = entry->mLoader;
if (loader) { // existing entry
MOZ_ASSERT(sampleRate == loader->databaseSampleRate());
return loader;
return loader.forget();
}

loader = new HRTFDatabaseLoader(sampleRate);
entry->mLoader = loader;

loader->loadAsynchronously();

return loader;
return loader.forget();
}

HRTFDatabaseLoader::HRTFDatabaseLoader(float sampleRate)
Expand Down
3 changes: 2 additions & 1 deletion dom/svg/nsSVGPathGeometryElement.cpp
Expand Up @@ -89,7 +89,8 @@ nsSVGPathGeometryElement::GetOrBuildPath(const DrawTarget& aDrawTarget,
// looking at the global variable that the pref's stored in.
if (cacheable && mCachedPath) {
if (aDrawTarget.GetBackendType() == mCachedPath->GetBackendType()) {
return mCachedPath;
RefPtr<Path> path(mCachedPath);
return path.forget();
}
}
RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder(aFillRule);
Expand Down
2 changes: 1 addition & 1 deletion dom/system/gonk/MozMtpDatabase.cpp
Expand Up @@ -164,7 +164,7 @@ MozMtpDatabase::GetEntry(MtpObjectHandle aHandle)
if (aHandle > 0 && aHandle < mDb.Length()) {
entry = mDb[aHandle];
}
return entry;
return entry.forget();
}

void
Expand Down
9 changes: 5 additions & 4 deletions dom/system/gonk/VolumeManager.cpp
Expand Up @@ -75,7 +75,8 @@ TemporaryRef<Volume>
VolumeManager::GetVolume(size_t aIndex)
{
MOZ_ASSERT(aIndex < NumVolumes());
return sVolumeManager->mVolumeArray[aIndex];
RefPtr<Volume> vol = sVolumeManager->mVolumeArray[aIndex];
return vol.forget();
}

//static
Expand Down Expand Up @@ -135,7 +136,7 @@ VolumeManager::FindVolumeByName(const nsCSubstring& aName)
for (volIndex = 0; volIndex < numVolumes; volIndex++) {
RefPtr<Volume> vol = GetVolume(volIndex);
if (vol->Name().Equals(aName)) {
return vol;
return vol.forget();
}
}
return nullptr;
Expand All @@ -147,12 +148,12 @@ VolumeManager::FindAddVolumeByName(const nsCSubstring& aName)
{
RefPtr<Volume> vol = FindVolumeByName(aName);
if (vol) {
return vol;
return vol.forget();
}
// No volume found, create and add a new one.
vol = new Volume(aName);
sVolumeManager->mVolumeArray.AppendElement(vol);
return vol;
return vol.forget();
}

//static
Expand Down
2 changes: 1 addition & 1 deletion gfx/2d/DrawTarget.cpp
Expand Up @@ -21,7 +21,7 @@ DrawTarget::CreateCaptureDT(const IntSize& aSize)
return nullptr;
}

return dt;
return dt.forget();
}

void
Expand Down
3 changes: 2 additions & 1 deletion gfx/2d/DrawTargetCG.cpp
Expand Up @@ -197,7 +197,8 @@ DrawTargetCG::Snapshot()
mSnapshot = new SourceSurfaceCGBitmapContext(this);
}

return mSnapshot;
RefPtr<SourceSurface> snapshot(mSnapshot);
return snapshot.forget();
}

TemporaryRef<DrawTarget>
Expand Down
6 changes: 4 additions & 2 deletions gfx/2d/DrawTargetCairo.cpp
Expand Up @@ -658,7 +658,8 @@ TemporaryRef<SourceSurface>
DrawTargetCairo::Snapshot()
{
if (mSnapshot) {
return mSnapshot;
RefPtr<SourceSurface> snapshot(mSnapshot);
return snapshot.forget();
}

IntSize size = GetSize();
Expand All @@ -667,7 +668,8 @@ DrawTargetCairo::Snapshot()
size,
GfxFormatForCairoSurface(mSurface),
this);
return mSnapshot;
RefPtr<SourceSurface> snapshot(mSnapshot);
return snapshot.forget();
}

bool
Expand Down

0 comments on commit db188ea

Please sign in to comment.