script/dom/canvas/2d/
canvasrenderingcontext2d.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use base::Epoch;
6use canvas_traits::canvas::{Canvas2dMsg, CanvasId};
7use dom_struct::dom_struct;
8use euclid::default::Size2D;
9use ipc_channel::ipc;
10use pixels::Snapshot;
11use servo_url::ServoUrl;
12use webrender_api::ImageKey;
13
14use super::canvas_state::CanvasState;
15use crate::canvas_context::{CanvasContext, CanvasHelpers, HTMLCanvasElementOrOffscreenCanvas};
16use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::{
17    CanvasDirection, CanvasFillRule, CanvasImageSource, CanvasLineCap, CanvasLineJoin,
18    CanvasRenderingContext2DMethods, CanvasTextAlign, CanvasTextBaseline,
19};
20use crate::dom::bindings::codegen::Bindings::DOMMatrixBinding::DOMMatrix2DInit;
21use crate::dom::bindings::codegen::UnionTypes::{
22    HTMLCanvasElementOrOffscreenCanvas as RootedHTMLCanvasElementOrOffscreenCanvas,
23    StringOrCanvasGradientOrCanvasPattern,
24};
25use crate::dom::bindings::error::{ErrorResult, Fallible};
26use crate::dom::bindings::num::Finite;
27use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
28use crate::dom::bindings::root::{Dom, DomRoot};
29use crate::dom::bindings::str::DOMString;
30use crate::dom::canvasgradient::CanvasGradient;
31use crate::dom::canvaspattern::CanvasPattern;
32use crate::dom::dommatrix::DOMMatrix;
33use crate::dom::globalscope::GlobalScope;
34use crate::dom::html::htmlcanvaselement::HTMLCanvasElement;
35use crate::dom::imagedata::ImageData;
36use crate::dom::path2d::Path2D;
37use crate::dom::textmetrics::TextMetrics;
38use crate::script_runtime::CanGc;
39
40// https://html.spec.whatwg.org/multipage/#canvasrenderingcontext2d
41#[dom_struct]
42pub(crate) struct CanvasRenderingContext2D {
43    reflector_: Reflector,
44    canvas: HTMLCanvasElementOrOffscreenCanvas,
45    canvas_state: CanvasState,
46}
47
48impl CanvasRenderingContext2D {
49    #[cfg_attr(crown, allow(crown::unrooted_must_root))]
50    pub(crate) fn new_inherited(
51        global: &GlobalScope,
52        canvas: HTMLCanvasElementOrOffscreenCanvas,
53        size: Size2D<u32>,
54    ) -> Option<CanvasRenderingContext2D> {
55        let canvas_state =
56            CanvasState::new(global, Size2D::new(size.width as u64, size.height as u64))?;
57        Some(CanvasRenderingContext2D {
58            reflector_: Reflector::new(),
59            canvas,
60            canvas_state,
61        })
62    }
63
64    pub(crate) fn new(
65        global: &GlobalScope,
66        canvas: &HTMLCanvasElement,
67        size: Size2D<u32>,
68        can_gc: CanGc,
69    ) -> Option<DomRoot<CanvasRenderingContext2D>> {
70        CanvasRenderingContext2D::new_inherited(
71            global,
72            HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(Dom::from_ref(canvas)),
73            size,
74        )
75        .map(|context| reflect_dom_object(Box::new(context), global, can_gc))
76    }
77
78    pub(crate) fn take_missing_image_urls(&self) -> Vec<ServoUrl> {
79        std::mem::take(&mut self.canvas_state.get_missing_image_urls().borrow_mut())
80    }
81
82    pub(crate) fn get_canvas_id(&self) -> CanvasId {
83        self.canvas_state.get_canvas_id()
84    }
85
86    pub(crate) fn send_canvas_2d_msg(&self, msg: Canvas2dMsg) {
87        self.canvas_state.send_canvas_2d_msg(msg)
88    }
89
90    pub(crate) fn set_image_key(&self, image_key: ImageKey) {
91        self.canvas_state.set_image_key(image_key);
92    }
93
94    pub(crate) fn update_rendering(&self, canvas_epoch: Epoch) -> bool {
95        if !self.onscreen() {
96            return false;
97        }
98        self.canvas_state.update_rendering(Some(canvas_epoch))
99    }
100}
101
102impl CanvasContext for CanvasRenderingContext2D {
103    type ID = CanvasId;
104
105    fn context_id(&self) -> Self::ID {
106        self.canvas_state.get_canvas_id()
107    }
108
109    fn canvas(&self) -> Option<RootedHTMLCanvasElementOrOffscreenCanvas> {
110        Some(RootedHTMLCanvasElementOrOffscreenCanvas::from(&self.canvas))
111    }
112
113    fn resize(&self) {
114        self.canvas_state.set_bitmap_dimensions(self.size().cast());
115    }
116
117    fn reset_bitmap(&self) {
118        self.canvas_state.reset_bitmap()
119    }
120
121    fn get_image_data(&self) -> Option<Snapshot> {
122        if !self.canvas_state.is_paintable() {
123            return None;
124        }
125
126        let (sender, receiver) = ipc::channel().unwrap();
127        self.canvas_state
128            .send_canvas_2d_msg(Canvas2dMsg::GetImageData(None, sender));
129        Some(receiver.recv().unwrap().to_owned())
130    }
131
132    fn origin_is_clean(&self) -> bool {
133        self.canvas_state.origin_is_clean()
134    }
135
136    fn mark_as_dirty(&self) {
137        self.canvas.mark_as_dirty();
138    }
139}
140
141// We add a guard to each of methods by the spec:
142// http://www.w3.org/html/wg/drafts/2dcontext/html5_canvas_CR/
143//
144// > Except where otherwise specified, for the 2D context interface,
145// > any method call with a numeric argument whose value is infinite or a NaN value must be ignored.
146//
147//  Restricted values are guarded in glue code. Therefore we need not add a guard.
148//
149// FIXME: this behavior should might be generated by some annotations to idl.
150impl CanvasRenderingContext2DMethods<crate::DomTypeHolder> for CanvasRenderingContext2D {
151    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-canvas>
152    fn Canvas(&self) -> DomRoot<HTMLCanvasElement> {
153        match &self.canvas {
154            HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(canvas) => canvas.as_rooted(),
155            _ => panic!("Should not be called from offscreen canvas"),
156        }
157    }
158
159    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-save>
160    fn Save(&self) {
161        self.canvas_state.save()
162    }
163
164    #[cfg_attr(crown, allow(crown::unrooted_must_root))]
165    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-restore>
166    fn Restore(&self) {
167        self.canvas_state.restore()
168    }
169
170    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-reset>
171    fn Reset(&self) {
172        self.canvas_state.reset()
173    }
174
175    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-scale>
176    fn Scale(&self, x: f64, y: f64) {
177        self.canvas_state.scale(x, y)
178    }
179
180    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-rotate>
181    fn Rotate(&self, angle: f64) {
182        self.canvas_state.rotate(angle)
183    }
184
185    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-translate>
186    fn Translate(&self, x: f64, y: f64) {
187        self.canvas_state.translate(x, y)
188    }
189
190    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-transform>
191    fn Transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) {
192        self.canvas_state.transform(a, b, c, d, e, f)
193    }
194
195    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform>
196    fn GetTransform(&self, can_gc: CanGc) -> DomRoot<DOMMatrix> {
197        self.canvas_state.get_transform(&self.global(), can_gc)
198    }
199
200    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform>
201    fn SetTransform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) -> ErrorResult {
202        self.canvas_state.set_transform(a, b, c, d, e, f);
203        Ok(())
204    }
205
206    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform-matrix>
207    fn SetTransform_(&self, transform: &DOMMatrix2DInit) -> ErrorResult {
208        self.canvas_state.set_transform_(transform)
209    }
210
211    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-resettransform>
212    fn ResetTransform(&self) {
213        self.canvas_state.reset_transform()
214    }
215
216    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-globalalpha>
217    fn GlobalAlpha(&self) -> f64 {
218        self.canvas_state.global_alpha()
219    }
220
221    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-globalalpha>
222    fn SetGlobalAlpha(&self, alpha: f64) {
223        self.canvas_state.set_global_alpha(alpha)
224    }
225
226    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation>
227    fn GlobalCompositeOperation(&self) -> DOMString {
228        self.canvas_state.global_composite_operation()
229    }
230
231    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation>
232    fn SetGlobalCompositeOperation(&self, op_str: DOMString) {
233        self.canvas_state.set_global_composite_operation(op_str)
234    }
235
236    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-fillrect>
237    fn FillRect(&self, x: f64, y: f64, width: f64, height: f64) {
238        self.canvas_state.fill_rect(x, y, width, height);
239        self.mark_as_dirty();
240    }
241
242    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-clearrect>
243    fn ClearRect(&self, x: f64, y: f64, width: f64, height: f64) {
244        self.canvas_state.clear_rect(x, y, width, height);
245        self.mark_as_dirty();
246    }
247
248    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-strokerect>
249    fn StrokeRect(&self, x: f64, y: f64, width: f64, height: f64) {
250        self.canvas_state.stroke_rect(x, y, width, height);
251        self.mark_as_dirty();
252    }
253
254    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-beginpath>
255    fn BeginPath(&self) {
256        self.canvas_state.begin_path()
257    }
258
259    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-closepath>
260    fn ClosePath(&self) {
261        self.canvas_state.close_path()
262    }
263
264    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-fill>
265    fn Fill(&self, fill_rule: CanvasFillRule) {
266        self.canvas_state.fill(fill_rule);
267        self.mark_as_dirty();
268    }
269
270    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-fill>
271    fn Fill_(&self, path: &Path2D, fill_rule: CanvasFillRule) {
272        self.canvas_state.fill_(path.segments(), fill_rule);
273        self.mark_as_dirty();
274    }
275
276    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-stroke>
277    fn Stroke(&self) {
278        self.canvas_state.stroke();
279        self.mark_as_dirty();
280    }
281
282    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-stroke>
283    fn Stroke_(&self, path: &Path2D) {
284        self.canvas_state.stroke_(path.segments());
285        self.mark_as_dirty();
286    }
287
288    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-clip>
289    fn Clip(&self, fill_rule: CanvasFillRule) {
290        self.canvas_state.clip(fill_rule)
291    }
292
293    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-clip>
294    fn Clip_(&self, path: &Path2D, fill_rule: CanvasFillRule) {
295        self.canvas_state.clip_(path.segments(), fill_rule)
296    }
297
298    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-ispointinpath>
299    fn IsPointInPath(&self, x: f64, y: f64, fill_rule: CanvasFillRule) -> bool {
300        self.canvas_state
301            .is_point_in_path(&self.global(), x, y, fill_rule)
302    }
303
304    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-ispointinpath>
305    fn IsPointInPath_(&self, path: &Path2D, x: f64, y: f64, fill_rule: CanvasFillRule) -> bool {
306        self.canvas_state
307            .is_point_in_path_(&self.global(), path.segments(), x, y, fill_rule)
308    }
309
310    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-filltext>
311    fn FillText(&self, text: DOMString, x: f64, y: f64, max_width: Option<f64>) {
312        self.canvas_state.fill_text(
313            &self.global(),
314            self.canvas.canvas().as_deref(),
315            text,
316            x,
317            y,
318            max_width,
319        );
320        self.mark_as_dirty();
321    }
322
323    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-stroketext>
324    fn StrokeText(&self, text: DOMString, x: f64, y: f64, max_width: Option<f64>) {
325        self.canvas_state.stroke_text(
326            &self.global(),
327            self.canvas.canvas().as_deref(),
328            text,
329            x,
330            y,
331            max_width,
332        );
333        self.mark_as_dirty();
334    }
335
336    /// <https://html.spec.whatwg.org/multipage/#textmetrics>
337    fn MeasureText(&self, text: DOMString, can_gc: CanGc) -> DomRoot<TextMetrics> {
338        self.canvas_state.measure_text(
339            &self.global(),
340            self.canvas.canvas().as_deref(),
341            text,
342            can_gc,
343        )
344    }
345
346    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-font>
347    fn Font(&self) -> DOMString {
348        self.canvas_state.font()
349    }
350
351    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-font>
352    fn SetFont(&self, value: DOMString) {
353        self.canvas_state
354            .set_font(self.canvas.canvas().as_deref(), value)
355    }
356
357    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-textalign>
358    fn TextAlign(&self) -> CanvasTextAlign {
359        self.canvas_state.text_align()
360    }
361
362    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-textalign>
363    fn SetTextAlign(&self, value: CanvasTextAlign) {
364        self.canvas_state.set_text_align(value)
365    }
366
367    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-textbaseline>
368    fn TextBaseline(&self) -> CanvasTextBaseline {
369        self.canvas_state.text_baseline()
370    }
371
372    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-textbaseline>
373    fn SetTextBaseline(&self, value: CanvasTextBaseline) {
374        self.canvas_state.set_text_baseline(value)
375    }
376
377    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-direction>
378    fn Direction(&self) -> CanvasDirection {
379        self.canvas_state.direction()
380    }
381
382    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-direction>
383    fn SetDirection(&self, value: CanvasDirection) {
384        self.canvas_state.set_direction(value)
385    }
386
387    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage>
388    fn DrawImage(&self, image: CanvasImageSource, dx: f64, dy: f64) -> ErrorResult {
389        self.canvas_state
390            .draw_image(self.canvas.canvas().as_deref(), image, dx, dy)
391    }
392
393    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage>
394    fn DrawImage_(
395        &self,
396        image: CanvasImageSource,
397        dx: f64,
398        dy: f64,
399        dw: f64,
400        dh: f64,
401    ) -> ErrorResult {
402        self.canvas_state
403            .draw_image_(self.canvas.canvas().as_deref(), image, dx, dy, dw, dh)
404    }
405
406    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage>
407    fn DrawImage__(
408        &self,
409        image: CanvasImageSource,
410        sx: f64,
411        sy: f64,
412        sw: f64,
413        sh: f64,
414        dx: f64,
415        dy: f64,
416        dw: f64,
417        dh: f64,
418    ) -> ErrorResult {
419        self.canvas_state.draw_image__(
420            self.canvas.canvas().as_deref(),
421            image,
422            sx,
423            sy,
424            sw,
425            sh,
426            dx,
427            dy,
428            dw,
429            dh,
430        )
431    }
432
433    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-moveto>
434    fn MoveTo(&self, x: f64, y: f64) {
435        self.canvas_state.move_to(x, y)
436    }
437
438    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-lineto>
439    fn LineTo(&self, x: f64, y: f64) {
440        self.canvas_state.line_to(x, y)
441    }
442
443    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-rect>
444    fn Rect(&self, x: f64, y: f64, width: f64, height: f64) {
445        self.canvas_state.rect(x, y, width, height)
446    }
447
448    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-quadraticcurveto>
449    fn QuadraticCurveTo(&self, cpx: f64, cpy: f64, x: f64, y: f64) {
450        self.canvas_state.quadratic_curve_to(cpx, cpy, x, y)
451    }
452
453    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-beziercurveto>
454    fn BezierCurveTo(&self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, x: f64, y: f64) {
455        self.canvas_state
456            .bezier_curve_to(cp1x, cp1y, cp2x, cp2y, x, y)
457    }
458
459    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-arc>
460    fn Arc(&self, x: f64, y: f64, r: f64, start: f64, end: f64, ccw: bool) -> ErrorResult {
461        self.canvas_state.arc(x, y, r, start, end, ccw)
462    }
463
464    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-arcto>
465    fn ArcTo(&self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, r: f64) -> ErrorResult {
466        self.canvas_state.arc_to(cp1x, cp1y, cp2x, cp2y, r)
467    }
468
469    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-ellipse>
470    fn Ellipse(
471        &self,
472        x: f64,
473        y: f64,
474        rx: f64,
475        ry: f64,
476        rotation: f64,
477        start: f64,
478        end: f64,
479        ccw: bool,
480    ) -> ErrorResult {
481        self.canvas_state
482            .ellipse(x, y, rx, ry, rotation, start, end, ccw)
483    }
484
485    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled>
486    fn ImageSmoothingEnabled(&self) -> bool {
487        self.canvas_state.image_smoothing_enabled()
488    }
489
490    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-imagesmoothingenabled>
491    fn SetImageSmoothingEnabled(&self, value: bool) {
492        self.canvas_state.set_image_smoothing_enabled(value)
493    }
494
495    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle>
496    fn StrokeStyle(&self) -> StringOrCanvasGradientOrCanvasPattern {
497        self.canvas_state.stroke_style()
498    }
499
500    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle>
501    fn SetStrokeStyle(&self, value: StringOrCanvasGradientOrCanvasPattern) {
502        self.canvas_state
503            .set_stroke_style(self.canvas.canvas().as_deref(), value)
504    }
505
506    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle>
507    fn FillStyle(&self) -> StringOrCanvasGradientOrCanvasPattern {
508        self.canvas_state.fill_style()
509    }
510
511    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-strokestyle>
512    fn SetFillStyle(&self, value: StringOrCanvasGradientOrCanvasPattern) {
513        self.canvas_state
514            .set_fill_style(self.canvas.canvas().as_deref(), value)
515    }
516
517    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata>
518    fn CreateImageData(&self, sw: i32, sh: i32, can_gc: CanGc) -> Fallible<DomRoot<ImageData>> {
519        self.canvas_state
520            .create_image_data(&self.global(), sw, sh, can_gc)
521    }
522
523    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata>
524    fn CreateImageData_(
525        &self,
526        imagedata: &ImageData,
527        can_gc: CanGc,
528    ) -> Fallible<DomRoot<ImageData>> {
529        self.canvas_state
530            .create_image_data_(&self.global(), imagedata, can_gc)
531    }
532
533    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata>
534    fn GetImageData(
535        &self,
536        sx: i32,
537        sy: i32,
538        sw: i32,
539        sh: i32,
540        can_gc: CanGc,
541    ) -> Fallible<DomRoot<ImageData>> {
542        self.canvas_state
543            .get_image_data(self.canvas.size(), &self.global(), sx, sy, sw, sh, can_gc)
544    }
545
546    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata>
547    fn PutImageData(&self, imagedata: &ImageData, dx: i32, dy: i32) {
548        self.canvas_state
549            .put_image_data(self.canvas.size(), imagedata, dx, dy)
550    }
551
552    // https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
553    fn PutImageData_(
554        &self,
555        imagedata: &ImageData,
556        dx: i32,
557        dy: i32,
558        dirty_x: i32,
559        dirty_y: i32,
560        dirty_width: i32,
561        dirty_height: i32,
562    ) {
563        self.canvas_state.put_image_data_(
564            self.canvas.size(),
565            imagedata,
566            dx,
567            dy,
568            dirty_x,
569            dirty_y,
570            dirty_width,
571            dirty_height,
572        );
573        self.mark_as_dirty();
574    }
575
576    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-createlineargradient>
577    fn CreateLinearGradient(
578        &self,
579        x0: Finite<f64>,
580        y0: Finite<f64>,
581        x1: Finite<f64>,
582        y1: Finite<f64>,
583        can_gc: CanGc,
584    ) -> DomRoot<CanvasGradient> {
585        self.canvas_state
586            .create_linear_gradient(&self.global(), x0, y0, x1, y1, can_gc)
587    }
588
589    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-createradialgradient>
590    fn CreateRadialGradient(
591        &self,
592        x0: Finite<f64>,
593        y0: Finite<f64>,
594        r0: Finite<f64>,
595        x1: Finite<f64>,
596        y1: Finite<f64>,
597        r1: Finite<f64>,
598        can_gc: CanGc,
599    ) -> Fallible<DomRoot<CanvasGradient>> {
600        self.canvas_state
601            .create_radial_gradient(&self.global(), x0, y0, r0, x1, y1, r1, can_gc)
602    }
603
604    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-createpattern>
605    fn CreatePattern(
606        &self,
607        image: CanvasImageSource,
608        repetition: DOMString,
609        can_gc: CanGc,
610    ) -> Fallible<Option<DomRoot<CanvasPattern>>> {
611        self.canvas_state
612            .create_pattern(&self.global(), image, repetition, can_gc)
613    }
614
615    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth>
616    fn LineWidth(&self) -> f64 {
617        self.canvas_state.line_width()
618    }
619
620    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth>
621    fn SetLineWidth(&self, width: f64) {
622        self.canvas_state.set_line_width(width)
623    }
624
625    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap>
626    fn LineCap(&self) -> CanvasLineCap {
627        self.canvas_state.line_cap()
628    }
629
630    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap>
631    fn SetLineCap(&self, cap: CanvasLineCap) {
632        self.canvas_state.set_line_cap(cap)
633    }
634
635    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin>
636    fn LineJoin(&self) -> CanvasLineJoin {
637        self.canvas_state.line_join()
638    }
639
640    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin>
641    fn SetLineJoin(&self, join: CanvasLineJoin) {
642        self.canvas_state.set_line_join(join)
643    }
644
645    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-miterlimit>
646    fn MiterLimit(&self) -> f64 {
647        self.canvas_state.miter_limit()
648    }
649
650    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-miterlimit>
651    fn SetMiterLimit(&self, limit: f64) {
652        self.canvas_state.set_miter_limit(limit)
653    }
654
655    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-setlinedash>
656    fn SetLineDash(&self, segments: Vec<f64>) {
657        self.canvas_state.set_line_dash(segments);
658    }
659
660    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-getlinedash>
661    fn GetLineDash(&self) -> Vec<f64> {
662        self.canvas_state.line_dash()
663    }
664
665    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-linedashoffset>
666    fn LineDashOffset(&self) -> f64 {
667        self.canvas_state.line_dash_offset()
668    }
669
670    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-linedashoffset>
671    fn SetLineDashOffset(&self, offset: f64) {
672        self.canvas_state.set_line_dash_offset(offset);
673    }
674
675    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsetx>
676    fn ShadowOffsetX(&self) -> f64 {
677        self.canvas_state.shadow_offset_x()
678    }
679
680    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsetx>
681    fn SetShadowOffsetX(&self, value: f64) {
682        self.canvas_state.set_shadow_offset_x(value)
683    }
684
685    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsety>
686    fn ShadowOffsetY(&self) -> f64 {
687        self.canvas_state.shadow_offset_y()
688    }
689
690    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowoffsety>
691    fn SetShadowOffsetY(&self, value: f64) {
692        self.canvas_state.set_shadow_offset_y(value)
693    }
694
695    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowblur>
696    fn ShadowBlur(&self) -> f64 {
697        self.canvas_state.shadow_blur()
698    }
699
700    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowblur>
701    fn SetShadowBlur(&self, value: f64) {
702        self.canvas_state.set_shadow_blur(value)
703    }
704
705    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowcolor>
706    fn ShadowColor(&self) -> DOMString {
707        self.canvas_state.shadow_color()
708    }
709
710    /// <https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowcolor>
711    fn SetShadowColor(&self, value: DOMString) {
712        self.canvas_state
713            .set_shadow_color(self.canvas.canvas().as_deref(), value)
714    }
715}