From 79b30e7c9a8d3cfdf40750c212eda00c5e6bdae1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 24 Aug 2025 15:50:24 +0200 Subject: [PATCH] LibWeb: Create a new painter after resizing canvas element backing store Otherwise, we just keep painting into the old backing store. This fixes an issue where the main spreadsheet area in Google Sheets was not visually updating, despite everything looking good in memory. --- .../LibWeb/HTML/CanvasRenderingContext2D.cpp | 2 ++ .../resize-canvas-and-keep-painting.txt | 4 ++++ .../resize-canvas-and-keep-painting.html | 20 +++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/canvas/resize-canvas-and-keep-painting.txt create mode 100644 Tests/LibWeb/Text/input/canvas/resize-canvas-and-keep-painting.html diff --git a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp index 9e2b243e86d..bc171aa20c6 100644 --- a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp +++ b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp @@ -222,6 +222,7 @@ void CanvasRenderingContext2D::set_size(Gfx::IntSize const& size) return; m_size = size; m_surface = nullptr; + m_painter = nullptr; } void CanvasRenderingContext2D::allocate_painting_surface_if_needed() @@ -238,6 +239,7 @@ void CanvasRenderingContext2D::allocate_painting_surface_if_needed() auto skia_backend_context = canvas_element().navigable()->traversable_navigable()->skia_backend_context(); m_surface = Gfx::PaintingSurface::create_with_size(skia_backend_context, canvas_element().bitmap_size_for_canvas(), color_type, Gfx::AlphaType::Premultiplied); + m_painter = nullptr; // https://html.spec.whatwg.org/multipage/canvas.html#the-canvas-settings:concept-canvas-alpha // Thus, the bitmap of such a context starts off as opaque black instead of transparent black; diff --git a/Tests/LibWeb/Text/expected/canvas/resize-canvas-and-keep-painting.txt b/Tests/LibWeb/Text/expected/canvas/resize-canvas-and-keep-painting.txt new file mode 100644 index 00000000000..fc0bdc8a71c --- /dev/null +++ b/Tests/LibWeb/Text/expected/canvas/resize-canvas-and-keep-painting.txt @@ -0,0 +1,4 @@ +0 +128 +0 +255 diff --git a/Tests/LibWeb/Text/input/canvas/resize-canvas-and-keep-painting.html b/Tests/LibWeb/Text/input/canvas/resize-canvas-and-keep-painting.html new file mode 100644 index 00000000000..ebf190e425f --- /dev/null +++ b/Tests/LibWeb/Text/input/canvas/resize-canvas-and-keep-painting.html @@ -0,0 +1,20 @@ + + + +