LibWeb: Use ExternalContentSource for canvas painting

present() now snapshots the PaintingSurface into an ImmutableBitmap
and publishes it to the ExternalContentSource, so the rendering thread
never touches the live GPU surface — eliminating the data race
described in the ExternalContentSource commit (problem 1).

Canvas elements are registered with Page and presented once per frame
from the event loop, rather than on every individual draw call in
CRC2D::did_draw(). A dirty flag on HTMLCanvasElement ensures the
snapshot is only taken when content has actually changed, and makes
the present() call in CanvasPaintable::paint() a no-op when the
surface has already been snapshotted for the current frame.
This commit is contained in:
Aliaksandr Kalenik
2026-02-19 19:31:20 +01:00
committed by Alexander Kalenik
parent 8a31ecdf39
commit 004e5f851e
Notes: github-actions[bot] 2026-02-20 17:42:50 +00:00
11 changed files with 90 additions and 28 deletions

View File

@@ -392,6 +392,10 @@ void EventLoop::update_the_rendering()
for (auto& document : docs)
document->page().update_all_media_element_video_sinks();
// AD-HOC: Present all canvas element surfaces in documents' pages.
for (auto& document : docs)
document->page().present_all_canvas_element_surfaces();
// FIXME: 4. Unnecessary rendering: Remove from docs any Document object doc for which all of the following are true:
// FIXME: 5. Remove from docs all Document objects for which the user agent believes that it's preferable to skip updating the rendering for other reasons.