[webkit-dev] Canvas performance and memory usage
David Hyatt
hyatt at apple.com
Mon Aug 16 15:15:39 PDT 2010
The changes to ImageBuffer have landed. Here is what port authors need to know:
Image* image() on ImageBuffer is gone.
It has been replaced with:
PassRefPtr<Image> copyImage()
This function should always simply copy the image. It is used in any place where you want to get a snapshot of the ImageBuffer and not be broken if the ImageBuffer subsequently changes.
For drawing, callers should now use drawImageBuffer on GraphicsContext instead of drawImage. drawImageBuffer internally just turns around and calls a draw function on ImageBuffer. clipToImageBuffer now also turns around and calls clip on the ImageBuffer.
void clip(GraphicsContext*, const FloatRect&) const;
// The draw method draws the contents of the buffer without copying it.
void draw(GraphicsContext*, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1),
CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform,
const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
I've made sure the above functions are implemented in the various ports, although the Skia and Cairo implementations currently draw by copying the image and then just calling drawImage. I've left it up to those ports to fix this issue (the current behavior is the same on those platforms as it was before my patch).
There is a temporary method implemented by all ports called:
bool drawsUsingCopy() const; // If the image buffer has to render using a copied image, it will return true.
This method only exists right now because some of the ports are still copying. Once everyone has switched over to drawing the image buffer without making copies, then I can remove this method from the interface. HTMLCanvasElement is using it in order to cache a copy of the image for repeated drawing of a static canvas, so that the "copying" platforms don't suffer a performance degradation from my changes.
Feel free to ping me on IRC or in email if you have any questions about this change.
Thanks,
Dave
(hyatt at apple.com)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20100816/f10d9d00/attachment.html>
More information about the webkit-dev
mailing list