Struct script::canvas_state::CanvasState

source ·
pub(crate) struct CanvasState {
    ipc_renderer: IpcSender<CanvasMsg>,
    canvas_id: CanvasId,
    state: DomRefCell<CanvasContextState>,
    origin_clean: Cell<bool>,
    image_cache: Arc<dyn ImageCache>,
    base_url: ServoUrl,
    origin: ImmutableOrigin,
    missing_image_urls: DomRefCell<Vec<ServoUrl>>,
    saved_states: DomRefCell<Vec<CanvasContextState>>,
}

Fields§

§ipc_renderer: IpcSender<CanvasMsg>§canvas_id: CanvasId§state: DomRefCell<CanvasContextState>§origin_clean: Cell<bool>§image_cache: Arc<dyn ImageCache>§base_url: ServoUrl

The base URL for resolving CSS image URL values. Needed because of https://github.com/servo/servo/issues/17625

§origin: ImmutableOrigin§missing_image_urls: DomRefCell<Vec<ServoUrl>>

Any missing image URLs.

§saved_states: DomRefCell<Vec<CanvasContextState>>

Implementations§

source§

impl CanvasState

source

pub(crate) fn new(global: &GlobalScope, size: Size2D<u64>) -> CanvasState

source

pub fn get_ipc_renderer(&self) -> &IpcSender<CanvasMsg>

source

pub fn get_missing_image_urls(&self) -> &DomRefCell<Vec<ServoUrl>>

source

pub fn get_canvas_id(&self) -> CanvasId

source

pub fn send_canvas_2d_msg(&self, msg: Canvas2dMsg)

source

pub fn set_bitmap_dimensions(&self, size: Size2D<u64>)

source

pub fn reset(&self)

source

pub fn reset_to_initial_state(&self)

source

fn create_drawable_rect( &self, x: f64, y: f64, w: f64, h: f64, ) -> Option<Rect<f32>>

source

pub fn origin_is_clean(&self) -> bool

source

fn set_origin_unclean(&self)

source

fn is_origin_clean(&self, image: CanvasImageSource) -> bool

source

fn fetch_image_data( &self, url: ServoUrl, cors_setting: Option<CorsSettings>, ) -> Option<(IpcSharedMemory, Size2D<u32>)>

source

fn request_image_from_cache( &self, url: ServoUrl, cors_setting: Option<CorsSettings>, ) -> ImageResponse

source

pub fn get_rect(&self, canvas_size: Size2D<u64>, rect: Rect<u64>) -> Vec<u8>

source

fn draw_image_internal( &self, htmlcanvas: Option<&HTMLCanvasElement>, image: CanvasImageSource, sx: f64, sy: f64, sw: Option<f64>, sh: Option<f64>, dx: f64, dy: f64, dw: Option<f64>, dh: Option<f64>, ) -> Result<(), Error>

drawImage coordinates explained

 Source Image      Destination Canvas
+-------------+     +-------------+
|             |     |             |
|(sx,sy)      |     |(dx,dy)      |
|   +----+    |     |   +----+    |
|   |    |    |     |   |    |    |
|   |    |sh  |---->|   |    |dh  |
|   |    |    |     |   |    |    |
|   +----+    |     |   +----+    |
|     sw      |     |     dw      |
|             |     |             |
+-------------+     +-------------+

The rectangle (sx, sy, sw, sh) from the source image is copied on the rectangle (dx, dy, dh, dw) of the destination canvas

https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage

source

fn draw_offscreen_canvas( &self, canvas: &OffscreenCanvas, htmlcanvas: Option<&HTMLCanvasElement>, sx: f64, sy: f64, sw: Option<f64>, sh: Option<f64>, dx: f64, dy: f64, dw: Option<f64>, dh: Option<f64>, ) -> Result<(), Error>

source

fn draw_html_canvas_element( &self, canvas: &HTMLCanvasElement, htmlcanvas: Option<&HTMLCanvasElement>, sx: f64, sy: f64, sw: Option<f64>, sh: Option<f64>, dx: f64, dy: f64, dw: Option<f64>, dh: Option<f64>, ) -> Result<(), Error>

source

fn fetch_and_draw_image_data( &self, canvas: Option<&HTMLCanvasElement>, url: ServoUrl, cors_setting: Option<CorsSettings>, sx: f64, sy: f64, sw: Option<f64>, sh: Option<f64>, dx: f64, dy: f64, dw: Option<f64>, dh: Option<f64>, ) -> Result<(), Error>

source

pub fn mark_as_dirty(&self, canvas: Option<&HTMLCanvasElement>)

source

fn adjust_source_dest_rects( &self, image_size: Size2D<f64>, sx: f64, sy: f64, sw: f64, sh: f64, dx: f64, dy: f64, dw: f64, dh: f64, ) -> (Rect<f64>, Rect<f64>)

It is used by DrawImage to calculate the size of the source and destination rectangles based on the drawImage call arguments source rectangle = area of the original image to be copied destination rectangle = area of the destination canvas where the source image is going to be drawn

source

fn update_transform(&self)

source

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

source

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

source

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

source

pub fn shadow_offset_x(&self) -> f64

source

pub fn set_shadow_offset_x(&self, value: f64)

source

pub fn shadow_offset_y(&self) -> f64

source

pub fn set_shadow_offset_y(&self, value: f64)

source

pub fn shadow_blur(&self) -> f64

source

pub fn set_shadow_blur(&self, value: f64)

source

pub fn shadow_color(&self) -> DOMString

source

pub fn set_shadow_color( &self, canvas: Option<&HTMLCanvasElement>, value: DOMString, can_gc: CanGc, )

source

pub fn stroke_style(&self) -> StringOrCanvasGradientOrCanvasPattern

source

pub fn set_stroke_style( &self, canvas: Option<&HTMLCanvasElement>, value: StringOrCanvasGradientOrCanvasPattern, can_gc: CanGc, )

source

pub fn fill_style(&self) -> StringOrCanvasGradientOrCanvasPattern

source

pub fn set_fill_style( &self, canvas: Option<&HTMLCanvasElement>, value: StringOrCanvasGradientOrCanvasPattern, can_gc: CanGc, )

source

pub fn create_linear_gradient( &self, global: &GlobalScope, x0: Finite<f64>, y0: Finite<f64>, x1: Finite<f64>, y1: Finite<f64>, ) -> Root<Dom<CanvasGradient>>

source

pub fn create_radial_gradient( &self, global: &GlobalScope, x0: Finite<f64>, y0: Finite<f64>, r0: Finite<f64>, x1: Finite<f64>, y1: Finite<f64>, r1: Finite<f64>, ) -> Result<Root<Dom<CanvasGradient>>, Error>

source

pub fn create_pattern( &self, global: &GlobalScope, image: CanvasImageSource, repetition: DOMString, ) -> Result<Option<Root<Dom<CanvasPattern>>>, Error>

source

pub fn save(&self)

source

pub fn restore(&self)

source

pub fn global_alpha(&self) -> f64

source

pub fn set_global_alpha(&self, alpha: f64)

source

pub fn global_composite_operation(&self) -> DOMString

source

pub fn set_global_composite_operation(&self, op_str: DOMString)

source

pub fn image_smoothing_enabled(&self) -> bool

source

pub fn set_image_smoothing_enabled(&self, value: bool)

source

pub fn fill_text( &self, canvas: Option<&HTMLCanvasElement>, text: DOMString, x: f64, y: f64, max_width: Option<f64>, can_gc: CanGc, )

source

pub fn measure_text( &self, global: &GlobalScope, canvas: Option<&HTMLCanvasElement>, text: DOMString, can_gc: CanGc, ) -> Root<Dom<TextMetrics>>

source

pub fn set_font( &self, canvas: Option<&HTMLCanvasElement>, value: DOMString, can_gc: CanGc, )

source

pub fn font(&self) -> DOMString

source

pub fn text_align(&self) -> CanvasTextAlign

source

pub fn set_text_align(&self, value: CanvasTextAlign)

source

pub fn text_baseline(&self) -> CanvasTextBaseline

source

pub fn set_text_baseline(&self, value: CanvasTextBaseline)

source

pub fn direction(&self) -> CanvasDirection

source

pub fn set_direction(&self, value: CanvasDirection)

source

pub fn line_width(&self) -> f64

source

pub fn set_line_width(&self, width: f64)

source

pub fn line_cap(&self) -> CanvasLineCap

source

pub fn set_line_cap(&self, cap: CanvasLineCap)

source

pub fn line_join(&self) -> CanvasLineJoin

source

pub fn set_line_join(&self, join: CanvasLineJoin)

source

pub fn miter_limit(&self) -> f64

source

pub fn set_miter_limit(&self, limit: f64)

source

pub fn create_image_data( &self, global: &GlobalScope, sw: i32, sh: i32, can_gc: CanGc, ) -> Result<Root<Dom<ImageData>>, Error>

source

pub fn create_image_data_( &self, global: &GlobalScope, imagedata: &ImageData, can_gc: CanGc, ) -> Result<Root<Dom<ImageData>>, Error>

source

pub fn get_image_data( &self, canvas_size: Size2D<u64>, global: &GlobalScope, sx: i32, sy: i32, sw: i32, sh: i32, can_gc: CanGc, ) -> Result<Root<Dom<ImageData>>, Error>

source

pub fn put_image_data( &self, canvas_size: Size2D<u64>, imagedata: &ImageData, dx: i32, dy: i32, )

source

pub fn put_image_data_( &self, canvas_size: Size2D<u64>, imagedata: &ImageData, dx: i32, dy: i32, dirty_x: i32, dirty_y: i32, dirty_width: i32, dirty_height: i32, )

source

pub fn draw_image( &self, canvas: Option<&HTMLCanvasElement>, image: CanvasImageSource, dx: f64, dy: f64, ) -> Result<(), Error>

source

pub fn draw_image_( &self, canvas: Option<&HTMLCanvasElement>, image: CanvasImageSource, dx: f64, dy: f64, dw: f64, dh: f64, ) -> Result<(), Error>

source

pub fn draw_image__( &self, canvas: Option<&HTMLCanvasElement>, image: CanvasImageSource, sx: f64, sy: f64, sw: f64, sh: f64, dx: f64, dy: f64, dw: f64, dh: f64, ) -> Result<(), Error>

source

pub fn begin_path(&self)

source

pub fn fill(&self, _fill_rule: CanvasFillRule)

source

pub fn stroke(&self)

source

pub fn clip(&self, _fill_rule: CanvasFillRule)

source

pub fn is_point_in_path( &self, global: &GlobalScope, x: f64, y: f64, fill_rule: CanvasFillRule, ) -> bool

source

pub fn scale(&self, x: f64, y: f64)

source

pub fn rotate(&self, angle: f64)

source

pub fn translate(&self, x: f64, y: f64)

source

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

source

pub fn get_transform( &self, global: &GlobalScope, can_gc: CanGc, ) -> Root<Dom<DOMMatrix>>

source

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

source

pub fn reset_transform(&self)

source

pub fn close_path(&self)

source

pub fn move_to(&self, x: f64, y: f64)

source

pub fn line_to(&self, x: f64, y: f64)

source

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

source

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

source

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

source

pub fn arc( &self, x: f64, y: f64, r: f64, start: f64, end: f64, ccw: bool, ) -> Result<(), Error>

source

pub fn arc_to( &self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, r: f64, ) -> Result<(), Error>

source

pub fn ellipse( &self, x: f64, y: f64, rx: f64, ry: f64, rotation: f64, start: f64, end: f64, ccw: bool, ) -> Result<(), Error>

Trait Implementations§

source§

impl MallocSizeOf for CanvasState

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 Traceable for CanvasState

source§

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

Trace self.

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<T> Downcast<T> for T

source§

fn downcast(&self) -> &T

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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T