canvas: ensure there is a subpath in PathBuilderRef (#37251)

This is also required by spec:
https://html.spec.whatwg.org/multipage/canvas.html#ensure-there-is-a-subpath
and if we not ensure it vello will trigger debug asserts. Enforcing this
at `PathBuilderRef` is the lowest possible level that avoids misuse (and
avoids IPC messages if we were to do this in content process) while
still keeping it from backend.

Testing: There are tests in WPT
Split of https://github.com/servo/servo/pull/36821
try run: https://github.com/sagudev/servo/actions/runs/15449044694

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
sagudev 2025-06-05 04:47:37 +02:00 committed by GitHub
parent b13f49ab09
commit ffe9163892
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 10 deletions

View file

@ -710,7 +710,7 @@ impl GenericPathBuilder<RaqoteBackend> for PathBuilder {
PathOp::MoveTo(point) | PathOp::LineTo(point) => Some(Point2D::new(point.x, point.y)),
PathOp::CubicTo(_, _, point) => Some(Point2D::new(point.x, point.y)),
PathOp::QuadTo(_, point) => Some(Point2D::new(point.x, point.y)),
PathOp::Close => None,
PathOp::Close => path.ops.first().and_then(get_first_point),
})
}
@ -733,6 +733,15 @@ impl GenericPathBuilder<RaqoteBackend> for PathBuilder {
}
}
fn get_first_point(op: &PathOp) -> Option<euclid::Point2D<f32, euclid::UnknownUnit>> {
match op {
PathOp::MoveTo(point) | PathOp::LineTo(point) => Some(Point2D::new(point.x, point.y)),
PathOp::CubicTo(point, _, _) => Some(Point2D::new(point.x, point.y)),
PathOp::QuadTo(point, _) => Some(Point2D::new(point.x, point.y)),
PathOp::Close => None,
}
}
pub trait ToRaqoteStyle {
type Target;