Bug 517091 - Don't do an expensive asynchronous RequestDecode() if there's already an active full decoder. r=joe
--- a/modules/libpr0n/src/imgContainer.cpp
+++ b/modules/libpr0n/src/imgContainer.cpp
@@ -2210,17 +2210,26 @@ imgContainer::RequestDecode()
// If we're not storing source data, we have nothing to do
if (!StoringSourceData())
return NS_OK;
// If we're fully decoded, we have nothing to do
if (mDecoded)
return NS_OK;
- // If we're within the decoder, request asynchronously
+ // If we've already got a full decoder running, we have nothing to do
+ if (mDecoder && !(mDecoderFlags & imgIDecoder::DECODER_FLAG_HEADERONLY))
+ return NS_OK;
+
+ // If our callstack goes through a header-only decoder, we have a problem.
+ // We need to shutdown the header-only decoder and replace it with a full
+ // decoder, but can't do that from within the decoder itself. Thus, we post
+ // an asynchronous event to the event loop to do it later. Since
+ // RequestDecode() is an asynchronous function this works fine (though it's
+ // a little slower).
if (mInDecoder) {
nsRefPtr<imgDecodeRequestor> requestor = new imgDecodeRequestor(this);
if (!requestor)
return NS_ERROR_OUT_OF_MEMORY;
return NS_DispatchToCurrentThread(requestor);
}