I'm in the process of removing all traces of synchronous image loading from Servo, building on top of one of this quarter's NCSU projects. I'm dealing with a test failure right now where I understand the problem, but I'm currently stumped on how to solve it, so I'm open to ideas.

THE PROBLEM:
<style>li { list-style-image: url(smiling.png) }</style>
<li></li>
<li></li>

In the old reftest world, image loads were synchronous to avoid problems with taking screenshots before the images had appeared. In the new world, laying out the first list element triggers an asynchronous request for the image. If the scheduling works out right, the image is loaded and decoded by the time the second list element is laid out, so it's fine. In my current code, the first element increases an atomic counter indicating the number of pending image requests.

At some point in the future, the image cache notifies the layout thread that an image was completely decoded, so we decrease the counter. The existing code in LayoutThread::handle_request (Request::FromImageCache) then calls `self.repaint`, but this does nothing for us - the first list element doesn't have any image to repaint, and there's nothing tying the completed image to that particular element. Thus, we proceed to take a screenshot of the page, but the first list element is missing its image.

For images where the load is initiated via the script thread, we have the Trusted<HTMLImageElement> mechanism that ensures that the element remains alive so we can interact with it as image data is received. There are no such guarantees in the layout thread - the script thread could remove the list element from the document right after layout completes and trigger a GC, before the layout thread gets any image load notification. I'm not sure what to do here - the layout thread seems to need to initiate a reflow in certain situations, but I can't figure out how to limit the damage to relevant nodes.

Cheers,
Josh
_______________________________________________
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo

Reply via email to