mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Canvas: add clipping path support.
This commit is contained in:
parent
3a1bf45dea
commit
6fd6eefb35
29 changed files with 16 additions and 134 deletions
|
@ -24,8 +24,9 @@ pub enum Canvas2dMsg {
|
||||||
DrawImageSelf(Size2D<f64>, Rect<f64>, Rect<f64>, bool),
|
DrawImageSelf(Size2D<f64>, Rect<f64>, Rect<f64>, bool),
|
||||||
BeginPath,
|
BeginPath,
|
||||||
BezierCurveTo(Point2D<f32>, Point2D<f32>, Point2D<f32>),
|
BezierCurveTo(Point2D<f32>, Point2D<f32>, Point2D<f32>),
|
||||||
ClosePath,
|
|
||||||
ClearRect(Rect<f32>),
|
ClearRect(Rect<f32>),
|
||||||
|
Clip,
|
||||||
|
ClosePath,
|
||||||
Fill,
|
Fill,
|
||||||
FillRect(Rect<f32>),
|
FillRect(Rect<f32>),
|
||||||
GetImageData(Rect<f64>, Size2D<f64>, Sender<Vec<u8>>),
|
GetImageData(Rect<f64>, Size2D<f64>, Sender<Vec<u8>>),
|
||||||
|
|
|
@ -212,6 +212,7 @@ impl<'a> CanvasPaintTask<'a> {
|
||||||
Canvas2dMsg::ClosePath => painter.close_path(),
|
Canvas2dMsg::ClosePath => painter.close_path(),
|
||||||
Canvas2dMsg::Fill => painter.fill(),
|
Canvas2dMsg::Fill => painter.fill(),
|
||||||
Canvas2dMsg::Stroke => painter.stroke(),
|
Canvas2dMsg::Stroke => painter.stroke(),
|
||||||
|
Canvas2dMsg::Clip => painter.clip(),
|
||||||
Canvas2dMsg::DrawImage(imagedata, image_size, dest_rect, source_rect, smoothing_enabled) => {
|
Canvas2dMsg::DrawImage(imagedata, image_size, dest_rect, source_rect, smoothing_enabled) => {
|
||||||
painter.draw_image(imagedata, image_size, dest_rect, source_rect, smoothing_enabled)
|
painter.draw_image(imagedata, image_size, dest_rect, source_rect, smoothing_enabled)
|
||||||
}
|
}
|
||||||
|
@ -271,6 +272,7 @@ impl<'a> CanvasPaintTask<'a> {
|
||||||
if let Some(state) = self.saved_states.pop() {
|
if let Some(state) = self.saved_states.pop() {
|
||||||
mem::replace(&mut self.state, state);
|
mem::replace(&mut self.state, state);
|
||||||
self.drawtarget.set_transform(&self.state.transform);
|
self.drawtarget.set_transform(&self.state.transform);
|
||||||
|
self.drawtarget.pop_clip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,6 +327,10 @@ impl<'a> CanvasPaintTask<'a> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn clip(&self) {
|
||||||
|
self.drawtarget.push_clip(&self.path_builder.finish());
|
||||||
|
}
|
||||||
|
|
||||||
fn draw_image(&self, image_data: Vec<u8>, image_size: Size2D<f64>,
|
fn draw_image(&self, image_data: Vec<u8>, image_size: Size2D<f64>,
|
||||||
dest_rect: Rect<f64>, source_rect: Rect<f64>, smoothing_enabled: bool) {
|
dest_rect: Rect<f64>, source_rect: Rect<f64>, smoothing_enabled: bool) {
|
||||||
// We round up the floating pixel values to draw the pixels
|
// We round up the floating pixel values to draw the pixels
|
||||||
|
|
|
@ -454,6 +454,7 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-fill
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-fill
|
||||||
fn Fill(self, _: CanvasWindingRule) {
|
fn Fill(self, _: CanvasWindingRule) {
|
||||||
|
// TODO: Process winding rule
|
||||||
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::Fill)).unwrap();
|
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::Fill)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,6 +463,12 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
|
||||||
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::Stroke)).unwrap();
|
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::Stroke)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-clip
|
||||||
|
fn Clip(self, _: CanvasWindingRule) {
|
||||||
|
// TODO: Process winding rule
|
||||||
|
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::Clip)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage
|
||||||
fn DrawImage(self, image: HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D,
|
fn DrawImage(self, image: HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D,
|
||||||
dx: f64, dy: f64) -> Fallible<()> {
|
dx: f64, dy: f64) -> Fallible<()> {
|
||||||
|
|
|
@ -90,7 +90,7 @@ interface CanvasRenderingContext2D {
|
||||||
//boolean drawCustomFocusRing(Path2D path, Element element);
|
//boolean drawCustomFocusRing(Path2D path, Element element);
|
||||||
//void scrollPathIntoView();
|
//void scrollPathIntoView();
|
||||||
//void scrollPathIntoView(Path2D path);
|
//void scrollPathIntoView(Path2D path);
|
||||||
//void clip(optional CanvasWindingRule fillRule = "nonzero");
|
void clip(optional CanvasWindingRule fillRule = "nonzero");
|
||||||
//void clip(Path2D path, optional CanvasWindingRule fillRule = "nonzero");
|
//void clip(Path2D path, optional CanvasWindingRule fillRule = "nonzero");
|
||||||
//void resetClip();
|
//void resetClip();
|
||||||
//boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasWindingRule fillRule = "nonzero");
|
//boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasWindingRule fillRule = "nonzero");
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.clip.copy.html]
|
|
||||||
type: testharness
|
|
||||||
[fill() does not affect pixels outside the clip region.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.clip.destination-atop.html]
|
|
||||||
type: testharness
|
|
||||||
[fill() does not affect pixels outside the clip region.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.clip.destination-in.html]
|
|
||||||
type: testharness
|
|
||||||
[fill() does not affect pixels outside the clip region.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.clip.destination-out.html]
|
|
||||||
type: testharness
|
|
||||||
[fill() does not affect pixels outside the clip region.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.clip.destination-over.html]
|
|
||||||
type: testharness
|
|
||||||
[fill() does not affect pixels outside the clip region.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.clip.lighter.html]
|
|
||||||
type: testharness
|
|
||||||
[fill() does not affect pixels outside the clip region.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.clip.source-atop.html]
|
|
||||||
type: testharness
|
|
||||||
[fill() does not affect pixels outside the clip region.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.clip.source-in.html]
|
|
||||||
type: testharness
|
|
||||||
[fill() does not affect pixels outside the clip region.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.clip.source-out.html]
|
|
||||||
type: testharness
|
|
||||||
[fill() does not affect pixels outside the clip region.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.clip.source-over.html]
|
|
||||||
type: testharness
|
|
||||||
[fill() does not affect pixels outside the clip region.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.composite.clip.xor.html]
|
|
||||||
type: testharness
|
|
||||||
[fill() does not affect pixels outside the clip region.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.drawImage.clip.html]
|
|
||||||
type: testharness
|
|
||||||
[Canvas test: 2d.drawImage.clip]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.clearRect.clip.html]
|
|
||||||
type: testharness
|
|
||||||
[clearRect is affected by clipping regions]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.fillRect.clip.html]
|
|
||||||
type: testharness
|
|
||||||
[fillRect is affected by clipping regions]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.strokeRect.clip.html]
|
|
||||||
type: testharness
|
|
||||||
[strokeRect is affected by clipping regions]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.path.clip.basic.1.html]
|
|
||||||
type: testharness
|
|
||||||
[Canvas test: 2d.path.clip.basic.1]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.path.clip.basic.2.html]
|
|
||||||
type: testharness
|
|
||||||
[Canvas test: 2d.path.clip.basic.2]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.path.clip.empty.html]
|
|
||||||
type: testharness
|
|
||||||
[Canvas test: 2d.path.clip.empty]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.path.clip.intersect.html]
|
|
||||||
type: testharness
|
|
||||||
[Canvas test: 2d.path.clip.intersect]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.path.clip.winding.1.html]
|
|
||||||
type: testharness
|
|
||||||
[Canvas test: 2d.path.clip.winding.1]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.path.clip.winding.2.html]
|
|
||||||
type: testharness
|
|
||||||
[Canvas test: 2d.path.clip.winding.2]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.shadow.clip.2.html]
|
|
||||||
type: testharness
|
|
||||||
[Shadows are not drawn outside the clipping region]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[2d.state.saverestore.clip.html]
|
|
||||||
type: testharness
|
|
||||||
[save()/restore() affects the clipping path]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -6924,9 +6924,6 @@
|
||||||
[CanvasRenderingContext2D interface: operation clip(CanvasFillRule)]
|
[CanvasRenderingContext2D interface: operation clip(CanvasFillRule)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation clip(Path2D,CanvasFillRule)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: operation resetClip()]
|
[CanvasRenderingContext2D interface: operation resetClip()]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -7086,15 +7083,6 @@
|
||||||
[CanvasRenderingContext2D interface: calling scrollPathIntoView(Path2D) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
|
[CanvasRenderingContext2D interface: calling scrollPathIntoView(Path2D) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "clip" with the proper type (39)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: calling clip(CanvasFillRule) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "clip" with the proper type (40)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CanvasRenderingContext2D interface: calling clip(Path2D,CanvasFillRule) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
|
[CanvasRenderingContext2D interface: calling clip(Path2D,CanvasFillRule) on document.createElement("canvas").getContext("2d") with too few arguments must throw TypeError]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[initial.reset.clip.html]
|
|
||||||
type: testharness
|
|
||||||
[Resetting the canvas state resets the current clip region]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue