Bug 517091 - Don't do an expensive asynchronous RequestDecode() if there's already an active full decoder. r=joe
authorBobby Holley <bobbyholley@stanford.edu>
Sat, 19 Sep 2009 12:33:00 -0700
changeset 32884 54f161dc183aea7dd3c38a2bd2fbf8fa1fdba0c2
parent 32883 c899688404f7dcb940a51e7653e7a96bc3b59ec0
child 32885 c655e28003ef81c439d07e55af5ada467784cd7b
push id9214
push userbobbyholley@stanford.edu
push dateSat, 19 Sep 2009 19:34:34 +0000
treeherdermozilla-central@54f161dc183a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe
bugs517091
milestone1.9.3a1pre
Bug 517091 - Don't do an expensive asynchronous RequestDecode() if there's already an active full decoder. r=joe
modules/libpr0n/src/imgContainer.cpp
--- 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);
   }