When retrieving the unmultiplied pixel data via CanvasRenderingContext2D's getImageData(), QtWebKit currently does the following: 1. QPixmap::toImage() (our canvas is backed by a QPixmap) 2. QImage::convertToFormat(ARGB32) 3. Copy image byte-by-byte to destination buffer swapping Red and Blue channels. Benchmarking with http://www.semantix.gr/statue.html I get these numbers before any changes: 23.43 FPS { 23.52, 23.49, 23.41, 23.46, 23.48, 23.35, 23.33 } We can optimize this as such: 1. QPixmap::toImage() 2. QImage::convertToFormat(ARGB32_PM) (no-op on raster paintengine) 3. Copy image pixel by pixel to destination buffer doing combined RGB->BGR and un-premultiplication. Same benchmark with the above algorithm: 25.19 FPS { 25.15, 25.22, 25.32, 25.31, 25.03, 25.07, 25.23 }
Created attachment 62523 [details] Proposed patch
Comment on attachment 62523 [details] Proposed patch WebCore/platform/graphics/qt/ImageBufferQt.cpp:178 + QImage image = imageData.m_pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied); I think it would be nice with a comment here why you disconsider the bool multiplied, people might think that is an error in the future. WebCore/platform/graphics/qt/ImageBufferQt.cpp:212 + pixel = ((pixel << 16) & 0xff0000) | ((pixel >> 16) & 0xff) | (pixel & 0xff00ff00); Maybe you should explain the RGB->BGR swapping here, just like a little comment
Comment on attachment 62523 [details] Proposed patch r- due to comments from John Brooks on IRC; this code should have a special path for opaque colors.
Created attachment 62557 [details] Proposed patch v2 Added special path for un-premultiplication when alpha == 255. Also added comments like Kenneth requested.
Comment on attachment 62557 [details] Proposed patch v2 Clearing flags on attachment: 62557 Committed r64041: <http://trac.webkit.org/changeset/64041>
All reviewed patches have been landed. Closing bug.