mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
canvas: Make pixel obtaining methods take &mut GenericDrawTarget (#38264)
This will be needed for vello_cpu. While we could wrap it in RefCell for inner mut, but that would be less ergonomic and performant. Testing: Just refactoring, but the code is covered by WPT tests. Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
9d29017c0d
commit
fc0038743d
3 changed files with 10 additions and 8 deletions
|
@ -86,7 +86,9 @@ pub(crate) trait GenericDrawTarget {
|
||||||
composition_options: CompositionOptions,
|
composition_options: CompositionOptions,
|
||||||
transform: Transform2D<f32>,
|
transform: Transform2D<f32>,
|
||||||
);
|
);
|
||||||
fn surface(&self) -> Self::SourceSurface;
|
fn surface(&mut self) -> Self::SourceSurface;
|
||||||
fn image_descriptor_and_serializable_data(&self) -> (ImageDescriptor, SerializableImageData);
|
fn image_descriptor_and_serializable_data(
|
||||||
fn snapshot(&self) -> Snapshot;
|
&mut self,
|
||||||
|
) -> (ImageDescriptor, SerializableImageData);
|
||||||
|
fn snapshot(&mut self) -> Snapshot;
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ impl<DrawTarget: GenericDrawTarget> CanvasData<DrawTarget> {
|
||||||
font_context: Arc<FontContext>,
|
font_context: Arc<FontContext>,
|
||||||
) -> CanvasData<DrawTarget> {
|
) -> CanvasData<DrawTarget> {
|
||||||
let size = size.max(MIN_WR_IMAGE_SIZE);
|
let size = size.max(MIN_WR_IMAGE_SIZE);
|
||||||
let draw_target = DrawTarget::new(size.cast());
|
let mut draw_target = DrawTarget::new(size.cast());
|
||||||
let image_key = compositor_api.generate_image_key_blocking().unwrap();
|
let image_key = compositor_api.generate_image_key_blocking().unwrap();
|
||||||
let (descriptor, data) = draw_target.image_descriptor_and_serializable_data();
|
let (descriptor, data) = draw_target.image_descriptor_and_serializable_data();
|
||||||
compositor_api.add_image(image_key, descriptor, data);
|
compositor_api.add_image(image_key, descriptor, data);
|
||||||
|
@ -724,7 +724,7 @@ impl<DrawTarget: GenericDrawTarget> CanvasData<DrawTarget> {
|
||||||
/// read_rect: The area of the canvas we want to read from
|
/// read_rect: The area of the canvas we want to read from
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub(crate) fn read_pixels(
|
pub(crate) fn read_pixels(
|
||||||
&self,
|
&mut self,
|
||||||
read_rect: Option<Rect<u32>>,
|
read_rect: Option<Rect<u32>>,
|
||||||
canvas_size: Option<Size2D<u32>>,
|
canvas_size: Option<Size2D<u32>>,
|
||||||
) -> Snapshot {
|
) -> Snapshot {
|
||||||
|
|
|
@ -401,7 +401,7 @@ impl GenericDrawTarget for raqote::DrawTarget {
|
||||||
fn push_clip_rect(&mut self, rect: &Rect<i32>) {
|
fn push_clip_rect(&mut self, rect: &Rect<i32>) {
|
||||||
self.push_clip_rect(rect.to_box2d());
|
self.push_clip_rect(rect.to_box2d());
|
||||||
}
|
}
|
||||||
fn surface(&self) -> Self::SourceSurface {
|
fn surface(&mut self) -> Self::SourceSurface {
|
||||||
self.get_data_u8().to_vec()
|
self.get_data_u8().to_vec()
|
||||||
}
|
}
|
||||||
fn stroke(
|
fn stroke(
|
||||||
|
@ -450,7 +450,7 @@ impl GenericDrawTarget for raqote::DrawTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn image_descriptor_and_serializable_data(
|
fn image_descriptor_and_serializable_data(
|
||||||
&self,
|
&mut self,
|
||||||
) -> (
|
) -> (
|
||||||
webrender_api::ImageDescriptor,
|
webrender_api::ImageDescriptor,
|
||||||
compositing_traits::SerializableImageData,
|
compositing_traits::SerializableImageData,
|
||||||
|
@ -466,7 +466,7 @@ impl GenericDrawTarget for raqote::DrawTarget {
|
||||||
(descriptor, data)
|
(descriptor, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn snapshot(&self) -> Snapshot {
|
fn snapshot(&mut self) -> Snapshot {
|
||||||
Snapshot::from_vec(
|
Snapshot::from_vec(
|
||||||
self.get_size().cast(),
|
self.get_size().cast(),
|
||||||
SnapshotPixelFormat::BGRA,
|
SnapshotPixelFormat::BGRA,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue