LibWeb+LibGfx: Support alpha in CanvasRenderingContext2D

This is implemented by these related changes:

  * The Skia alpha type 'Opaque' is selected for surfaces that were
    created with the intention of not having an alpha channel.
    Previously we were simply creating one with alpha.

  * Clearing now happens through Skia's `clear()` which always uses the
    source color's value for the result, instead of setting all values
    to 0.

  * CanvasRenderingContext2D selects a different clearing color based on
    the `alpha` context attribute's value.
This commit is contained in:
Jelle Raaijmakers 2025-04-28 16:12:30 +02:00
commit 35efd4d14b
Notes: github-actions[bot] 2025-04-29 11:52:28 +00:00
7 changed files with 68 additions and 12 deletions

View file

@ -125,11 +125,11 @@ PainterSkia::~PainterSkia() = default;
void PainterSkia::clear_rect(Gfx::FloatRect const& rect, Gfx::Color color)
{
SkPaint paint;
paint.setColor(to_skia_color(color));
paint.setBlendMode(SkBlendMode::kClear);
impl().with_canvas([&](auto& canvas) {
canvas.drawRect(to_skia_rect(rect), paint);
canvas.save();
canvas.clipRect(to_skia_rect(rect));
canvas.clear(to_skia_color(color));
canvas.restore();
});
}