Change canvas/context/snapshot size from u64 -> u32 (#36827)

Replaces uses of `euclid::default::Size2D<u64>` with
`euclid::default::Size2D<u32>` for the canvas/context/snapshot.

This PR includes changes to the following components:
 - canvas
 - pixels
 - script
 - script_bindings
 - shared/canvas
 - shared/snapshot

Testing: https://github.com/hashcatHitman/servo/actions/runs/15426115391
(as of 892edc0048)

Fixes: #36706

---------

Signed-off-by: hashcatHitman <155700084+hashcatHitman@users.noreply.github.com>
This commit is contained in:
Sam K 2025-06-07 14:37:21 +00:00 committed by GitHub
parent 87de9fdf8c
commit a625420b23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 69 additions and 69 deletions

View file

@ -397,8 +397,8 @@ impl HTMLCanvasElement {
// u32 can't panic, since the data comes from a canvas which is always smaller than
// u32::MAX.
let canvas_data = snapshot.data();
let width = snapshot.size().width as u32;
let height = snapshot.size().height as u32;
let width = snapshot.size().width;
let height = snapshot.size().height;
match image_type {
EncodedImageType::Png => {

View file

@ -154,8 +154,8 @@ impl ImageData {
}
#[allow(unsafe_code)]
pub(crate) unsafe fn get_rect(&self, rect: Rect<u64>) -> Cow<[u8]> {
pixels::rgba8_get_rect(self.as_slice(), self.get_size().to_u64(), rect)
pub(crate) unsafe fn get_rect(&self, rect: Rect<u32>) -> Cow<[u8]> {
pixels::rgba8_get_rect(self.as_slice(), self.get_size().to_u32(), rect)
}
pub(crate) fn get_size(&self) -> Size2D<u32> {

View file

@ -72,8 +72,11 @@ impl OffscreenCanvas {
)
}
pub(crate) fn get_size(&self) -> Size2D<u64> {
Size2D::new(self.Width(), self.Height())
pub(crate) fn get_size(&self) -> Size2D<u32> {
Size2D::new(
self.Width().try_into().unwrap_or(u32::MAX),
self.Height().try_into().unwrap_or(u32::MAX),
)
}
pub(crate) fn origin_is_clean(&self) -> bool {

View file

@ -534,7 +534,7 @@ impl WebGL2RenderingContext {
let src_origin = Point2D::new(x, y);
let src_size = Size2D::new(width as u32, height as u32);
let fb_size = Size2D::new(fb_width as u32, fb_height as u32);
match pixels::clip(src_origin, src_size.to_u64(), fb_size.to_u64()) {
match pixels::clip(src_origin, src_size.to_u32(), fb_size.to_u32()) {
Some(rect) => rect.to_u32(),
None => return,
}
@ -2183,7 +2183,7 @@ impl WebGL2RenderingContextMethods<crate::DomTypeHolder> for WebGL2RenderingCont
let src_origin = Point2D::new(x, y);
let src_size = Size2D::new(width as u32, height as u32);
let fb_size = Size2D::new(fb_width as u32, fb_height as u32);
if pixels::clip(src_origin, src_size.to_u64(), fb_size.to_u64()).is_none() {
if pixels::clip(src_origin, src_size.to_u32(), fb_size.to_u32()).is_none() {
return;
}
}

View file

@ -3838,7 +3838,7 @@ impl WebGLRenderingContextMethods<crate::DomTypeHolder> for WebGLRenderingContex
let src_origin = Point2D::new(x, y);
let src_size = Size2D::new(width as u32, height as u32);
let fb_size = Size2D::new(fb_width as u32, fb_height as u32);
let src_rect = match pixels::clip(src_origin, src_size.to_u64(), fb_size.to_u64()) {
let src_rect = match pixels::clip(src_origin, src_size.to_u32(), fb_size.to_u32()) {
Some(rect) => rect,
None => return,
};

View file

@ -167,8 +167,8 @@ impl GPUCanvasContext {
// causes FAIL on webgpu:web_platform,canvas,configure:usage:*
usage: configuration.usage | GPUTextureUsageConstants::COPY_SRC,
size: GPUExtent3D::GPUExtent3DDict(GPUExtent3DDict {
width: size.width as u32,
height: size.height as u32,
width: size.width,
height: size.height,
depthOrArrayLayers: 1,
}),
viewFormats: configuration.viewFormats.clone(),

View file

@ -129,10 +129,7 @@ impl XRWebGLLayer {
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(canvas) => canvas.get_size(),
HTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(canvas) => {
let size = canvas.get_size();
Size2D::new(
size.width.try_into().unwrap_or(0),
size.height.try_into().unwrap_or(0),
)
Size2D::new(size.width, size.height)
},
};
Size2D::from_untyped(size)