diff --git a/image/DecodePool.cpp b/image/DecodePool.cpp index 5101451c11f9..9aa3d58229f4 100644 --- a/image/DecodePool.cpp +++ b/image/DecodePool.cpp @@ -328,7 +328,7 @@ DecodePool::AsyncRun(IDecodingTask* aTask) mImpl->PushWork(aTask); } -void +bool DecodePool::SyncRunIfPreferred(IDecodingTask* aTask) { MOZ_ASSERT(NS_IsMainThread()); @@ -336,10 +336,11 @@ DecodePool::SyncRunIfPreferred(IDecodingTask* aTask) if (aTask->ShouldPreferSyncRun()) { aTask->Run(); - return; + return true; } AsyncRun(aTask); + return false; } void diff --git a/image/DecodePool.h b/image/DecodePool.h index 9d62731e500f..e8823d4f0118 100644 --- a/image/DecodePool.h +++ b/image/DecodePool.h @@ -62,8 +62,9 @@ public: * itself to make this decision; @see IDecodingTask::ShouldPreferSyncRun(). If * @aTask doesn't prefer it, just run @aTask asynchronously and return * immediately. + * @return true if the task was run sync, false otherwise. */ - void SyncRunIfPreferred(IDecodingTask* aTask); + bool SyncRunIfPreferred(IDecodingTask* aTask); /** * Run @aTask synchronously. This does not guarantee that @aTask will complete diff --git a/image/RasterImage.cpp b/image/RasterImage.cpp index ed5624d42c70..edeac73fb7b7 100644 --- a/image/RasterImage.cpp +++ b/image/RasterImage.cpp @@ -336,10 +336,10 @@ RasterImage::LookupFrame(const IntSize& aSize, !mAnimationState || mAnimationState->KnownFrameCount() < 1, "Animated frames should be locked"); - Decode(requestedSize, aFlags, aPlaybackType); + bool ranSync = Decode(requestedSize, aFlags, aPlaybackType); - // If we can sync decode, we should already have the frame. - if (aFlags & FLAG_SYNC_DECODE) { + // If we can or did sync decode, we should already have the frame. + if (ranSync || (aFlags & FLAG_SYNC_DECODE)) { result = LookupFrameInternal(requestedSize, aFlags, aPlaybackType); } } @@ -1080,7 +1080,7 @@ RasterImage::RequestDecodeForSize(const IntSize& aSize, uint32_t aFlags) return NS_OK; } -static void +static bool LaunchDecodingTask(IDecodingTask* aTask, RasterImage* aImage, uint32_t aFlags, @@ -1093,24 +1093,24 @@ LaunchDecodingTask(IDecodingTask* aTask, js::ProfileEntry::Category::GRAPHICS, "%s", aImage->GetURIString().get()); DecodePool::Singleton()->SyncRunIfPossible(aTask); - return; + return true; } if (aFlags & imgIContainer::FLAG_SYNC_DECODE_IF_FAST) { PROFILER_LABEL_PRINTF("DecodePool", "SyncRunIfPreferred", js::ProfileEntry::Category::GRAPHICS, "%s", aImage->GetURIString().get()); - DecodePool::Singleton()->SyncRunIfPreferred(aTask); - return; + return DecodePool::Singleton()->SyncRunIfPreferred(aTask); } } // Perform an async decode. We also take this path if we don't have all the // source data yet, since sync decoding is impossible in that situation. DecodePool::Singleton()->AsyncRun(aTask); + return false; } -NS_IMETHODIMP +bool RasterImage::Decode(const IntSize& aSize, uint32_t aFlags, PlaybackType aPlaybackType) @@ -1118,13 +1118,13 @@ RasterImage::Decode(const IntSize& aSize, MOZ_ASSERT(NS_IsMainThread()); if (mError) { - return NS_ERROR_FAILURE; + return false; } // If we don't have a size yet, we can't do any other decoding. if (!mHasSize) { mWantFullDecode = true; - return NS_OK; + return false; } // We're about to decode again, which may mean that some of the previous sizes @@ -1169,14 +1169,13 @@ RasterImage::Decode(const IntSize& aSize, // Make sure DecoderFactory was able to create a decoder successfully. if (!task) { - return NS_ERROR_FAILURE; + return false; } mDecodeCount++; // We're ready to decode; start the decoder. - LaunchDecodingTask(task, this, aFlags, mHasSourceData); - return NS_OK; + return LaunchDecodingTask(task, this, aFlags, mHasSourceData); } NS_IMETHODIMP diff --git a/image/RasterImage.h b/image/RasterImage.h index 9fe86fde3ffa..bc80e77c258d 100644 --- a/image/RasterImage.h +++ b/image/RasterImage.h @@ -336,10 +336,12 @@ private: * * It's an error to call Decode() before this image's intrinsic size is * available. A metadata decode must successfully complete first. + * + * Returns true of the decode was run synchronously. */ - NS_IMETHOD Decode(const gfx::IntSize& aSize, - uint32_t aFlags, - PlaybackType aPlaybackType); + bool Decode(const gfx::IntSize& aSize, + uint32_t aFlags, + PlaybackType aPlaybackType); /** * Creates and runs a metadata decoder, either synchronously or