Skip to content

Commit

Permalink
Auto merge of #25734 - pylbrecht:get.transform, r=jdm
Browse files Browse the repository at this point in the history
Implement CanvasRenderingContext2D.getTransform()

<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix part of #25331

<!-- Either: -->
- [x] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
  • Loading branch information
bors-servo committed Feb 13, 2020
2 parents e3a2301 + 588c09b commit 2c70db5
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 22 deletions.
4 changes: 4 additions & 0 deletions components/canvas/canvas_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,10 @@ impl<'a> CanvasData<'a> {
self.state.stroke_opts.set_miter_limit(limit);
}

pub fn get_transform(&self) -> Transform2D<f32> {
self.drawtarget.get_transform()
}

pub fn set_transform(&mut self, transform: &Transform2D<f32>) {
// If there is an in-progress path, store the existing transformation required
// to move between device and user space.
Expand Down
4 changes: 4 additions & 0 deletions components/canvas/canvas_paint_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ impl<'a> CanvasPaintThread<'a> {
Canvas2dMsg::SetLineCap(cap) => self.canvas(canvas_id).set_line_cap(cap),
Canvas2dMsg::SetLineJoin(join) => self.canvas(canvas_id).set_line_join(join),
Canvas2dMsg::SetMiterLimit(limit) => self.canvas(canvas_id).set_miter_limit(limit),
Canvas2dMsg::GetTransform(sender) => {
let transform = self.canvas(canvas_id).get_transform();
sender.send(transform).unwrap();
},
Canvas2dMsg::SetTransform(ref matrix) => self.canvas(canvas_id).set_transform(matrix),
Canvas2dMsg::SetGlobalAlpha(alpha) => self.canvas(canvas_id).set_global_alpha(alpha),
Canvas2dMsg::SetGlobalComposition(op) => {
Expand Down
1 change: 1 addition & 0 deletions components/canvas_traits/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub enum Canvas2dMsg {
FillText(String, f64, f64, Option<f64>, FillOrStrokeStyle),
FillRect(Rect<f32>, FillOrStrokeStyle),
GetImageData(Rect<u64>, Size2D<u64>, IpcBytesSender),
GetTransform(IpcSender<Transform2D<f32>>),
IsPointInPath(f64, f64, FillRule, IpcSender<bool>),
LineTo(Point2D<f32>),
MoveTo(Point2D<f32>),
Expand Down
10 changes: 10 additions & 0 deletions components/script/canvas_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::canvasgradient::{CanvasGradient, CanvasGradientStyle, ToFillOrStrokeStyle};
use crate::dom::canvaspattern::CanvasPattern;
use crate::dom::dommatrix::DOMMatrix;
use crate::dom::element::cors_setting_for_element;
use crate::dom::element::Element;
use crate::dom::globalscope::GlobalScope;
Expand Down Expand Up @@ -1415,6 +1416,15 @@ impl CanvasState {
self.update_transform()
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform
pub fn get_transform(&self, global: &GlobalScope) -> DomRoot<DOMMatrix> {
let (sender, receiver) = ipc::channel::<Transform2D<f32>>().unwrap();
self.send_canvas_2d_msg(Canvas2dMsg::GetTransform(sender));
let transform = receiver.recv().unwrap();

DOMMatrix::new(global, true, transform.cast::<f64>().to_3d())
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform
pub fn set_transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
if !(a.is_finite() &&
Expand Down
6 changes: 6 additions & 0 deletions components/script/dom/canvasrenderingcontext2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::dom::bindings::root::{Dom, DomRoot, LayoutDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::canvasgradient::CanvasGradient;
use crate::dom::canvaspattern::CanvasPattern;
use crate::dom::dommatrix::DOMMatrix;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlcanvaselement::HTMLCanvasElement;
use crate::dom::imagedata::ImageData;
Expand Down Expand Up @@ -224,6 +225,11 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
self.canvas_state.borrow().transform(a, b, c, d, e, f)
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform
fn GetTransform(&self) -> DomRoot<DOMMatrix> {
self.canvas_state.borrow().get_transform(&self.global())
}

// 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) {
self.canvas_state.borrow().set_transform(a, b, c, d, e, f)
Expand Down
6 changes: 6 additions & 0 deletions components/script/dom/offscreencanvasrenderingcontext2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::canvasgradient::CanvasGradient;
use crate::dom::canvaspattern::CanvasPattern;
use crate::dom::dommatrix::DOMMatrix;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlcanvaselement::HTMLCanvasElement;
use crate::dom::imagedata::ImageData;
Expand Down Expand Up @@ -470,6 +471,11 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
self.canvas_state.borrow().transform(a, b, c, d, e, f)
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform
fn GetTransform(&self) -> DomRoot<DOMMatrix> {
self.canvas_state.borrow().get_transform(&self.global())
}

// 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) {
self.canvas_state.borrow().set_transform(a, b, c, d, e, f)
Expand Down
6 changes: 6 additions & 0 deletions components/script/dom/paintrenderingcontext2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::dom::bindings::str::DOMString;
use crate::dom::canvasgradient::CanvasGradient;
use crate::dom::canvaspattern::CanvasPattern;
use crate::dom::canvasrenderingcontext2d::CanvasRenderingContext2D;
use crate::dom::dommatrix::DOMMatrix;
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
use crate::euclidext::Size2DExt;
use canvas_traits::canvas::CanvasImageData;
Expand Down Expand Up @@ -119,6 +120,11 @@ impl PaintRenderingContext2DMethods for PaintRenderingContext2D {
self.context.Transform(a, b, c, d, e, f)
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform
fn GetTransform(&self) -> DomRoot<DOMMatrix> {
self.context.GetTransform()
}

// 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) {
self.context.SetTransform(a, b, c, d, e, f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ interface mixin CanvasTransform {
unrestricted double e,
unrestricted double f);

// [NewObject] DOMMatrix getTransform();
[NewObject] DOMMatrix getTransform();
void setTransform(unrestricted double a,
unrestricted double b,
unrestricted double c,
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/DOMMatrix.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* related or neighboring rights to this work.
*/

[Exposed=(Window,Worker),
[Exposed=(Window,Worker,PaintWorklet),
LegacyWindowAlias=WebKitCSSMatrix]
interface DOMMatrix : DOMMatrixReadOnly {
[Throws] constructor(optional (DOMString or sequence<unrestricted double>) init);
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/DOMMatrixReadOnly.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* related or neighboring rights to this work.
*/

[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,PaintWorklet)]
interface DOMMatrixReadOnly {
[Throws] constructor(optional (DOMString or sequence<unrestricted double>) init);

Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/DOMPoint.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

// http://dev.w3.org/fxtf/geometry/Overview.html#dompoint
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,PaintWorklet)]
interface DOMPoint : DOMPointReadOnly {
[Throws] constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
optional unrestricted double z = 0, optional unrestricted double w = 1);
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/DOMPointReadOnly.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

// http://dev.w3.org/fxtf/geometry/Overview.html#dompointreadonly
[Exposed=(Window,Worker)]
[Exposed=(Window,Worker,PaintWorklet)]
interface DOMPointReadOnly {
[Throws] constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
optional unrestricted double z = 0, optional unrestricted double w = 1);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
[addPath({f: 0, m42: 5e-324}) (invalid)]
expected: FAIL

[setTransform (Sanity check without dictionary)]
expected: FAIL

[addPath (Sanity check without second parameter)]
expected: FAIL

Expand Down
6 changes: 0 additions & 6 deletions tests/wpt/metadata/html/dom/idlharness.https.html.ini
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@
[ApplicationCache interface: window.applicationCache must inherit property "ondownloading" with the proper type]
expected: FAIL

[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "getTransform()" with the proper type]
expected: FAIL

[OffscreenCanvasRenderingContext2D interface: attribute imageSmoothingEnabled]
expected: FAIL

Expand Down Expand Up @@ -1178,9 +1175,6 @@
[External interface object length]
expected: FAIL

[CanvasRenderingContext2D interface: operation getTransform()]
expected: FAIL

[OffscreenCanvasRenderingContext2D interface: operation arc(unrestricted double, unrestricted double, unrestricted double, unrestricted double, unrestricted double, boolean)]
expected: FAIL

Expand Down

This file was deleted.

0 comments on commit 2c70db5

Please sign in to comment.