ImageLib decodes GIF, JPEG and PNG images, and provides the decoded data to the Compositor for display. If Firefox or Seamonkey can display an image when loaded separately from the page, ImageLib is working, and the actual imaging bug exists elsewhere within Firefox or Seamonkey.

This builds on the patch in Bug 684919 which adds COMPtrWithFlag<T>, which acts mostly like nsCOMPtr<T> with a flag bit. The API might change in that bug, so this may end up looking a bit different.
The flag bit is used to store whether or not the image should be tracked. Then we add a BindToTree/UnbindFromTree implementation that registers/unregisters the image with the document depending on the value of that flag.

Comment on attachment 558801[details][diff][review]
Patch
Review of attachment 558801[details][diff][review]:
-----------------------------------------------------------------
::: content/base/src/nsImageLoadingContent.cpp
@@ +329,5 @@
>
> // We can only do this if we have a presshell
> + // XXXkhuey should this be GetOurCurrentDocument? Decoding if we're not in
> + // the document seems silly.
> + nsIDocument* doc = GetOurOwnerDocument();
When do we have an owner document but not a current document? (This is one of the reasons I want a content person to review this. ;) )
@@ +845,5 @@
> + // XXXkhuey this is an incredibly nasty hack, but because cloning notifies
> + // synchronously, we can't use a temporary nsCOMPtr here (we'll assert to
> + // death in OnStopDecode). Note that the reference on the outparameter
> + // is owned by the RequestWithState, so this is not leaky, even though it
> + // looks like it might be. Bug 580466 shall save us!
Can you note in that bug so whoever fixes it knows to fix this too?

Comment on attachment 558801[details][diff][review]
Patch
Canceling review request for now per irc discussion. Specifically:
1) We're going to add a getter_AddRefs that takes a RequestWithState (or
generally a COMPtrAndFlag, I would think).
2) Kyle will test whether this gets us flicker on image-swapping tests and if so
how to deal with that.

Comment on attachment 558922[details][diff][review]
Patch
We discussed a possible bandaid for flickering issues on IRC, which is to do some amount of decoding synchronously in RasterImage::RequestDecode, and then do the rest (if any is left) asynchronously on the event loop. I'm going to file a separate bug for addressing that.

Note that with the attached patch (and without Bug 685516) we will always do a decode when <img>.src is set and we will always decode synchronously when inserting an image that has a compressed size of less than 150K into the DOM, so the potential for flicker is fairly low to begin with.

Comment on attachment 558922[details][diff][review]
Patch
> nsImageLoadingContent::ClearCurrentRequest(nsresult aReason)
>+ mCurrentRequest.Set(nsnull, false);
Why not Clear()?
Similar in ClearPendingRequest.
The comment about why GetOurDocument is not called GetDocument should now explain why the methods are not GetOwnerDoc and GetCurrentDoc.
Speaking of which, probably better to call the new methods GetOurOwnerDoc and GetOurCurrentDoc. But either way.
You need to add BindToTree and UnbindFromTree calling up into nsImageLoadingContent to nsSVGImageElement. r- for this part to make sure it happens.

(In reply to Boris Zbarsky (:bz) from comment #12)
> > Not sure if you wanted to look at this again ...
>
> I did. Hence the r- vs "r+ if you change this".
It felt more like an "r- so you pay attention" ;-)
Thanks for the review.

Comment on attachment 565836[details][diff][review]
Make RasterImage::GetFrame honor the flags it
r=bholley contingent on that followup bug discussed on IRC (factoring out the 3 copy-pasted instances of the 'screwed' code into a helper method).

Since I can't manage to get the tests running on android under a debugger, we have the following options:
1. Land this without Bug 685516.
2. Scope Bug 685516 to affect desktop only (in other words, keep synchronously decoding small images on mobile).
3. Find someone who can actually debug on android to debug the test failures in Bug 685516.

On behalf of Facebook Inc, let me just say that we are prepared to give over one thousand free "pokes" to anyone who fixes this bug or alternatively https://bugzilla.mozilla.org/show_bug.cgi?id=689623. I will also gladly show you Mark Zuckerberg's desk and give you free dinner and cookies as part of a complementary tour of Facebook HQ in Menlo Park.

This is one of two worst image-related bugs that we're aware of (the other is bug 689623). Tons of slideshows on the web hit this. On a memory-constrained mobile device, this is a particularly bad bug, so k90?.

Comment on attachment 644367[details][diff][review]
Patch, again
The indentation in nsNodeUtils.cpp is off, unless this is a diff -w.
It might make sense to put the flags next to mImageBlockingStatus and make the PRUin16 or even PRUint8 to make them pack better.
r=me with that.

(In reply to HyungGon Baek from comment #30)
> Is this patch for FF14?
This patch is for trunk, more or less.
> Can I get this patch for FF11?
If you do the work, yes. Otherwise, no. It's not a good use of my time to backport this to an unsupported version.

(In reply to Kyle Huey [:khuey] (khuey@mozilla.com) from comment #31)
> > Can I get this patch for FF11?
>
> If you do the work, yes. Otherwise, no. It's not a good use of my time to
> backport this to an unsupported version.
Not to mention entirely insecure. Please upgrade to the latest version of Firefox!

(In reply to Jim Jeffery not reading bug-mail 1/2/11 from comment #35)
> Appears to me its re-landed just today on m-i, should be coming to m-c next
> merge hopefully, unless it backed out again:
It originated from the build-system repo and was merged to m-c first, then inbound.