mirror of
https://github.com/servo/servo
synced 2026-05-14 19:06:31 +02:00
Canvas expects input data to be in RGBA premultiplied format and WebRender already supports RGBA and BGRA data as long as they are premultiplied. Pre-multiplying up front allows: - Avoiding many conversions when painting images to canvas. - Passing the `RasterImage` IpcSharedMemory of the image instead of creating a new one with the premultiplied data every time we upload to WebRender. This is a big deal for animated gifs, because before every frame was creating a new shared memory segment. It seems that for rasterized SVGs were were already putting premultplied data into the `RasterImage` so it's quite likely SVGs were being composited incorrectly. Testing: This causes 8 tests to start passing and 2 tests to fail in the WebGL conformance suite. The failures are due to the fact that premultiplying alpha is lossy when alpha is 0. In that case, the resulting color of a blend operation might be wrong. This is typically only a problem if you use RGBA data as RGB data, which is pretty unusual. In the case that you are blending with RGBA the final color values will be 0 or close to 0 anyway. Gecko solves this issue by having a cacheable surface generation API that can fetch both premulitplied and unpremulitplied data from things like image elements. We do not have that yet, but I argue that this change is important anyway due to the amount that it reduces memory and file descriptor usage as well as the cost of copying image data so much in memory. Signed-off-by: Martin Robinson <mrobinson@igalia.com>