mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Initial move of canvas/context/snapshot size from u64 -> u32
Changed the two instances of `euclid::default::Size2D<u64>` in `servo/components/script/canvas_context.rs` and `servo/components/shared/snapshot/lib.rs` that were outlined as the bare minimum in "Make canvas/context/snapshot size be u32 everywhere" to `euclid::default::Size2D<u32>`. Every other change made in this commit is either: - of similar nature, and is the minimum that would allow compilation - resolving lints triggered by the former More might be needed to complete the issue, but I feel like this is a good starting point. This commit includes changes to the following components: - canvas - pixels - script - shared/canvas - shared/snapshot Signed-off-by: hashcatHitman <155700084+hashcatHitman@users.noreply.github.com>
This commit is contained in:
parent
c94605b13e
commit
326a2e9ab6
14 changed files with 53 additions and 53 deletions
|
@ -447,7 +447,7 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
||||||
pub(crate) fn draw_image(
|
pub(crate) fn draw_image(
|
||||||
&mut self,
|
&mut self,
|
||||||
image_data: &[u8],
|
image_data: &[u8],
|
||||||
image_size: Size2D<u64>,
|
image_size: Size2D<u32>,
|
||||||
dest_rect: Rect<f64>,
|
dest_rect: Rect<f64>,
|
||||||
source_rect: Rect<f64>,
|
source_rect: Rect<f64>,
|
||||||
smoothing_enabled: bool,
|
smoothing_enabled: bool,
|
||||||
|
@ -457,7 +457,7 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
||||||
let source_rect = source_rect.ceil();
|
let source_rect = source_rect.ceil();
|
||||||
// It discards the extra pixels (if any) that won't be painted
|
// It discards the extra pixels (if any) that won't be painted
|
||||||
let image_data = if Rect::from_size(image_size.to_f64()).contains_rect(&source_rect) {
|
let image_data = if Rect::from_size(image_size.to_f64()).contains_rect(&source_rect) {
|
||||||
pixels::rgba8_get_rect(image_data, image_size, source_rect.to_u64()).into()
|
pixels::rgba8_get_rect(image_data, image_size, source_rect.to_u32()).into()
|
||||||
} else {
|
} else {
|
||||||
image_data.into()
|
image_data.into()
|
||||||
};
|
};
|
||||||
|
@ -1221,7 +1221,7 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
||||||
pub(crate) fn put_image_data(&mut self, mut imagedata: Vec<u8>, rect: Rect<u64>) {
|
pub(crate) fn put_image_data(&mut self, mut imagedata: Vec<u8>, rect: Rect<u32>) {
|
||||||
assert_eq!(imagedata.len() % 4, 0);
|
assert_eq!(imagedata.len() % 4, 0);
|
||||||
assert_eq!(rect.size.area() as usize, imagedata.len() / 4);
|
assert_eq!(rect.size.area() as usize, imagedata.len() / 4);
|
||||||
pixels::rgba8_byte_swap_and_premultiply_inplace(&mut imagedata);
|
pixels::rgba8_byte_swap_and_premultiply_inplace(&mut imagedata);
|
||||||
|
@ -1310,8 +1310,8 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub(crate) fn read_pixels(
|
pub(crate) fn read_pixels(
|
||||||
&self,
|
&self,
|
||||||
read_rect: Option<Rect<u64>>,
|
read_rect: Option<Rect<u32>>,
|
||||||
canvas_size: Option<Size2D<u64>>,
|
canvas_size: Option<Size2D<u32>>,
|
||||||
) -> Snapshot {
|
) -> Snapshot {
|
||||||
let canvas_size = canvas_size.unwrap_or(self.drawtarget.get_size().cast());
|
let canvas_size = canvas_size.unwrap_or(self.drawtarget.get_size().cast());
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,7 @@ impl<'a> CanvasPaintThread<'a> {
|
||||||
Canvas2dMsg::DrawEmptyImage(image_size, dest_rect, source_rect) => {
|
Canvas2dMsg::DrawEmptyImage(image_size, dest_rect, source_rect) => {
|
||||||
self.canvas(canvas_id).draw_image(
|
self.canvas(canvas_id).draw_image(
|
||||||
&vec![0; image_size.area() as usize * 4],
|
&vec![0; image_size.area() as usize * 4],
|
||||||
image_size.to_u64(),
|
image_size.to_u32(),
|
||||||
dest_rect,
|
dest_rect,
|
||||||
source_rect,
|
source_rect,
|
||||||
false,
|
false,
|
||||||
|
@ -203,10 +203,10 @@ impl<'a> CanvasPaintThread<'a> {
|
||||||
) => {
|
) => {
|
||||||
let image_data = self
|
let image_data = self
|
||||||
.canvas(canvas_id)
|
.canvas(canvas_id)
|
||||||
.read_pixels(Some(source_rect.to_u64()), Some(image_size.to_u64()));
|
.read_pixels(Some(source_rect.to_u32()), Some(image_size.to_u32()));
|
||||||
self.canvas(other_canvas_id).draw_image(
|
self.canvas(other_canvas_id).draw_image(
|
||||||
image_data.data(),
|
image_data.data(),
|
||||||
source_rect.size.to_u64(),
|
source_rect.size.to_u32(),
|
||||||
dest_rect,
|
dest_rect,
|
||||||
source_rect,
|
source_rect,
|
||||||
smoothing,
|
smoothing,
|
||||||
|
@ -398,7 +398,7 @@ impl Canvas<'_> {
|
||||||
fn draw_image(
|
fn draw_image(
|
||||||
&mut self,
|
&mut self,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
size: Size2D<u64>,
|
size: Size2D<u32>,
|
||||||
dest_rect: Rect<f64>,
|
dest_rect: Rect<f64>,
|
||||||
source_rect: Rect<f64>,
|
source_rect: Rect<f64>,
|
||||||
smoothing_enabled: bool,
|
smoothing_enabled: bool,
|
||||||
|
@ -418,8 +418,8 @@ impl Canvas<'_> {
|
||||||
|
|
||||||
fn read_pixels(
|
fn read_pixels(
|
||||||
&mut self,
|
&mut self,
|
||||||
read_rect: Option<Rect<u64>>,
|
read_rect: Option<Rect<u32>>,
|
||||||
canvas_size: Option<Size2D<u64>>,
|
canvas_size: Option<Size2D<u32>>,
|
||||||
) -> snapshot::Snapshot {
|
) -> snapshot::Snapshot {
|
||||||
match self {
|
match self {
|
||||||
Canvas::Raqote(canvas_data) => canvas_data.read_pixels(read_rect, canvas_size),
|
Canvas::Raqote(canvas_data) => canvas_data.read_pixels(read_rect, canvas_size),
|
||||||
|
@ -612,7 +612,7 @@ impl Canvas<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn put_image_data(&mut self, unwrap: Vec<u8>, rect: Rect<u64>) {
|
fn put_image_data(&mut self, unwrap: Vec<u8>, rect: Rect<u32>) {
|
||||||
match self {
|
match self {
|
||||||
Canvas::Raqote(canvas_data) => canvas_data.put_image_data(unwrap, rect),
|
Canvas::Raqote(canvas_data) => canvas_data.put_image_data(unwrap, rect),
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub fn compute_rgba8_byte_length_if_within_limit(width: usize, height: usize) ->
|
||||||
.filter(|v| *v <= MAX_IMAGE_BYTE_LENGTH)
|
.filter(|v| *v <= MAX_IMAGE_BYTE_LENGTH)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rgba8_get_rect(pixels: &[u8], size: Size2D<u64>, rect: Rect<u64>) -> Cow<[u8]> {
|
pub fn rgba8_get_rect(pixels: &[u8], size: Size2D<u32>, rect: Rect<u32>) -> Cow<[u8]> {
|
||||||
assert!(!rect.is_empty());
|
assert!(!rect.is_empty());
|
||||||
assert!(Rect::from_size(size).contains_rect(&rect));
|
assert!(Rect::from_size(size).contains_rect(&rect));
|
||||||
assert_eq!(pixels.len() % 4, 0);
|
assert_eq!(pixels.len() % 4, 0);
|
||||||
|
@ -106,18 +106,18 @@ pub fn multiply_u8_color(a: u8, b: u8) -> u8 {
|
||||||
|
|
||||||
pub fn clip(
|
pub fn clip(
|
||||||
mut origin: Point2D<i32>,
|
mut origin: Point2D<i32>,
|
||||||
mut size: Size2D<u64>,
|
mut size: Size2D<u32>,
|
||||||
surface: Size2D<u64>,
|
surface: Size2D<u32>,
|
||||||
) -> Option<Rect<u64>> {
|
) -> Option<Rect<u32>> {
|
||||||
if origin.x < 0 {
|
if origin.x < 0 {
|
||||||
size.width = size.width.saturating_sub(-origin.x as u64);
|
size.width = size.width.saturating_sub(-origin.x as u32);
|
||||||
origin.x = 0;
|
origin.x = 0;
|
||||||
}
|
}
|
||||||
if origin.y < 0 {
|
if origin.y < 0 {
|
||||||
size.height = size.height.saturating_sub(-origin.y as u64);
|
size.height = size.height.saturating_sub(-origin.y as u32);
|
||||||
origin.y = 0;
|
origin.y = 0;
|
||||||
}
|
}
|
||||||
let origin = Point2D::new(origin.x as u64, origin.y as u64);
|
let origin = Point2D::new(origin.x as u32, origin.y as u32);
|
||||||
Rect::new(origin, size)
|
Rect::new(origin, size)
|
||||||
.intersection(&Rect::from_size(surface))
|
.intersection(&Rect::from_size(surface))
|
||||||
.filter(|rect| !rect.is_empty())
|
.filter(|rect| !rect.is_empty())
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub(crate) trait CanvasContext {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size(&self) -> Size2D<u64> {
|
fn size(&self) -> Size2D<u32> {
|
||||||
self.canvas().size()
|
self.canvas().size()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,12 +73,12 @@ pub(crate) trait CanvasContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait CanvasHelpers {
|
pub(crate) trait CanvasHelpers {
|
||||||
fn size(&self) -> Size2D<u64>;
|
fn size(&self) -> Size2D<u32>;
|
||||||
fn canvas(&self) -> Option<&HTMLCanvasElement>;
|
fn canvas(&self) -> Option<&HTMLCanvasElement>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CanvasHelpers for HTMLCanvasElementOrOffscreenCanvas {
|
impl CanvasHelpers for HTMLCanvasElementOrOffscreenCanvas {
|
||||||
fn size(&self) -> Size2D<u64> {
|
fn size(&self) -> Size2D<u32> {
|
||||||
match self {
|
match self {
|
||||||
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(canvas) => {
|
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(canvas) => {
|
||||||
canvas.get_size().cast()
|
canvas.get_size().cast()
|
||||||
|
@ -164,7 +164,7 @@ impl CanvasContext for RenderingContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size(&self) -> Size2D<u64> {
|
fn size(&self) -> Size2D<u32> {
|
||||||
match self {
|
match self {
|
||||||
RenderingContext::Placeholder(context) => (*context.context().unwrap()).size(),
|
RenderingContext::Placeholder(context) => (*context.context().unwrap()).size(),
|
||||||
RenderingContext::Context2d(context) => context.size(),
|
RenderingContext::Context2d(context) => context.size(),
|
||||||
|
@ -251,7 +251,7 @@ impl CanvasContext for OffscreenRenderingContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size(&self) -> Size2D<u64> {
|
fn size(&self) -> Size2D<u32> {
|
||||||
match self {
|
match self {
|
||||||
OffscreenRenderingContext::Context2d(context) => context.size(),
|
OffscreenRenderingContext::Context2d(context) => context.size(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -383,7 +383,7 @@ impl CanvasState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_rect(&self, canvas_size: Size2D<u64>, rect: Rect<u64>) -> Vec<u8> {
|
pub(crate) fn get_rect(&self, canvas_size: Size2D<u32>, rect: Rect<u32>) -> Vec<u8> {
|
||||||
assert!(self.origin_is_clean());
|
assert!(self.origin_is_clean());
|
||||||
assert!(Rect::from_size(canvas_size).contains_rect(&rect));
|
assert!(Rect::from_size(canvas_size).contains_rect(&rect));
|
||||||
|
|
||||||
|
@ -1486,7 +1486,7 @@ impl CanvasState {
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub(crate) fn get_image_data(
|
pub(crate) fn get_image_data(
|
||||||
&self,
|
&self,
|
||||||
canvas_size: Size2D<u64>,
|
canvas_size: Size2D<u32>,
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
sx: i32,
|
sx: i32,
|
||||||
sy: i32,
|
sy: i32,
|
||||||
|
@ -1506,7 +1506,7 @@ impl CanvasState {
|
||||||
}
|
}
|
||||||
|
|
||||||
let (origin, size) = adjust_size_sign(Point2D::new(sx, sy), Size2D::new(sw, sh));
|
let (origin, size) = adjust_size_sign(Point2D::new(sx, sy), Size2D::new(sw, sh));
|
||||||
let read_rect = match pixels::clip(origin, size.to_u64(), canvas_size) {
|
let read_rect = match pixels::clip(origin, size.to_u32(), canvas_size) {
|
||||||
Some(rect) => rect,
|
Some(rect) => rect,
|
||||||
None => {
|
None => {
|
||||||
// All the pixels are outside the canvas surface.
|
// All the pixels are outside the canvas surface.
|
||||||
|
@ -1526,7 +1526,7 @@ impl CanvasState {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
||||||
pub(crate) fn put_image_data(
|
pub(crate) fn put_image_data(
|
||||||
&self,
|
&self,
|
||||||
canvas_size: Size2D<u64>,
|
canvas_size: Size2D<u32>,
|
||||||
imagedata: &ImageData,
|
imagedata: &ImageData,
|
||||||
dx: i32,
|
dx: i32,
|
||||||
dy: i32,
|
dy: i32,
|
||||||
|
@ -1547,7 +1547,7 @@ impl CanvasState {
|
||||||
#[allow(unsafe_code, clippy::too_many_arguments)]
|
#[allow(unsafe_code, clippy::too_many_arguments)]
|
||||||
pub(crate) fn put_image_data_(
|
pub(crate) fn put_image_data_(
|
||||||
&self,
|
&self,
|
||||||
canvas_size: Size2D<u64>,
|
canvas_size: Size2D<u32>,
|
||||||
imagedata: &ImageData,
|
imagedata: &ImageData,
|
||||||
dx: i32,
|
dx: i32,
|
||||||
dy: i32,
|
dy: i32,
|
||||||
|
@ -1579,7 +1579,7 @@ impl CanvasState {
|
||||||
Point2D::new(dirty_x, dirty_y),
|
Point2D::new(dirty_x, dirty_y),
|
||||||
Size2D::new(dirty_width, dirty_height),
|
Size2D::new(dirty_width, dirty_height),
|
||||||
);
|
);
|
||||||
let src_rect = match pixels::clip(src_origin, src_size.to_u64(), imagedata_size.to_u64()) {
|
let src_rect = match pixels::clip(src_origin, src_size.to_u32(), imagedata_size.to_u32()) {
|
||||||
Some(rect) => rect,
|
Some(rect) => rect,
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
|
@ -397,8 +397,8 @@ impl HTMLCanvasElement {
|
||||||
// u32 can't panic, since the data comes from a canvas which is always smaller than
|
// u32 can't panic, since the data comes from a canvas which is always smaller than
|
||||||
// u32::MAX.
|
// u32::MAX.
|
||||||
let canvas_data = snapshot.data();
|
let canvas_data = snapshot.data();
|
||||||
let width = snapshot.size().width as u32;
|
let width = snapshot.size().width;
|
||||||
let height = snapshot.size().height as u32;
|
let height = snapshot.size().height;
|
||||||
|
|
||||||
match image_type {
|
match image_type {
|
||||||
EncodedImageType::Png => {
|
EncodedImageType::Png => {
|
||||||
|
|
|
@ -154,8 +154,8 @@ impl ImageData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub(crate) unsafe fn get_rect(&self, rect: Rect<u64>) -> Cow<[u8]> {
|
pub(crate) unsafe fn get_rect(&self, rect: Rect<u32>) -> Cow<[u8]> {
|
||||||
pixels::rgba8_get_rect(self.as_slice(), self.get_size().to_u64(), rect)
|
pixels::rgba8_get_rect(self.as_slice(), self.get_size().to_u32(), rect)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_size(&self) -> Size2D<u32> {
|
pub(crate) fn get_size(&self) -> Size2D<u32> {
|
||||||
|
|
|
@ -72,8 +72,11 @@ impl OffscreenCanvas {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_size(&self) -> Size2D<u64> {
|
pub(crate) fn get_size(&self) -> Size2D<u32> {
|
||||||
Size2D::new(self.Width(), self.Height())
|
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 {
|
pub(crate) fn origin_is_clean(&self) -> bool {
|
||||||
|
|
|
@ -534,7 +534,7 @@ impl WebGL2RenderingContext {
|
||||||
let src_origin = Point2D::new(x, y);
|
let src_origin = Point2D::new(x, y);
|
||||||
let src_size = Size2D::new(width as u32, height as u32);
|
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 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(),
|
Some(rect) => rect.to_u32(),
|
||||||
None => return,
|
None => return,
|
||||||
}
|
}
|
||||||
|
@ -2183,7 +2183,7 @@ impl WebGL2RenderingContextMethods<crate::DomTypeHolder> for WebGL2RenderingCont
|
||||||
let src_origin = Point2D::new(x, y);
|
let src_origin = Point2D::new(x, y);
|
||||||
let src_size = Size2D::new(width as u32, height as u32);
|
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 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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3838,7 +3838,7 @@ impl WebGLRenderingContextMethods<crate::DomTypeHolder> for WebGLRenderingContex
|
||||||
let src_origin = Point2D::new(x, y);
|
let src_origin = Point2D::new(x, y);
|
||||||
let src_size = Size2D::new(width as u32, height as u32);
|
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 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,
|
Some(rect) => rect,
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
|
@ -167,8 +167,8 @@ impl GPUCanvasContext {
|
||||||
// causes FAIL on webgpu:web_platform,canvas,configure:usage:*
|
// causes FAIL on webgpu:web_platform,canvas,configure:usage:*
|
||||||
usage: configuration.usage | GPUTextureUsageConstants::COPY_SRC,
|
usage: configuration.usage | GPUTextureUsageConstants::COPY_SRC,
|
||||||
size: GPUExtent3D::GPUExtent3DDict(GPUExtent3DDict {
|
size: GPUExtent3D::GPUExtent3DDict(GPUExtent3DDict {
|
||||||
width: size.width as u32,
|
width: size.width,
|
||||||
height: size.height as u32,
|
height: size.height,
|
||||||
depthOrArrayLayers: 1,
|
depthOrArrayLayers: 1,
|
||||||
}),
|
}),
|
||||||
viewFormats: configuration.viewFormats.clone(),
|
viewFormats: configuration.viewFormats.clone(),
|
||||||
|
|
|
@ -129,10 +129,7 @@ impl XRWebGLLayer {
|
||||||
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(canvas) => canvas.get_size(),
|
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(canvas) => canvas.get_size(),
|
||||||
HTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(canvas) => {
|
HTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(canvas) => {
|
||||||
let size = canvas.get_size();
|
let size = canvas.get_size();
|
||||||
Size2D::new(
|
Size2D::new(size.width, size.height)
|
||||||
size.width.try_into().unwrap_or(0),
|
|
||||||
size.height.try_into().unwrap_or(0),
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
Size2D::from_untyped(size)
|
Size2D::from_untyped(size)
|
||||||
|
|
|
@ -102,14 +102,14 @@ pub enum Canvas2dMsg {
|
||||||
FillPath(FillOrStrokeStyle, Vec<PathSegment>),
|
FillPath(FillOrStrokeStyle, Vec<PathSegment>),
|
||||||
FillText(String, f64, f64, Option<f64>, FillOrStrokeStyle, bool),
|
FillText(String, f64, f64, Option<f64>, FillOrStrokeStyle, bool),
|
||||||
FillRect(Rect<f32>, FillOrStrokeStyle),
|
FillRect(Rect<f32>, FillOrStrokeStyle),
|
||||||
GetImageData(Rect<u64>, Size2D<u64>, IpcSender<IpcSnapshot>),
|
GetImageData(Rect<u32>, Size2D<u32>, IpcSender<IpcSnapshot>),
|
||||||
GetTransform(IpcSender<Transform2D<f32>>),
|
GetTransform(IpcSender<Transform2D<f32>>),
|
||||||
IsPointInCurrentPath(f64, f64, FillRule, IpcSender<bool>),
|
IsPointInCurrentPath(f64, f64, FillRule, IpcSender<bool>),
|
||||||
IsPointInPath(Vec<PathSegment>, f64, f64, FillRule, IpcSender<bool>),
|
IsPointInPath(Vec<PathSegment>, f64, f64, FillRule, IpcSender<bool>),
|
||||||
LineTo(Point2D<f32>),
|
LineTo(Point2D<f32>),
|
||||||
MoveTo(Point2D<f32>),
|
MoveTo(Point2D<f32>),
|
||||||
MeasureText(String, IpcSender<TextMetrics>),
|
MeasureText(String, IpcSender<TextMetrics>),
|
||||||
PutImageData(Rect<u64>, IpcBytesReceiver),
|
PutImageData(Rect<u32>, IpcBytesReceiver),
|
||||||
QuadraticCurveTo(Point2D<f32>, Point2D<f32>),
|
QuadraticCurveTo(Point2D<f32>, Point2D<f32>),
|
||||||
Rect(Rect<f32>),
|
Rect(Rect<f32>),
|
||||||
RestoreContext,
|
RestoreContext,
|
||||||
|
|
|
@ -87,7 +87,7 @@ pub type IpcSnapshot = Snapshot<IpcSharedMemory>;
|
||||||
/// <https://gpuweb.github.io/gpuweb/#abstract-opdef-get-a-copy-of-the-image-contents-of-a-context>
|
/// <https://gpuweb.github.io/gpuweb/#abstract-opdef-get-a-copy-of-the-image-contents-of-a-context>
|
||||||
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
|
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
|
||||||
pub struct Snapshot<T = Data> {
|
pub struct Snapshot<T = Data> {
|
||||||
size: Size2D<u64>,
|
size: Size2D<u32>,
|
||||||
/// internal data (can be any format it will be converted on use if needed)
|
/// internal data (can be any format it will be converted on use if needed)
|
||||||
data: T,
|
data: T,
|
||||||
/// RGBA/BGRA (reflect internal data)
|
/// RGBA/BGRA (reflect internal data)
|
||||||
|
@ -97,7 +97,7 @@ pub struct Snapshot<T = Data> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Snapshot<T> {
|
impl<T> Snapshot<T> {
|
||||||
pub const fn size(&self) -> Size2D<u64> {
|
pub const fn size(&self) -> Size2D<u32> {
|
||||||
self.size
|
self.size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ impl Snapshot<Data> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns snapshot with provided size that is black transparent alpha
|
/// Returns snapshot with provided size that is black transparent alpha
|
||||||
pub fn cleared(size: Size2D<u64>) -> Self {
|
pub fn cleared(size: Size2D<u32>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
size,
|
size,
|
||||||
data: Data::Owned(vec![0; size.area() as usize * 4]),
|
data: Data::Owned(vec![0; size.area() as usize * 4]),
|
||||||
|
@ -143,7 +143,7 @@ impl Snapshot<Data> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_vec(
|
pub fn from_vec(
|
||||||
size: Size2D<u64>,
|
size: Size2D<u32>,
|
||||||
format: PixelFormat,
|
format: PixelFormat,
|
||||||
alpha_mode: AlphaMode,
|
alpha_mode: AlphaMode,
|
||||||
data: Vec<u8>,
|
data: Vec<u8>,
|
||||||
|
@ -157,7 +157,7 @@ impl Snapshot<Data> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_shared_memory(
|
pub fn from_shared_memory(
|
||||||
size: Size2D<u64>,
|
size: Size2D<u32>,
|
||||||
format: PixelFormat,
|
format: PixelFormat,
|
||||||
alpha_mode: AlphaMode,
|
alpha_mode: AlphaMode,
|
||||||
ism: IpcSharedMemory,
|
ism: IpcSharedMemory,
|
||||||
|
@ -177,7 +177,7 @@ impl Snapshot<Data> {
|
||||||
/// This is safe if data is owned by this process only
|
/// This is safe if data is owned by this process only
|
||||||
/// (ownership is transferred on send)
|
/// (ownership is transferred on send)
|
||||||
pub unsafe fn from_shared_memory(
|
pub unsafe fn from_shared_memory(
|
||||||
size: Size2D<u64>,
|
size: Size2D<u32>,
|
||||||
format: PixelFormat,
|
format: PixelFormat,
|
||||||
alpha_mode: AlphaMode,
|
alpha_mode: AlphaMode,
|
||||||
ism: IpcSharedMemory,
|
ism: IpcSharedMemory,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue