Bug 799335. Fix unintenional image flash on tab switch. r=joe,dholbert
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Fri, 12 Oct 2012 16:04:32 -0400
changeset 110279 0ea416c21d176c96e9a792128a806245606e9fde
parent 110278 b8970531e93ee8b034c6e55650145ff43424f6e5
child 110280 5f1d0cfe99ace6c6383bd98230ea2ee986471c51
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjoe, dholbert
bugs799335, 792199
milestone19.0a1
Bug 799335. Fix unintenional image flash on tab switch. r=joe,dholbert This was caused by bug 792199. There are two parts to this fix: 1. Always decode during StartDecoding even if we already have a Decoder (hopefully this is safe) This was a bug in the original patch. 2. After calling StartDecoding() we recheck if we're complete and abort if we're not doing a SYNC_DECODE. Before this regression we would usually be done decoding the image because of the decoding we did when we Locked all of the images on tab switch.
image/src/RasterImage.cpp
layout/base/nsCSSRendering.cpp
--- a/image/src/RasterImage.cpp
+++ b/image/src/RasterImage.cpp
@@ -2547,19 +2547,25 @@ RasterImage::RequestDecodeCore(RequestDe
   // If we're fully decoded, we have nothing to do
   if (mDecoded)
     return NS_OK;
 
   // If we're not storing source data, we have nothing to do
   if (!StoringSourceData())
     return NS_OK;
 
-  // If we've already got a full decoder running, we have nothing to do
-  if (mDecoder && !mDecoder->IsSizeDecode())
+  // If we've already got a full decoder running, we'll spend a bit of time
+  // decoding because the caller want's an image soon.
+  if (mDecoder && !mDecoder->IsSizeDecode()) {
+    if (!mDecoded && !mInDecoder && mHasSourceData && aDecodeType == SOMEWHAT_SYNCHRONOUS) {
+      SAMPLE_LABEL_PRINTF("RasterImage", "DecodeABitOf", "%s", GetURIString());
+      DecodeWorker::Singleton()->DecodeABitOf(this);
+    }
     return NS_OK;
+  }
 
   // mFinishing protects against the case when we enter RequestDecode from
   // ShutdownDecoder -- in that case, we're done with the decode, we're just
   // not quite ready to admit it.  See bug 744309.
   if (mFinishing)
     return NS_OK;
 
   // If our callstack goes through a size decoder, we have a problem.
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -4009,29 +4009,35 @@ nsImageRenderer::nsImageRenderer(nsIFram
 
 nsImageRenderer::~nsImageRenderer()
 {
 }
 
 bool
 nsImageRenderer::PrepareImage()
 {
-  if (mImage->IsEmpty() || !mImage->IsComplete()) {
+  if (mImage->IsEmpty())
+    return false;
+
+  if (!mImage->IsComplete()) {
     // Make sure the image is actually decoding
     mImage->StartDecoding();
 
-    // We can not prepare the image for rendering if it is not fully loaded.
-    //
-    // Special case: If we requested a sync decode and we have an image, push
-    // on through
-    nsCOMPtr<imgIContainer> img;
-    if (!((mFlags & FLAG_SYNC_DECODE_IMAGES) &&
-          (mType == eStyleImageType_Image) &&
-          (NS_SUCCEEDED(mImage->GetImageData()->GetImage(getter_AddRefs(img))) && img)))
-      return false;
+    // check again to see if we finished
+    if (!mImage->IsComplete()) {
+      // We can not prepare the image for rendering if it is not fully loaded.
+      //
+      // Special case: If we requested a sync decode and we have an image, push
+      // on through because the Draw() will do a sync decode then
+      nsCOMPtr<imgIContainer> img;
+      if (!((mFlags & FLAG_SYNC_DECODE_IMAGES) &&
+            (mType == eStyleImageType_Image) &&
+            (NS_SUCCEEDED(mImage->GetImageData()->GetImage(getter_AddRefs(img))) && img)))
+        return false;
+    }
   }
 
   switch (mType) {
     case eStyleImageType_Image:
     {
       nsCOMPtr<imgIContainer> srcImage;
       mImage->GetImageData()->GetImage(getter_AddRefs(srcImage));
       NS_ABORT_IF_FALSE(srcImage, "If srcImage is null, mImage->IsComplete() "