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
impl CanvasState
pub(crate) fn new(global: &GlobalScope, size: Size2D<u64>) -> CanvasState
pub(crate) fn get_ipc_renderer(&self) -> &IpcSender<CanvasMsg>
pub(crate) fn get_missing_image_urls(&self) -> &DomRefCell<Vec<ServoUrl>>
pub(crate) fn get_canvas_id(&self) -> CanvasId
pub(crate) fn send_canvas_2d_msg(&self, msg: Canvas2dMsg)
pub(crate) fn set_bitmap_dimensions(&self, size: Size2D<u64>)
pub(crate) fn reset(&self)
pub(crate) fn reset_to_initial_state(&self)
fn create_drawable_rect( &self, x: f64, y: f64, w: f64, h: f64, ) -> Option<Rect<f32>>
pub(crate) fn origin_is_clean(&self) -> bool
fn set_origin_unclean(&self)
fn is_origin_clean(&self, image: CanvasImageSource) -> bool
fn fetch_image_data( &self, url: ServoUrl, cors_setting: Option<CorsSettings>, ) -> Option<(IpcSharedMemory, Size2D<u32>)>
fn request_image_from_cache( &self, url: ServoUrl, cors_setting: Option<CorsSettings>, ) -> ImageResponse
pub(crate) fn get_rect( &self, canvas_size: Size2D<u64>, rect: Rect<u64>, ) -> Vec<u8> ⓘ
sourcefn 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>
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
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>
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>
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>
pub(crate) fn mark_as_dirty(&self, canvas: Option<&HTMLCanvasElement>)
sourcefn 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>)
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
fn update_transform(&self)
pub(crate) fn fill_rect(&self, x: f64, y: f64, width: f64, height: f64)
pub(crate) fn clear_rect(&self, x: f64, y: f64, width: f64, height: f64)
pub(crate) fn stroke_rect(&self, x: f64, y: f64, width: f64, height: f64)
pub(crate) fn shadow_offset_x(&self) -> f64
pub(crate) fn set_shadow_offset_x(&self, value: f64)
pub(crate) fn shadow_offset_y(&self) -> f64
pub(crate) fn set_shadow_offset_y(&self, value: f64)
pub(crate) fn shadow_blur(&self) -> f64
pub(crate) fn set_shadow_blur(&self, value: f64)
pub(crate) fn shadow_color(&self) -> DOMString
pub(crate) fn set_shadow_color( &self, canvas: Option<&HTMLCanvasElement>, value: DOMString, can_gc: CanGc, )
pub(crate) fn stroke_style(&self) -> StringOrCanvasGradientOrCanvasPattern
pub(crate) fn set_stroke_style( &self, canvas: Option<&HTMLCanvasElement>, value: StringOrCanvasGradientOrCanvasPattern, can_gc: CanGc, )
pub(crate) fn fill_style(&self) -> StringOrCanvasGradientOrCanvasPattern
pub(crate) fn set_fill_style( &self, canvas: Option<&HTMLCanvasElement>, value: StringOrCanvasGradientOrCanvasPattern, can_gc: CanGc, )
pub(crate) fn create_linear_gradient( &self, global: &GlobalScope, x0: Finite<f64>, y0: Finite<f64>, x1: Finite<f64>, y1: Finite<f64>, ) -> Root<Dom<CanvasGradient>>
sourcepub(crate) 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>
pub(crate) 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>
pub(crate) fn create_pattern( &self, global: &GlobalScope, image: CanvasImageSource, repetition: DOMString, ) -> Result<Option<Root<Dom<CanvasPattern>>>, Error>
pub(crate) fn save(&self)
pub(crate) fn restore(&self)
pub(crate) fn global_alpha(&self) -> f64
pub(crate) fn set_global_alpha(&self, alpha: f64)
pub(crate) fn global_composite_operation(&self) -> DOMString
pub(crate) fn set_global_composite_operation(&self, op_str: DOMString)
pub(crate) fn image_smoothing_enabled(&self) -> bool
pub(crate) fn set_image_smoothing_enabled(&self, value: bool)
pub(crate) fn fill_text( &self, canvas: Option<&HTMLCanvasElement>, text: DOMString, x: f64, y: f64, max_width: Option<f64>, can_gc: CanGc, )
pub(crate) fn measure_text( &self, global: &GlobalScope, canvas: Option<&HTMLCanvasElement>, text: DOMString, can_gc: CanGc, ) -> Root<Dom<TextMetrics>>
pub(crate) fn set_font( &self, canvas: Option<&HTMLCanvasElement>, value: DOMString, can_gc: CanGc, )
pub(crate) fn font(&self) -> DOMString
pub(crate) fn text_align(&self) -> CanvasTextAlign
pub(crate) fn set_text_align(&self, value: CanvasTextAlign)
pub(crate) fn text_baseline(&self) -> CanvasTextBaseline
pub(crate) fn set_text_baseline(&self, value: CanvasTextBaseline)
pub(crate) fn direction(&self) -> CanvasDirection
pub(crate) fn set_direction(&self, value: CanvasDirection)
pub(crate) fn line_width(&self) -> f64
pub(crate) fn set_line_width(&self, width: f64)
pub(crate) fn line_cap(&self) -> CanvasLineCap
pub(crate) fn set_line_cap(&self, cap: CanvasLineCap)
pub(crate) fn line_join(&self) -> CanvasLineJoin
pub(crate) fn set_line_join(&self, join: CanvasLineJoin)
pub(crate) fn miter_limit(&self) -> f64
pub(crate) fn set_miter_limit(&self, limit: f64)
pub(crate) fn create_image_data( &self, global: &GlobalScope, sw: i32, sh: i32, can_gc: CanGc, ) -> Result<Root<Dom<ImageData>>, Error>
pub(crate) fn create_image_data_( &self, global: &GlobalScope, imagedata: &ImageData, can_gc: CanGc, ) -> Result<Root<Dom<ImageData>>, Error>
pub(crate) 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>
pub(crate) fn put_image_data( &self, canvas_size: Size2D<u64>, imagedata: &ImageData, dx: i32, dy: i32, )
sourcepub(crate) 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,
)
pub(crate) 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, )
pub(crate) fn draw_image( &self, canvas: Option<&HTMLCanvasElement>, image: CanvasImageSource, dx: f64, dy: f64, ) -> Result<(), Error>
pub(crate) fn draw_image_( &self, canvas: Option<&HTMLCanvasElement>, image: CanvasImageSource, dx: f64, dy: f64, dw: f64, dh: f64, ) -> Result<(), Error>
sourcepub(crate) 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>
pub(crate) 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>
pub(crate) fn begin_path(&self)
pub(crate) fn fill(&self, _fill_rule: CanvasFillRule)
pub(crate) fn stroke(&self)
pub(crate) fn clip(&self, _fill_rule: CanvasFillRule)
pub(crate) fn is_point_in_path( &self, global: &GlobalScope, x: f64, y: f64, fill_rule: CanvasFillRule, ) -> bool
pub(crate) fn scale(&self, x: f64, y: f64)
pub(crate) fn rotate(&self, angle: f64)
pub(crate) fn translate(&self, x: f64, y: f64)
pub(crate) fn transform(&self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64)
pub(crate) fn get_transform( &self, global: &GlobalScope, can_gc: CanGc, ) -> Root<Dom<DOMMatrix>>
pub(crate) fn set_transform( &self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64, )
pub(crate) fn reset_transform(&self)
pub(crate) fn close_path(&self)
pub(crate) fn move_to(&self, x: f64, y: f64)
pub(crate) fn line_to(&self, x: f64, y: f64)
pub(crate) fn rect(&self, x: f64, y: f64, width: f64, height: f64)
pub(crate) fn quadratic_curve_to(&self, cpx: f64, cpy: f64, x: f64, y: f64)
pub(crate) fn bezier_curve_to( &self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, x: f64, y: f64, )
pub(crate) fn arc( &self, x: f64, y: f64, r: f64, start: f64, end: f64, ccw: bool, ) -> Result<(), Error>
pub(crate) fn arc_to( &self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, r: f64, ) -> Result<(), Error>
Trait Implementations§
source§impl MallocSizeOf for CanvasState
impl MallocSizeOf for CanvasState
source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
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.
Auto Trait Implementations§
impl !Freeze for CanvasState
impl !RefUnwindSafe for CanvasState
impl !Send for CanvasState
impl !Sync for CanvasState
impl Unpin for CanvasState
impl !UnwindSafe for CanvasState
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Filterable for T
impl<T> Filterable for T
source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
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> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moresource§impl<T> MaybeBoxed<Box<T>> for T
impl<T> MaybeBoxed<Box<T>> for T
source§fn maybe_boxed(self) -> Box<T>
fn maybe_boxed(self) -> Box<T>
Convert
source§impl<T> MaybeBoxed<T> for T
impl<T> MaybeBoxed<T> for T
source§fn maybe_boxed(self) -> T
fn maybe_boxed(self) -> T
Convert