mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
canvas: Use snapshot in canvas backends (#37863)
This removes assumption about pixel format from backend abstraction to actual backend implementation. This is important for vello. Testing: WPT tests --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
8df5e1e74d
commit
e1a891ea96
10 changed files with 174 additions and 292 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use euclid::default::Size2D;
|
||||
use euclid::default::{Rect, Size2D};
|
||||
use image::codecs::jpeg::JpegEncoder;
|
||||
use image::codecs::png::PngEncoder;
|
||||
use image::codecs::webp::WebPEncoder;
|
||||
|
@ -13,7 +13,7 @@ use ipc_channel::ipc::IpcSharedMemory;
|
|||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{EncodedImageType, Multiply, transform_inplace};
|
||||
use crate::{EncodedImageType, Multiply, rgba8_get_rect, transform_inplace};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
|
||||
pub enum SnapshotPixelFormat {
|
||||
|
@ -180,6 +180,11 @@ impl Snapshot<SnapshotData> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_rect(&self, rect: Rect<u32>) -> Self {
|
||||
let data = rgba8_get_rect(self.as_raw_bytes(), self.size(), rect).to_vec();
|
||||
Self::from_vec(rect.size, self.format, self.alpha_mode, data)
|
||||
}
|
||||
|
||||
// TODO: https://github.com/servo/servo/issues/36594
|
||||
/*
|
||||
/// # Safety
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue