mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Addresses Issue: Support OffscreenCanvas as CanvasImageSource #24269
Added methods to canvas_data to support drawing an offscreen canvas onto another canvas Bug fix: Swapped OffscreenCanvas width and height parameters to match Mozilla spec Tests: Updated metadata for 866 tests
This commit is contained in:
parent
951dc2419a
commit
deae103042
869 changed files with 133 additions and 3478 deletions
|
@ -16,9 +16,12 @@ use crate::dom::globalscope::GlobalScope;
|
|||
use crate::dom::htmlcanvaselement::HTMLCanvasElement;
|
||||
use crate::dom::offscreencanvasrenderingcontext2d::OffscreenCanvasRenderingContext2D;
|
||||
use crate::script_runtime::JSContext;
|
||||
use canvas_traits::canvas::{CanvasMsg, FromScriptMsg};
|
||||
use dom_struct::dom_struct;
|
||||
use euclid::default::Size2D;
|
||||
use ipc_channel::ipc::IpcSharedMemory;
|
||||
use js::rust::HandleValue;
|
||||
use profile_traits::ipc;
|
||||
use ref_filter_map;
|
||||
use std::cell::Cell;
|
||||
use std::cell::Ref;
|
||||
|
@ -34,22 +37,22 @@ pub enum OffscreenCanvasContext {
|
|||
#[dom_struct]
|
||||
pub struct OffscreenCanvas {
|
||||
eventtarget: EventTarget,
|
||||
height: Cell<u64>,
|
||||
width: Cell<u64>,
|
||||
height: Cell<u64>,
|
||||
context: DomRefCell<Option<OffscreenCanvasContext>>,
|
||||
placeholder: Option<Dom<HTMLCanvasElement>>,
|
||||
}
|
||||
|
||||
impl OffscreenCanvas {
|
||||
pub fn new_inherited(
|
||||
height: u64,
|
||||
width: u64,
|
||||
height: u64,
|
||||
placeholder: Option<&HTMLCanvasElement>,
|
||||
) -> OffscreenCanvas {
|
||||
OffscreenCanvas {
|
||||
eventtarget: EventTarget::new_inherited(),
|
||||
height: Cell::new(height),
|
||||
width: Cell::new(width),
|
||||
height: Cell::new(height),
|
||||
context: DomRefCell::new(None),
|
||||
placeholder: placeholder.map(Dom::from_ref),
|
||||
}
|
||||
|
@ -57,12 +60,12 @@ impl OffscreenCanvas {
|
|||
|
||||
pub fn new(
|
||||
global: &GlobalScope,
|
||||
height: u64,
|
||||
width: u64,
|
||||
height: u64,
|
||||
placeholder: Option<&HTMLCanvasElement>,
|
||||
) -> DomRoot<OffscreenCanvas> {
|
||||
reflect_dom_object(
|
||||
Box::new(OffscreenCanvas::new_inherited(height, width, placeholder)),
|
||||
Box::new(OffscreenCanvas::new_inherited(width, height, placeholder)),
|
||||
global,
|
||||
OffscreenCanvasWrap,
|
||||
)
|
||||
|
@ -70,10 +73,10 @@ impl OffscreenCanvas {
|
|||
|
||||
pub fn Constructor(
|
||||
global: &GlobalScope,
|
||||
height: u64,
|
||||
width: u64,
|
||||
height: u64,
|
||||
) -> Fallible<DomRoot<OffscreenCanvas>> {
|
||||
let offscreencanvas = OffscreenCanvas::new(global, height, width, None);
|
||||
let offscreencanvas = OffscreenCanvas::new(global, width, height, None);
|
||||
Ok(offscreencanvas)
|
||||
}
|
||||
|
||||
|
@ -81,10 +84,44 @@ impl OffscreenCanvas {
|
|||
Size2D::new(self.Width(), self.Height())
|
||||
}
|
||||
|
||||
pub fn origin_is_clean(&self) -> bool {
|
||||
match *self.context.borrow() {
|
||||
Some(OffscreenCanvasContext::OffscreenContext2d(ref context)) => {
|
||||
context.origin_is_clean()
|
||||
},
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn context(&self) -> Option<Ref<OffscreenCanvasContext>> {
|
||||
ref_filter_map::ref_filter_map(self.context.borrow(), |ctx| ctx.as_ref())
|
||||
}
|
||||
|
||||
pub fn fetch_all_data(&self) -> Option<(Option<IpcSharedMemory>, Size2D<u32>)> {
|
||||
let size = self.get_size();
|
||||
|
||||
if size.width == 0 || size.height == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let data = match self.context.borrow().as_ref() {
|
||||
Some(&OffscreenCanvasContext::OffscreenContext2d(ref context)) => {
|
||||
let (sender, receiver) =
|
||||
ipc::channel(self.global().time_profiler_chan().clone()).unwrap();
|
||||
let msg = CanvasMsg::FromScript(
|
||||
FromScriptMsg::SendPixels(sender),
|
||||
context.get_canvas_id(),
|
||||
);
|
||||
context.get_ipc_renderer().send(msg).unwrap();
|
||||
|
||||
Some(receiver.recv().unwrap())
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
|
||||
Some((data, size.to_u32()))
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_or_init_2d_context(&self) -> Option<DomRoot<OffscreenCanvasRenderingContext2D>> {
|
||||
if let Some(ctx) = self.context() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue