mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Remove DomRefCell wrapper for canvas_state from CanvasRenderingContext2D
This commit is contained in:
parent
4a730d1cd2
commit
d98ade2a68
1 changed files with 72 additions and 118 deletions
|
@ -36,7 +36,7 @@ pub struct CanvasRenderingContext2D {
|
||||||
/// For rendering contexts created by an HTML canvas element, this is Some,
|
/// For rendering contexts created by an HTML canvas element, this is Some,
|
||||||
/// for ones created by a paint worklet, this is None.
|
/// for ones created by a paint worklet, this is None.
|
||||||
canvas: Option<Dom<HTMLCanvasElement>>,
|
canvas: Option<Dom<HTMLCanvasElement>>,
|
||||||
canvas_state: DomRefCell<CanvasState>,
|
canvas_state: CanvasState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CanvasRenderingContext2D {
|
impl CanvasRenderingContext2D {
|
||||||
|
@ -48,10 +48,10 @@ impl CanvasRenderingContext2D {
|
||||||
CanvasRenderingContext2D {
|
CanvasRenderingContext2D {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
canvas: canvas.map(Dom::from_ref),
|
canvas: canvas.map(Dom::from_ref),
|
||||||
canvas_state: DomRefCell::new(CanvasState::new(
|
canvas_state: CanvasState::new(
|
||||||
global,
|
global,
|
||||||
Size2D::new(size.width as u64, size.height as u64),
|
Size2D::new(size.width as u64, size.height as u64),
|
||||||
)),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,11 +72,10 @@ impl CanvasRenderingContext2D {
|
||||||
pub fn set_bitmap_dimensions(&self, size: Size2D<u32>) {
|
pub fn set_bitmap_dimensions(&self, size: Size2D<u32>) {
|
||||||
self.reset_to_initial_state();
|
self.reset_to_initial_state();
|
||||||
self.canvas_state
|
self.canvas_state
|
||||||
.borrow()
|
|
||||||
.get_ipc_renderer()
|
.get_ipc_renderer()
|
||||||
.send(CanvasMsg::Recreate(
|
.send(CanvasMsg::Recreate(
|
||||||
size.to_u64(),
|
size.to_u64(),
|
||||||
self.canvas_state.borrow().get_canvas_id(),
|
self.canvas_state.get_canvas_id(),
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -84,12 +83,8 @@ impl CanvasRenderingContext2D {
|
||||||
// TODO: This duplicates functionality in canvas state
|
// TODO: This duplicates functionality in canvas state
|
||||||
// https://html.spec.whatwg.org/multipage/#reset-the-rendering-context-to-its-default-state
|
// https://html.spec.whatwg.org/multipage/#reset-the-rendering-context-to-its-default-state
|
||||||
fn reset_to_initial_state(&self) {
|
fn reset_to_initial_state(&self) {
|
||||||
self.canvas_state
|
self.canvas_state.get_saved_state().borrow_mut().clear();
|
||||||
.borrow()
|
*self.canvas_state.get_state().borrow_mut() = CanvasContextState::new();
|
||||||
.get_saved_state()
|
|
||||||
.borrow_mut()
|
|
||||||
.clear();
|
|
||||||
*self.canvas_state.borrow().get_state().borrow_mut() = CanvasContextState::new();
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
pub fn get_canvas_state(&self) -> Ref<CanvasState> {
|
pub fn get_canvas_state(&self) -> Ref<CanvasState> {
|
||||||
|
@ -98,41 +93,36 @@ impl CanvasRenderingContext2D {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pub fn set_canvas_bitmap_dimensions(&self, size: Size2D<u64>) {
|
pub fn set_canvas_bitmap_dimensions(&self, size: Size2D<u64>) {
|
||||||
self.canvas_state.borrow().set_bitmap_dimensions(size);
|
self.canvas_state.set_bitmap_dimensions(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mark_as_dirty(&self) {
|
pub fn mark_as_dirty(&self) {
|
||||||
self.canvas_state
|
self.canvas_state
|
||||||
.borrow()
|
|
||||||
.mark_as_dirty(self.canvas.as_ref().map(|c| &**c))
|
.mark_as_dirty(self.canvas.as_ref().map(|c| &**c))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn take_missing_image_urls(&self) -> Vec<ServoUrl> {
|
pub fn take_missing_image_urls(&self) -> Vec<ServoUrl> {
|
||||||
mem::replace(
|
mem::replace(
|
||||||
&mut self
|
&mut self.canvas_state.get_missing_image_urls().borrow_mut(),
|
||||||
.canvas_state
|
|
||||||
.borrow()
|
|
||||||
.get_missing_image_urls()
|
|
||||||
.borrow_mut(),
|
|
||||||
vec![],
|
vec![],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_canvas_id(&self) -> CanvasId {
|
pub fn get_canvas_id(&self) -> CanvasId {
|
||||||
self.canvas_state.borrow().get_canvas_id()
|
self.canvas_state.get_canvas_id()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_canvas_2d_msg(&self, msg: Canvas2dMsg) {
|
pub fn send_canvas_2d_msg(&self, msg: Canvas2dMsg) {
|
||||||
self.canvas_state.borrow().send_canvas_2d_msg(msg)
|
self.canvas_state.send_canvas_2d_msg(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove this
|
// TODO: Remove this
|
||||||
pub fn get_ipc_renderer(&self) -> IpcSender<CanvasMsg> {
|
pub fn get_ipc_renderer(&self) -> IpcSender<CanvasMsg> {
|
||||||
self.canvas_state.borrow().get_ipc_renderer().clone()
|
self.canvas_state.get_ipc_renderer().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn origin_is_clean(&self) -> bool {
|
pub fn origin_is_clean(&self) -> bool {
|
||||||
self.canvas_state.borrow().origin_is_clean()
|
self.canvas_state.origin_is_clean()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_rect(&self, rect: Rect<u32>) -> Vec<u8> {
|
pub fn get_rect(&self, rect: Rect<u32>) -> Vec<u8> {
|
||||||
|
@ -140,7 +130,7 @@ impl CanvasRenderingContext2D {
|
||||||
Point2D::new(rect.origin.x as u64, rect.origin.y as u64),
|
Point2D::new(rect.origin.x as u64, rect.origin.y as u64),
|
||||||
Size2D::new(rect.size.width as u64, rect.size.height as u64),
|
Size2D::new(rect.size.width as u64, rect.size.height as u64),
|
||||||
);
|
);
|
||||||
self.canvas_state.borrow().get_rect(
|
self.canvas_state.get_rect(
|
||||||
self.canvas
|
self.canvas
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(Size2D::zero(), |c| c.get_size().to_u64()),
|
.map_or(Size2D::zero(), |c| c.get_size().to_u64()),
|
||||||
|
@ -158,11 +148,7 @@ pub trait LayoutCanvasRenderingContext2DHelpers {
|
||||||
impl LayoutCanvasRenderingContext2DHelpers for LayoutDom<'_, CanvasRenderingContext2D> {
|
impl LayoutCanvasRenderingContext2DHelpers for LayoutDom<'_, CanvasRenderingContext2D> {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_ipc_renderer(self) -> IpcSender<CanvasMsg> {
|
unsafe fn get_ipc_renderer(self) -> IpcSender<CanvasMsg> {
|
||||||
(*self.unsafe_get())
|
(*self.unsafe_get()).canvas_state.get_ipc_renderer().clone()
|
||||||
.canvas_state
|
|
||||||
.borrow_for_layout()
|
|
||||||
.get_ipc_renderer()
|
|
||||||
.clone()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
|
@ -170,12 +156,7 @@ impl LayoutCanvasRenderingContext2DHelpers for LayoutDom<'_, CanvasRenderingCont
|
||||||
// FIXME(nox): This relies on the fact that CanvasState::get_canvas_id
|
// FIXME(nox): This relies on the fact that CanvasState::get_canvas_id
|
||||||
// does nothing fancy but it would be easier to trust a
|
// does nothing fancy but it would be easier to trust a
|
||||||
// LayoutDom<_>-like type that would wrap the &CanvasState.
|
// LayoutDom<_>-like type that would wrap the &CanvasState.
|
||||||
unsafe {
|
unsafe { self.unsafe_get().canvas_state.get_canvas_id() }
|
||||||
self.unsafe_get()
|
|
||||||
.canvas_state
|
|
||||||
.borrow_for_layout()
|
|
||||||
.get_canvas_id()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,141 +179,135 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-save
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-save
|
||||||
fn Save(&self) {
|
fn Save(&self) {
|
||||||
self.canvas_state.borrow().save()
|
self.canvas_state.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-restore
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-restore
|
||||||
fn Restore(&self) {
|
fn Restore(&self) {
|
||||||
self.canvas_state.borrow().restore()
|
self.canvas_state.restore()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-scale
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-scale
|
||||||
fn Scale(&self, x: f64, y: f64) {
|
fn Scale(&self, x: f64, y: f64) {
|
||||||
self.canvas_state.borrow().scale(x, y)
|
self.canvas_state.scale(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-rotate
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-rotate
|
||||||
fn Rotate(&self, angle: f64) {
|
fn Rotate(&self, angle: f64) {
|
||||||
self.canvas_state.borrow().rotate(angle)
|
self.canvas_state.rotate(angle)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-translate
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-translate
|
||||||
fn Translate(&self, x: f64, y: f64) {
|
fn Translate(&self, x: f64, y: f64) {
|
||||||
self.canvas_state.borrow().translate(x, y)
|
self.canvas_state.translate(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-transform
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-transform
|
||||||
fn Transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
|
fn Transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
|
||||||
self.canvas_state.borrow().transform(a, b, c, d, e, f)
|
self.canvas_state.transform(a, b, c, d, e, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform
|
||||||
fn GetTransform(&self) -> DomRoot<DOMMatrix> {
|
fn GetTransform(&self) -> DomRoot<DOMMatrix> {
|
||||||
self.canvas_state.borrow().get_transform(&self.global())
|
self.canvas_state.get_transform(&self.global())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform
|
||||||
fn SetTransform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
|
fn SetTransform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
|
||||||
self.canvas_state.borrow().set_transform(a, b, c, d, e, f)
|
self.canvas_state.set_transform(a, b, c, d, e, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-resettransform
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-resettransform
|
||||||
fn ResetTransform(&self) {
|
fn ResetTransform(&self) {
|
||||||
self.canvas_state.borrow().reset_transform()
|
self.canvas_state.reset_transform()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalalpha
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalalpha
|
||||||
fn GlobalAlpha(&self) -> f64 {
|
fn GlobalAlpha(&self) -> f64 {
|
||||||
self.canvas_state.borrow().global_alpha()
|
self.canvas_state.global_alpha()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalalpha
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalalpha
|
||||||
fn SetGlobalAlpha(&self, alpha: f64) {
|
fn SetGlobalAlpha(&self, alpha: f64) {
|
||||||
self.canvas_state.borrow().set_global_alpha(alpha)
|
self.canvas_state.set_global_alpha(alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
|
||||||
fn GlobalCompositeOperation(&self) -> DOMString {
|
fn GlobalCompositeOperation(&self) -> DOMString {
|
||||||
self.canvas_state.borrow().global_composite_operation()
|
self.canvas_state.global_composite_operation()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
|
||||||
fn SetGlobalCompositeOperation(&self, op_str: DOMString) {
|
fn SetGlobalCompositeOperation(&self, op_str: DOMString) {
|
||||||
self.canvas_state
|
self.canvas_state.set_global_composite_operation(op_str)
|
||||||
.borrow()
|
|
||||||
.set_global_composite_operation(op_str)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-fillrect
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-fillrect
|
||||||
fn FillRect(&self, x: f64, y: f64, width: f64, height: f64) {
|
fn FillRect(&self, x: f64, y: f64, width: f64, height: f64) {
|
||||||
self.canvas_state.borrow().fill_rect(x, y, width, height);
|
self.canvas_state.fill_rect(x, y, width, height);
|
||||||
self.mark_as_dirty();
|
self.mark_as_dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-clearrect
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-clearrect
|
||||||
fn ClearRect(&self, x: f64, y: f64, width: f64, height: f64) {
|
fn ClearRect(&self, x: f64, y: f64, width: f64, height: f64) {
|
||||||
self.canvas_state.borrow().clear_rect(x, y, width, height);
|
self.canvas_state.clear_rect(x, y, width, height);
|
||||||
self.mark_as_dirty();
|
self.mark_as_dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokerect
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokerect
|
||||||
fn StrokeRect(&self, x: f64, y: f64, width: f64, height: f64) {
|
fn StrokeRect(&self, x: f64, y: f64, width: f64, height: f64) {
|
||||||
self.canvas_state.borrow().stroke_rect(x, y, width, height);
|
self.canvas_state.stroke_rect(x, y, width, height);
|
||||||
self.mark_as_dirty();
|
self.mark_as_dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-beginpath
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-beginpath
|
||||||
fn BeginPath(&self) {
|
fn BeginPath(&self) {
|
||||||
self.canvas_state.borrow().begin_path()
|
self.canvas_state.begin_path()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-closepath
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-closepath
|
||||||
fn ClosePath(&self) {
|
fn ClosePath(&self) {
|
||||||
self.canvas_state.borrow().close_path()
|
self.canvas_state.close_path()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-fill
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-fill
|
||||||
fn Fill(&self, fill_rule: CanvasFillRule) {
|
fn Fill(&self, fill_rule: CanvasFillRule) {
|
||||||
self.canvas_state.borrow().fill(fill_rule);
|
self.canvas_state.fill(fill_rule);
|
||||||
self.mark_as_dirty();
|
self.mark_as_dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-stroke
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-stroke
|
||||||
fn Stroke(&self) {
|
fn Stroke(&self) {
|
||||||
self.canvas_state.borrow().stroke();
|
self.canvas_state.stroke();
|
||||||
self.mark_as_dirty();
|
self.mark_as_dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-clip
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-clip
|
||||||
fn Clip(&self, fill_rule: CanvasFillRule) {
|
fn Clip(&self, fill_rule: CanvasFillRule) {
|
||||||
self.canvas_state.borrow().clip(fill_rule)
|
self.canvas_state.clip(fill_rule)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-ispointinpath
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-ispointinpath
|
||||||
fn IsPointInPath(&self, x: f64, y: f64, fill_rule: CanvasFillRule) -> bool {
|
fn IsPointInPath(&self, x: f64, y: f64, fill_rule: CanvasFillRule) -> bool {
|
||||||
self.canvas_state
|
self.canvas_state
|
||||||
.borrow()
|
|
||||||
.is_point_in_path(&self.global(), x, y, fill_rule)
|
.is_point_in_path(&self.global(), x, y, fill_rule)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-filltext
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-filltext
|
||||||
fn FillText(&self, text: DOMString, x: f64, y: f64, max_width: Option<f64>) {
|
fn FillText(&self, text: DOMString, x: f64, y: f64, max_width: Option<f64>) {
|
||||||
self.canvas_state.borrow().fill_text(text, x, y, max_width);
|
self.canvas_state.fill_text(text, x, y, max_width);
|
||||||
self.mark_as_dirty();
|
self.mark_as_dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#textmetrics
|
// https://html.spec.whatwg.org/multipage/#textmetrics
|
||||||
fn MeasureText(&self, text: DOMString) -> DomRoot<TextMetrics> {
|
fn MeasureText(&self, text: DOMString) -> DomRoot<TextMetrics> {
|
||||||
self.canvas_state
|
self.canvas_state.measure_text(&self.global(), text)
|
||||||
.borrow()
|
|
||||||
.measure_text(&self.global(), text)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage
|
||||||
fn DrawImage(&self, image: CanvasImageSource, dx: f64, dy: f64) -> ErrorResult {
|
fn DrawImage(&self, image: CanvasImageSource, dx: f64, dy: f64) -> ErrorResult {
|
||||||
self.canvas_state
|
self.canvas_state
|
||||||
.borrow()
|
|
||||||
.draw_image(self.canvas.as_ref().map(|c| &**c), image, dx, dy)
|
.draw_image(self.canvas.as_ref().map(|c| &**c), image, dx, dy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,14 +320,8 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
dw: f64,
|
dw: f64,
|
||||||
dh: f64,
|
dh: f64,
|
||||||
) -> ErrorResult {
|
) -> ErrorResult {
|
||||||
self.canvas_state.borrow().draw_image_(
|
self.canvas_state
|
||||||
self.canvas.as_ref().map(|c| &**c),
|
.draw_image_(self.canvas.as_ref().map(|c| &**c), image, dx, dy, dw, dh)
|
||||||
image,
|
|
||||||
dx,
|
|
||||||
dy,
|
|
||||||
dw,
|
|
||||||
dh,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage
|
||||||
|
@ -368,7 +337,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
dw: f64,
|
dw: f64,
|
||||||
dh: f64,
|
dh: f64,
|
||||||
) -> ErrorResult {
|
) -> ErrorResult {
|
||||||
self.canvas_state.borrow().draw_image__(
|
self.canvas_state.draw_image__(
|
||||||
self.canvas.as_ref().map(|c| &**c),
|
self.canvas.as_ref().map(|c| &**c),
|
||||||
image,
|
image,
|
||||||
sx,
|
sx,
|
||||||
|
@ -384,41 +353,38 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-moveto
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-moveto
|
||||||
fn MoveTo(&self, x: f64, y: f64) {
|
fn MoveTo(&self, x: f64, y: f64) {
|
||||||
self.canvas_state.borrow().move_to(x, y)
|
self.canvas_state.move_to(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-lineto
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-lineto
|
||||||
fn LineTo(&self, x: f64, y: f64) {
|
fn LineTo(&self, x: f64, y: f64) {
|
||||||
self.canvas_state.borrow().line_to(x, y)
|
self.canvas_state.line_to(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-rect
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-rect
|
||||||
fn Rect(&self, x: f64, y: f64, width: f64, height: f64) {
|
fn Rect(&self, x: f64, y: f64, width: f64, height: f64) {
|
||||||
self.canvas_state.borrow().rect(x, y, width, height)
|
self.canvas_state.rect(x, y, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-quadraticcurveto
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-quadraticcurveto
|
||||||
fn QuadraticCurveTo(&self, cpx: f64, cpy: f64, x: f64, y: f64) {
|
fn QuadraticCurveTo(&self, cpx: f64, cpy: f64, x: f64, y: f64) {
|
||||||
self.canvas_state
|
self.canvas_state.quadratic_curve_to(cpx, cpy, x, y)
|
||||||
.borrow()
|
|
||||||
.quadratic_curve_to(cpx, cpy, x, y)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-beziercurveto
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-beziercurveto
|
||||||
fn BezierCurveTo(&self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, x: f64, y: f64) {
|
fn BezierCurveTo(&self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, x: f64, y: f64) {
|
||||||
self.canvas_state
|
self.canvas_state
|
||||||
.borrow()
|
|
||||||
.bezier_curve_to(cp1x, cp1y, cp2x, cp2y, x, y)
|
.bezier_curve_to(cp1x, cp1y, cp2x, cp2y, x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-arc
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-arc
|
||||||
fn Arc(&self, x: f64, y: f64, r: f64, start: f64, end: f64, ccw: bool) -> ErrorResult {
|
fn Arc(&self, x: f64, y: f64, r: f64, start: f64, end: f64, ccw: bool) -> ErrorResult {
|
||||||
self.canvas_state.borrow().arc(x, y, r, start, end, ccw)
|
self.canvas_state.arc(x, y, r, start, end, ccw)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-arcto
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-arcto
|
||||||
fn ArcTo(&self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, r: f64) -> ErrorResult {
|
fn ArcTo(&self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, r: f64) -> ErrorResult {
|
||||||
self.canvas_state.borrow().arc_to(cp1x, cp1y, cp2x, cp2y, r)
|
self.canvas_state.arc_to(cp1x, cp1y, cp2x, cp2y, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-ellipse
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-ellipse
|
||||||
|
@ -434,63 +400,55 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
ccw: bool,
|
ccw: bool,
|
||||||
) -> ErrorResult {
|
) -> ErrorResult {
|
||||||
self.canvas_state
|
self.canvas_state
|
||||||
.borrow()
|
|
||||||
.ellipse(x, y, rx, ry, rotation, start, end, ccw)
|
.ellipse(x, y, rx, ry, rotation, start, end, ccw)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled
|
||||||
fn ImageSmoothingEnabled(&self) -> bool {
|
fn ImageSmoothingEnabled(&self) -> bool {
|
||||||
self.canvas_state.borrow().image_smoothing_enabled()
|
self.canvas_state.image_smoothing_enabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled
|
||||||
fn SetImageSmoothingEnabled(&self, value: bool) {
|
fn SetImageSmoothingEnabled(&self, value: bool) {
|
||||||
self.canvas_state
|
self.canvas_state.set_image_smoothing_enabled(value)
|
||||||
.borrow()
|
|
||||||
.set_image_smoothing_enabled(value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle
|
||||||
fn StrokeStyle(&self) -> StringOrCanvasGradientOrCanvasPattern {
|
fn StrokeStyle(&self) -> StringOrCanvasGradientOrCanvasPattern {
|
||||||
self.canvas_state.borrow().stroke_style()
|
self.canvas_state.stroke_style()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle
|
||||||
fn SetStrokeStyle(&self, value: StringOrCanvasGradientOrCanvasPattern) {
|
fn SetStrokeStyle(&self, value: StringOrCanvasGradientOrCanvasPattern) {
|
||||||
self.canvas_state
|
self.canvas_state
|
||||||
.borrow()
|
|
||||||
.set_stroke_style(self.canvas.as_ref().map(|c| &**c), value)
|
.set_stroke_style(self.canvas.as_ref().map(|c| &**c), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle
|
||||||
fn FillStyle(&self) -> StringOrCanvasGradientOrCanvasPattern {
|
fn FillStyle(&self) -> StringOrCanvasGradientOrCanvasPattern {
|
||||||
self.canvas_state.borrow().fill_style()
|
self.canvas_state.fill_style()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle
|
||||||
fn SetFillStyle(&self, value: StringOrCanvasGradientOrCanvasPattern) {
|
fn SetFillStyle(&self, value: StringOrCanvasGradientOrCanvasPattern) {
|
||||||
self.canvas_state
|
self.canvas_state
|
||||||
.borrow()
|
|
||||||
.set_fill_style(self.canvas.as_ref().map(|c| &**c), value)
|
.set_fill_style(self.canvas.as_ref().map(|c| &**c), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
||||||
fn CreateImageData(&self, sw: i32, sh: i32) -> Fallible<DomRoot<ImageData>> {
|
fn CreateImageData(&self, sw: i32, sh: i32) -> Fallible<DomRoot<ImageData>> {
|
||||||
self.canvas_state
|
self.canvas_state.create_image_data(&self.global(), sw, sh)
|
||||||
.borrow()
|
|
||||||
.create_image_data(&self.global(), sw, sh)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
||||||
fn CreateImageData_(&self, imagedata: &ImageData) -> Fallible<DomRoot<ImageData>> {
|
fn CreateImageData_(&self, imagedata: &ImageData) -> Fallible<DomRoot<ImageData>> {
|
||||||
self.canvas_state
|
self.canvas_state
|
||||||
.borrow()
|
|
||||||
.create_image_data_(&self.global(), imagedata)
|
.create_image_data_(&self.global(), imagedata)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata
|
||||||
fn GetImageData(&self, sx: i32, sy: i32, sw: i32, sh: i32) -> Fallible<DomRoot<ImageData>> {
|
fn GetImageData(&self, sx: i32, sy: i32, sw: i32, sh: i32) -> Fallible<DomRoot<ImageData>> {
|
||||||
self.canvas_state.borrow().get_image_data(
|
self.canvas_state.get_image_data(
|
||||||
self.canvas
|
self.canvas
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(Size2D::zero(), |c| c.get_size().to_u64()),
|
.map_or(Size2D::zero(), |c| c.get_size().to_u64()),
|
||||||
|
@ -504,7 +462,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
||||||
fn PutImageData(&self, imagedata: &ImageData, dx: i32, dy: i32) {
|
fn PutImageData(&self, imagedata: &ImageData, dx: i32, dy: i32) {
|
||||||
self.canvas_state.borrow().put_image_data(
|
self.canvas_state.put_image_data(
|
||||||
self.canvas
|
self.canvas
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(Size2D::zero(), |c| c.get_size().to_u64()),
|
.map_or(Size2D::zero(), |c| c.get_size().to_u64()),
|
||||||
|
@ -526,7 +484,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
dirty_width: i32,
|
dirty_width: i32,
|
||||||
dirty_height: i32,
|
dirty_height: i32,
|
||||||
) {
|
) {
|
||||||
self.canvas_state.borrow().put_image_data_(
|
self.canvas_state.put_image_data_(
|
||||||
self.canvas
|
self.canvas
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(Size2D::zero(), |c| c.get_size().to_u64()),
|
.map_or(Size2D::zero(), |c| c.get_size().to_u64()),
|
||||||
|
@ -550,7 +508,6 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
y1: Finite<f64>,
|
y1: Finite<f64>,
|
||||||
) -> DomRoot<CanvasGradient> {
|
) -> DomRoot<CanvasGradient> {
|
||||||
self.canvas_state
|
self.canvas_state
|
||||||
.borrow()
|
|
||||||
.create_linear_gradient(&self.global(), x0, y0, x1, y1)
|
.create_linear_gradient(&self.global(), x0, y0, x1, y1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -565,7 +522,6 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
r1: Finite<f64>,
|
r1: Finite<f64>,
|
||||||
) -> Fallible<DomRoot<CanvasGradient>> {
|
) -> Fallible<DomRoot<CanvasGradient>> {
|
||||||
self.canvas_state
|
self.canvas_state
|
||||||
.borrow()
|
|
||||||
.create_radial_gradient(&self.global(), x0, y0, r0, x1, y1, r1)
|
.create_radial_gradient(&self.global(), x0, y0, r0, x1, y1, r1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -576,88 +532,87 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
repetition: DOMString,
|
repetition: DOMString,
|
||||||
) -> Fallible<Option<DomRoot<CanvasPattern>>> {
|
) -> Fallible<Option<DomRoot<CanvasPattern>>> {
|
||||||
self.canvas_state
|
self.canvas_state
|
||||||
.borrow()
|
|
||||||
.create_pattern(&self.global(), image, repetition)
|
.create_pattern(&self.global(), image, repetition)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth
|
||||||
fn LineWidth(&self) -> f64 {
|
fn LineWidth(&self) -> f64 {
|
||||||
self.canvas_state.borrow().line_width()
|
self.canvas_state.line_width()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth
|
||||||
fn SetLineWidth(&self, width: f64) {
|
fn SetLineWidth(&self, width: f64) {
|
||||||
self.canvas_state.borrow().set_line_width(width)
|
self.canvas_state.set_line_width(width)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
|
||||||
fn LineCap(&self) -> CanvasLineCap {
|
fn LineCap(&self) -> CanvasLineCap {
|
||||||
self.canvas_state.borrow().line_cap()
|
self.canvas_state.line_cap()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
|
||||||
fn SetLineCap(&self, cap: CanvasLineCap) {
|
fn SetLineCap(&self, cap: CanvasLineCap) {
|
||||||
self.canvas_state.borrow().set_line_cap(cap)
|
self.canvas_state.set_line_cap(cap)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
|
||||||
fn LineJoin(&self) -> CanvasLineJoin {
|
fn LineJoin(&self) -> CanvasLineJoin {
|
||||||
self.canvas_state.borrow().line_join()
|
self.canvas_state.line_join()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
|
||||||
fn SetLineJoin(&self, join: CanvasLineJoin) {
|
fn SetLineJoin(&self, join: CanvasLineJoin) {
|
||||||
self.canvas_state.borrow().set_line_join(join)
|
self.canvas_state.set_line_join(join)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-miterlimit
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-miterlimit
|
||||||
fn MiterLimit(&self) -> f64 {
|
fn MiterLimit(&self) -> f64 {
|
||||||
self.canvas_state.borrow().miter_limit()
|
self.canvas_state.miter_limit()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-miterlimit
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-miterlimit
|
||||||
fn SetMiterLimit(&self, limit: f64) {
|
fn SetMiterLimit(&self, limit: f64) {
|
||||||
self.canvas_state.borrow().set_miter_limit(limit)
|
self.canvas_state.set_miter_limit(limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsetx
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsetx
|
||||||
fn ShadowOffsetX(&self) -> f64 {
|
fn ShadowOffsetX(&self) -> f64 {
|
||||||
self.canvas_state.borrow().shadow_offset_x()
|
self.canvas_state.shadow_offset_x()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsetx
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsetx
|
||||||
fn SetShadowOffsetX(&self, value: f64) {
|
fn SetShadowOffsetX(&self, value: f64) {
|
||||||
self.canvas_state.borrow().set_shadow_offset_x(value)
|
self.canvas_state.set_shadow_offset_x(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsety
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsety
|
||||||
fn ShadowOffsetY(&self) -> f64 {
|
fn ShadowOffsetY(&self) -> f64 {
|
||||||
self.canvas_state.borrow().shadow_offset_y()
|
self.canvas_state.shadow_offset_y()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsety
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsety
|
||||||
fn SetShadowOffsetY(&self, value: f64) {
|
fn SetShadowOffsetY(&self, value: f64) {
|
||||||
self.canvas_state.borrow().set_shadow_offset_y(value)
|
self.canvas_state.set_shadow_offset_y(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowblur
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowblur
|
||||||
fn ShadowBlur(&self) -> f64 {
|
fn ShadowBlur(&self) -> f64 {
|
||||||
self.canvas_state.borrow().shadow_blur()
|
self.canvas_state.shadow_blur()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowblur
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowblur
|
||||||
fn SetShadowBlur(&self, value: f64) {
|
fn SetShadowBlur(&self, value: f64) {
|
||||||
self.canvas_state.borrow().set_shadow_blur(value)
|
self.canvas_state.set_shadow_blur(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowcolor
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowcolor
|
||||||
fn ShadowColor(&self) -> DOMString {
|
fn ShadowColor(&self) -> DOMString {
|
||||||
self.canvas_state.borrow().shadow_color()
|
self.canvas_state.shadow_color()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowcolor
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowcolor
|
||||||
fn SetShadowColor(&self, value: DOMString) {
|
fn SetShadowColor(&self, value: DOMString) {
|
||||||
self.canvas_state.borrow().set_shadow_color(value)
|
self.canvas_state.set_shadow_color(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -665,9 +620,8 @@ impl Drop for CanvasRenderingContext2D {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let Err(err) = self
|
if let Err(err) = self
|
||||||
.canvas_state
|
.canvas_state
|
||||||
.borrow()
|
|
||||||
.get_ipc_renderer()
|
.get_ipc_renderer()
|
||||||
.send(CanvasMsg::Close(self.canvas_state.borrow().get_canvas_id()))
|
.send(CanvasMsg::Close(self.canvas_state.get_canvas_id()))
|
||||||
{
|
{
|
||||||
warn!("Could not close canvas: {}", err)
|
warn!("Could not close canvas: {}", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue