Skip to main content

CanvasRenderingContext2D

Struct CanvasRenderingContext2D 

Source
#[repr(C)]
pub(crate) struct CanvasRenderingContext2D { reflector_: Reflector<AssociatedMemory>, canvas: HTMLCanvasElementOrOffscreenCanvas, canvas_state: CanvasState, }

Fields§

§reflector_: Reflector<AssociatedMemory>§canvas: HTMLCanvasElementOrOffscreenCanvas§canvas_state: CanvasState

Implementations§

Source§

impl CanvasRenderingContext2D

Source§

impl CanvasRenderingContext2D

Source

const RGBA8_BYTES_PER_PIXEL: usize = 4

Source

const ASSOCIATED_MEMORY_BUFFER_COUNT: usize = 4

Ideally this would be two bitmap buffers, unfortunately we currently have ~4 copies which are all retained until GC:

  1. The draw target’s backing bitmap in the canvas paint thread (CanvasData::draw_target, e.g. pixmap in VelloCPUDrawTarget).
  2. Additional backend resources (approximated with 1 bitmap buffer, actually depends on backend): e.g. ctx and resources in VelloCPUDrawTarget for vello_cpu. TODO: #46785 tracks getting accurate statistics from the backend.
  3. CachedImageData::Raw in WebRender (cpu memory copy).
  4. GPU memory in webrender / driver (also lives in RAM on unified memory systems).

This metric is only used to inform the GC about memory pressure, so it doesn’t need to be completely accurate, but undercounting may delay GCs and hence increase memory usage. On mobile devices this slightly undercounts (usually unified memory), on desktop this slightly overcounts, since GPU memory is separate.

Source

fn associated_memory_size(size: Size2D<u64>) -> usize

Source

pub(crate) fn update_associated_memory_size(&self)

Source

pub(crate) fn new_inherited( global: &GlobalScope, canvas: HTMLCanvasElementOrOffscreenCanvas, size: Size2D<u32>, ) -> Option<CanvasRenderingContext2D>

Source

pub(crate) fn new( cx: &mut JSContext, global: &GlobalScope, canvas: &HTMLCanvasElement, size: Size2D<u32>, ) -> Option<DomRoot<CanvasRenderingContext2D>>

Source

pub(crate) fn send_canvas_command_immediate(&self, msg: CanvasCommand)

Source

pub(crate) fn set_image_key(&self, image_key: ImageKey)

Source

pub(crate) fn update_rendering(&self, canvas_epoch: Epoch) -> bool

Trait Implementations§

Source§

impl CanvasContext for CanvasRenderingContext2D

Source§

impl CanvasRenderingContext2DMethods<DomTypeHolder> for CanvasRenderingContext2D

Source§

fn Canvas(&self) -> DomRoot<HTMLCanvasElement>

Source§

fn Save(&self)

Source§

fn Restore(&self)

Source§

fn Reset(&self)

Source§

fn Scale(&self, x: f64, y: f64)

Source§

fn Rotate(&self, angle: f64)

Source§

fn Translate(&self, x: f64, y: f64)

Source§

fn Transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64)

Source§

fn GetTransform(&self, cx: &mut JSContext) -> DomRoot<DOMMatrix>

Source§

fn SetTransform( &self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64, ) -> ErrorResult

Source§

fn SetTransform_(&self, transform: &DOMMatrix2DInit) -> ErrorResult

Source§

fn ResetTransform(&self)

Source§

fn GlobalAlpha(&self) -> f64

Source§

fn SetGlobalAlpha(&self, alpha: f64)

Source§

fn GlobalCompositeOperation(&self) -> DOMString

Source§

fn SetGlobalCompositeOperation(&self, op_str: DOMString)

Source§

fn FillRect(&self, x: f64, y: f64, width: f64, height: f64)

Source§

fn ClearRect(&self, x: f64, y: f64, width: f64, height: f64)

Source§

fn StrokeRect(&self, x: f64, y: f64, width: f64, height: f64)

Source§

fn BeginPath(&self)

Source§

fn ClosePath(&self)

Source§

fn Fill(&self, fill_rule: CanvasFillRule)

Source§

fn Fill_(&self, path: &Path2D, fill_rule: CanvasFillRule)

Source§

fn Stroke(&self)

Source§

fn Stroke_(&self, path: &Path2D)

Source§

fn Clip(&self, fill_rule: CanvasFillRule)

Source§

fn Clip_(&self, path: &Path2D, fill_rule: CanvasFillRule)

Source§

fn IsPointInPath(&self, x: f64, y: f64, fill_rule: CanvasFillRule) -> bool

Source§

fn IsPointInPath_( &self, path: &Path2D, x: f64, y: f64, fill_rule: CanvasFillRule, ) -> bool

Source§

fn FillText(&self, text: DOMString, x: f64, y: f64, max_width: Option<f64>)

Source§

fn StrokeText(&self, text: DOMString, x: f64, y: f64, max_width: Option<f64>)

Source§

fn MeasureText( &self, cx: &mut JSContext, text: DOMString, ) -> DomRoot<TextMetrics>

Source§

fn Font(&self) -> DOMString

Source§

fn SetFont(&self, value: DOMString)

Source§

fn TextAlign(&self) -> CanvasTextAlign

Source§

fn SetTextAlign(&self, value: CanvasTextAlign)

Source§

fn TextBaseline(&self) -> CanvasTextBaseline

Source§

fn SetTextBaseline(&self, value: CanvasTextBaseline)

Source§

fn Direction(&self) -> CanvasDirection

Source§

fn SetDirection(&self, value: CanvasDirection)

Source§

fn DrawImage( &self, image: CanvasImageSource<DomTypeHolder>, dx: f64, dy: f64, ) -> ErrorResult

Source§

fn DrawImage_( &self, image: CanvasImageSource<DomTypeHolder>, dx: f64, dy: f64, dw: f64, dh: f64, ) -> ErrorResult

Source§

fn DrawImage__( &self, image: CanvasImageSource<DomTypeHolder>, sx: f64, sy: f64, sw: f64, sh: f64, dx: f64, dy: f64, dw: f64, dh: f64, ) -> ErrorResult

Source§

fn MoveTo(&self, x: f64, y: f64)

Source§

fn LineTo(&self, x: f64, y: f64)

Source§

fn Rect(&self, x: f64, y: f64, width: f64, height: f64)

Source§

fn QuadraticCurveTo(&self, cpx: f64, cpy: f64, x: f64, y: f64)

Source§

fn BezierCurveTo( &self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, x: f64, y: f64, )

Source§

fn Arc( &self, x: f64, y: f64, r: f64, start: f64, end: f64, ccw: bool, ) -> ErrorResult

Source§

fn ArcTo( &self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, r: f64, ) -> ErrorResult

Source§

fn Ellipse( &self, x: f64, y: f64, rx: f64, ry: f64, rotation: f64, start: f64, end: f64, ccw: bool, ) -> ErrorResult

Source§

fn ImageSmoothingEnabled(&self) -> bool

Source§

fn SetImageSmoothingEnabled(&self, value: bool)

Source§

fn StrokeStyle(&self) -> StringOrCanvasGradientOrCanvasPattern<DomTypeHolder>

Source§

fn SetStrokeStyle( &self, value: StringOrCanvasGradientOrCanvasPattern<DomTypeHolder>, )

Source§

fn FillStyle(&self) -> StringOrCanvasGradientOrCanvasPattern<DomTypeHolder>

Source§

fn SetFillStyle( &self, value: StringOrCanvasGradientOrCanvasPattern<DomTypeHolder>, )

Source§

fn CreateImageData( &self, cx: &mut JSContext, sw: i32, sh: i32, ) -> Fallible<DomRoot<ImageData>>

Source§

fn CreateImageData_( &self, cx: &mut JSContext, imagedata: &ImageData, ) -> Fallible<DomRoot<ImageData>>

Source§

fn GetImageData( &self, cx: &mut JSContext, sx: i32, sy: i32, sw: i32, sh: i32, ) -> Fallible<DomRoot<ImageData>>

Source§

fn PutImageData(&self, no_gc: &NoGC, imagedata: &ImageData, dx: i32, dy: i32)

Source§

fn CreateLinearGradient( &self, cx: &mut JSContext, x0: Finite<f64>, y0: Finite<f64>, x1: Finite<f64>, y1: Finite<f64>, ) -> DomRoot<CanvasGradient>

Source§

fn CreateRadialGradient( &self, cx: &mut JSContext, x0: Finite<f64>, y0: Finite<f64>, r0: Finite<f64>, x1: Finite<f64>, y1: Finite<f64>, r1: Finite<f64>, ) -> Fallible<DomRoot<CanvasGradient>>

Source§

fn CreatePattern( &self, cx: &mut JSContext, image: CanvasImageSource<DomTypeHolder>, repetition: DOMString, ) -> Fallible<Option<DomRoot<CanvasPattern>>>

Source§

fn LineWidth(&self) -> f64

Source§

fn SetLineWidth(&self, width: f64)

Source§

fn LineCap(&self) -> CanvasLineCap

Source§

fn SetLineCap(&self, cap: CanvasLineCap)

Source§

fn LineJoin(&self) -> CanvasLineJoin

Source§

fn SetLineJoin(&self, join: CanvasLineJoin)

Source§

fn MiterLimit(&self) -> f64

Source§

fn SetMiterLimit(&self, limit: f64)

Source§

fn SetLineDash(&self, segments: Vec<f64>)

Source§

fn GetLineDash(&self) -> Vec<f64>

Source§

fn LineDashOffset(&self) -> f64

Source§

fn SetLineDashOffset(&self, offset: f64)

Source§

fn ShadowOffsetX(&self) -> f64

Source§

fn SetShadowOffsetX(&self, value: f64)

Source§

fn ShadowOffsetY(&self) -> f64

Source§

fn SetShadowOffsetY(&self, value: f64)

Source§

fn ShadowBlur(&self) -> f64

Source§

fn SetShadowBlur(&self, value: f64)

Source§

fn ShadowColor(&self) -> DOMString

Source§

fn SetShadowColor(&self, value: DOMString)

Source§

fn PutImageData_( &self, no_gc: &NoGC, imagedata: &ImageData, dx: i32, dy: i32, dirty_x: i32, dirty_y: i32, dirty_width: i32, dirty_height: i32, )

Source§

impl DomObject for CanvasRenderingContext2D

Source§

type ReflectorType = AssociatedMemory

Source§

fn reflector(&self) -> &Reflector<Self::ReflectorType>

Returns the receiver’s reflector.
Source§

impl DomObjectWrap<DomTypeHolder> for CanvasRenderingContext2D

Source§

const WRAP: unsafe fn(&mut JSContext, &GlobalScope, Option<HandleObject<'_>>, Box<Self>) -> Root<Dom<Self>>

Function pointer to the general wrap function type
Source§

impl Drop for CanvasRenderingContext2D

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl HasParent for CanvasRenderingContext2D

Source§

fn as_parent(&self) -> &Reflector<AssociatedMemory>

This is used in a type assertion to ensure that the source and webidls agree as to what the parent type is

Source§

type Parent = Reflector<AssociatedMemory>

Source§

impl IDLInterface for CanvasRenderingContext2D

Source§

const PROTO_FIRST: u16 = 48

First prototype ID in the DFS-ordered range for this interface and its descendants.
Source§

const PROTO_LAST: u16 = 48

Last prototype ID in the DFS-ordered range for this interface and its descendants.
Source§

fn derives(class: &'static DOMClass) -> bool

Returns whether the given DOM class derives that interface.
Source§

impl MallocSizeOf for CanvasRenderingContext2D

Source§

fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize

Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself.
Source§

impl MutDomObject for CanvasRenderingContext2D

Source§

unsafe fn init_reflector<Actual>(&self, obj: *mut JSObject)

Initializes the Reflector Read more
Source§

unsafe fn init_reflector_without_associated_memory(&self, obj: *mut JSObject)

Initializes the Reflector without recording any associated memory usage. Read more
Source§

impl PartialEq for CanvasRenderingContext2D

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToJSValConvertible for CanvasRenderingContext2D

Source§

fn safe_to_jsval(&self, cx: &mut JSContext, rval: MutableHandleValue<'_>)

Convert self to a JSVal. JSAPI failure causes a panic.
Source§

impl Traceable for CanvasRenderingContext2D

Source§

unsafe fn trace(&self, tracer: *mut JSTracer)

Trace self.
Source§

impl Eq for CanvasRenderingContext2D

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<D, T> DomGlobalGeneric<D> for T
where D: DomTypes, T: DomObject,

Source§

fn global_from_reflector(&self) -> Root<Dom<<D as DomTypes>::GlobalScope>>
where Self: Sized,

Returns the [GlobalScope] of the realm that the DomObject was created in. If this object is a Node, this will be different from it’s owning Document if adopted by. For Nodes it’s almost always better to use NodeTraits::owning_global.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> Filterable for T

Source§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ThisReflector for T
where T: DomObject,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,