canvas: Make 2D context state creation failable and use dom_canvas_backend pref for backend selection (#38310)

Before script just crashed in those cases because IPCSender was dropped,
now we send `None` to tell script about the failure and fail getContext
or registerPainter accordingly.
This PR also unifies `dom_canvas_{backends}_enabled` prefs into
`dom_canvas_backend` which is more flexible in multi-backends scenarios.

Reviewable per commit.

Testing: Added servo specific WPT test.

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
sagudev 2025-07-28 11:13:07 +02:00 committed by GitHub
parent 93d234d270
commit ae69646371
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 116 additions and 61 deletions

View file

@ -42,23 +42,25 @@ pub(crate) struct PaintRenderingContext2D {
}
impl PaintRenderingContext2D {
fn new_inherited(global: &PaintWorkletGlobalScope) -> PaintRenderingContext2D {
PaintRenderingContext2D {
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
fn new_inherited(global: &PaintWorkletGlobalScope) -> Option<PaintRenderingContext2D> {
Some(PaintRenderingContext2D {
reflector_: Reflector::new(),
canvas_state: CanvasState::new(global.upcast(), Size2D::zero()),
canvas_state: CanvasState::new(global.upcast(), Size2D::zero())?,
device_pixel_ratio: Cell::new(Scale::new(1.0)),
}
})
}
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
pub(crate) fn new(
global: &PaintWorkletGlobalScope,
can_gc: CanGc,
) -> DomRoot<PaintRenderingContext2D> {
reflect_dom_object(
Box::new(PaintRenderingContext2D::new_inherited(global)),
) -> Option<DomRoot<PaintRenderingContext2D>> {
Some(reflect_dom_object(
Box::new(PaintRenderingContext2D::new_inherited(global)?),
global,
can_gc,
)
))
}
/// Send update to canvas paint thread and returns [`ImageKey`]