mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +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
|
@ -12,6 +12,7 @@ use js::gc::CustomAutoRooterGuard;
|
|||
use js::jsapi::JSObject;
|
||||
use js::rust::HandleObject;
|
||||
use js::typedarray::{ClampedU8, Uint8ClampedArray};
|
||||
use pixels::{Snapshot, SnapshotAlphaMode, SnapshotPixelFormat};
|
||||
|
||||
use super::bindings::buffer_source::{HeapBufferSource, create_heap_buffer_source_with_length};
|
||||
use crate::dom::bindings::buffer_source::create_buffer_source;
|
||||
|
@ -183,6 +184,18 @@ impl ImageData {
|
|||
pixels::rgba8_get_rect(unsafe { self.as_slice() }, self.get_size().to_u32(), rect)
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub(crate) fn get_snapshot_rect(&self, rect: Rect<u32>) -> Snapshot {
|
||||
Snapshot::from_vec(
|
||||
rect.size,
|
||||
SnapshotPixelFormat::RGBA,
|
||||
SnapshotAlphaMode::Transparent {
|
||||
premultiplied: false,
|
||||
},
|
||||
unsafe { self.get_rect(rect).into_owned() },
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub(crate) fn to_shared_memory(&self) -> IpcSharedMemory {
|
||||
// This is safe because we copy the slice content
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue