pub(crate) struct CanvasState {
ipc_renderer: IpcSender<CanvasMsg>,
canvas_id: CanvasId,
image_key: ImageKey,
size: Cell<Size2D<u64>>,
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>>,
current_default_path: DomRefCell<Path>,
}
Fields§
§ipc_renderer: IpcSender<CanvasMsg>
§canvas_id: CanvasId
§image_key: ImageKey
§size: Cell<Size2D<u64>>
§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>>
§current_default_path: DomRefCell<Path>
Implementations§
Source§impl CanvasState
impl CanvasState
pub(crate) fn new( global: &GlobalScope, size: Size2D<u64>, ) -> Option<CanvasState>
pub(crate) fn image_key(&self) -> ImageKey
pub(crate) fn get_missing_image_urls(&self) -> &DomRefCell<Vec<ServoUrl>>
pub(crate) fn get_canvas_id(&self) -> CanvasId
pub(crate) fn is_paintable(&self) -> bool
pub(crate) fn send_canvas_2d_msg(&self, msg: Canvas2dMsg)
Sourcepub(crate) fn update_rendering(&self, canvas_epoch: Option<Epoch>) -> bool
pub(crate) fn update_rendering(&self, canvas_epoch: Option<Epoch>) -> bool
Updates WR image and blocks on completion
Sourcepub(crate) fn set_bitmap_dimensions(&self, size: Size2D<u64>)
pub(crate) fn set_bitmap_dimensions(&self, size: Size2D<u64>)
pub(crate) fn reset(&self)
pub(crate) fn reset_to_initial_state(&self)
pub(crate) fn reset_bitmap(&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)
Sourcefn is_origin_clean(&self, source: CanvasImageSource<DomTypeHolder>) -> bool
fn is_origin_clean(&self, source: CanvasImageSource<DomTypeHolder>) -> bool
fn fetch_image_data( &self, url: ServoUrl, cors_setting: Option<CorsSettings>, ) -> Option<Snapshot>
fn request_image_from_cache( &self, url: ServoUrl, cors_setting: Option<CorsSettings>, ) -> ImageResponse
Sourcefn draw_image_internal(
&self,
htmlcanvas: Option<&HTMLCanvasElement>,
image: CanvasImageSource<DomTypeHolder>,
sx: f64,
sy: f64,
sw: Option<f64>,
sh: Option<f64>,
dx: f64,
dy: f64,
dw: Option<f64>,
dh: Option<f64>,
) -> ErrorResult
fn draw_image_internal( &self, htmlcanvas: Option<&HTMLCanvasElement>, image: CanvasImageSource<DomTypeHolder>, sx: f64, sy: f64, sw: Option<f64>, sh: Option<f64>, dx: f64, dy: f64, dw: Option<f64>, dh: Option<f64>, ) -> ErrorResult
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
Sourcefn draw_html_image_element(
&self,
image: &HTMLImageElement,
canvas: Option<&HTMLCanvasElement>,
sx: f64,
sy: f64,
sw: Option<f64>,
sh: Option<f64>,
dx: f64,
dy: f64,
dw: Option<f64>,
dh: Option<f64>,
)
fn draw_html_image_element( &self, image: &HTMLImageElement, canvas: Option<&HTMLCanvasElement>, sx: f64, sy: f64, sw: Option<f64>, sh: Option<f64>, dx: f64, dy: f64, dw: Option<f64>, dh: Option<f64>, )
Sourcefn draw_html_video_element(
&self,
video: &HTMLVideoElement,
canvas: Option<&HTMLCanvasElement>,
sx: f64,
sy: f64,
sw: Option<f64>,
sh: Option<f64>,
dx: f64,
dy: f64,
dw: Option<f64>,
dh: Option<f64>,
)
fn draw_html_video_element( &self, video: &HTMLVideoElement, canvas: Option<&HTMLCanvasElement>, sx: f64, sy: f64, sw: Option<f64>, sh: Option<f64>, dx: f64, dy: f64, dw: Option<f64>, dh: Option<f64>, )
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>, ) -> ErrorResult
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>, ) -> ErrorResult
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>, ) -> ErrorResult
Sourcefn draw_image_bitmap(
&self,
bitmap: &ImageBitmap,
canvas: Option<&HTMLCanvasElement>,
sx: f64,
sy: f64,
sw: Option<f64>,
sh: Option<f64>,
dx: f64,
dy: f64,
dw: Option<f64>,
dh: Option<f64>,
)
fn draw_image_bitmap( &self, bitmap: &ImageBitmap, canvas: Option<&HTMLCanvasElement>, sx: f64, sy: f64, sw: Option<f64>, sh: Option<f64>, dx: f64, dy: f64, dw: Option<f64>, dh: Option<f64>, )
pub(crate) fn mark_as_dirty(&self, canvas: Option<&HTMLCanvasElement>)
Sourcefn adjust_source_dest_rects(
&self,
image_size: Size2D<u32>,
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<u32>, 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, transform: Transform2D<f64>)
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, )
pub(crate) fn stroke_style( &self, ) -> StringOrCanvasGradientOrCanvasPattern<DomTypeHolder>
pub(crate) fn set_stroke_style( &self, canvas: Option<&HTMLCanvasElement>, value: StringOrCanvasGradientOrCanvasPattern<DomTypeHolder>, )
pub(crate) fn fill_style( &self, ) -> StringOrCanvasGradientOrCanvasPattern<DomTypeHolder>
pub(crate) fn set_fill_style( &self, canvas: Option<&HTMLCanvasElement>, value: StringOrCanvasGradientOrCanvasPattern<DomTypeHolder>, )
pub(crate) fn create_linear_gradient( &self, global: &GlobalScope, x0: Finite<f64>, y0: Finite<f64>, x1: Finite<f64>, y1: Finite<f64>, can_gc: CanGc, ) -> DomRoot<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>,
can_gc: CanGc,
) -> Fallible<DomRoot<CanvasGradient>>
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>, can_gc: CanGc, ) -> Fallible<DomRoot<CanvasGradient>>
Sourcepub(crate) fn create_pattern(
&self,
global: &GlobalScope,
image: CanvasImageSource<DomTypeHolder>,
repetition: DOMString,
can_gc: CanGc,
) -> Fallible<Option<DomRoot<CanvasPattern>>>
pub(crate) fn create_pattern( &self, global: &GlobalScope, image: CanvasImageSource<DomTypeHolder>, repetition: DOMString, can_gc: CanGc, ) -> Fallible<Option<DomRoot<CanvasPattern>>>
pub(crate) fn save(&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, global_scope: &GlobalScope, canvas: Option<&HTMLCanvasElement>, text: DOMString, x: f64, y: f64, max_width: Option<f64>, )
Sourcepub(crate) fn measure_text(
&self,
global: &GlobalScope,
canvas: Option<&HTMLCanvasElement>,
text: DOMString,
can_gc: CanGc,
) -> DomRoot<TextMetrics>
pub(crate) fn measure_text( &self, global: &GlobalScope, canvas: Option<&HTMLCanvasElement>, text: DOMString, can_gc: CanGc, ) -> DomRoot<TextMetrics>
pub(crate) fn set_font( &self, canvas: Option<&HTMLCanvasElement>, value: DOMString, )
fn font_style(&self) -> ServoArc<Font>
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)
Sourcepub(crate) fn set_line_dash(&self, segments: Vec<f64>)
pub(crate) fn set_line_dash(&self, segments: Vec<f64>)
Sourcepub(crate) fn line_dash_offset(&self) -> f64
pub(crate) fn line_dash_offset(&self) -> f64
Sourcepub(crate) fn set_line_dash_offset(&self, offset: f64)
pub(crate) fn set_line_dash_offset(&self, offset: f64)
<https://html.spec.whatwg.org/multipage/#dom-context-2d-linedashoffset?
pub(crate) fn create_image_data( &self, global: &GlobalScope, sw: i32, sh: i32, can_gc: CanGc, ) -> Fallible<DomRoot<ImageData>>
pub(crate) fn create_image_data_( &self, global: &GlobalScope, imagedata: &ImageData, can_gc: CanGc, ) -> Fallible<DomRoot<ImageData>>
pub(crate) fn get_image_data( &self, canvas_size: Size2D<u32>, global: &GlobalScope, sx: i32, sy: i32, sw: i32, sh: i32, can_gc: CanGc, ) -> Fallible<DomRoot<ImageData>>
pub(crate) fn put_image_data( &self, canvas_size: Size2D<u32>, imagedata: &ImageData, dx: i32, dy: i32, )
Sourcepub(crate) fn put_image_data_(
&self,
canvas_size: Size2D<u32>,
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<u32>, 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<DomTypeHolder>, dx: f64, dy: f64, ) -> ErrorResult
pub(crate) fn draw_image_( &self, canvas: Option<&HTMLCanvasElement>, image: CanvasImageSource<DomTypeHolder>, dx: f64, dy: f64, dw: f64, dh: f64, ) -> ErrorResult
Sourcepub(crate) fn draw_image__(
&self,
canvas: Option<&HTMLCanvasElement>,
image: CanvasImageSource<DomTypeHolder>,
sx: f64,
sy: f64,
sw: f64,
sh: f64,
dx: f64,
dy: f64,
dw: f64,
dh: f64,
) -> ErrorResult
pub(crate) fn draw_image__( &self, canvas: Option<&HTMLCanvasElement>, image: CanvasImageSource<DomTypeHolder>, sx: f64, sy: f64, sw: f64, sh: f64, dx: f64, dy: f64, dw: f64, dh: f64, ) -> ErrorResult
pub(crate) fn begin_path(&self)
pub(crate) fn fill(&self, fill_rule: CanvasFillRule)
pub(crate) fn fill_(&self, path: Path, fill_rule: CanvasFillRule)
pub(crate) fn stroke(&self)
pub(crate) fn stroke_(&self, path: Path)
pub(crate) fn clip(&self, fill_rule: CanvasFillRule)
pub(crate) fn clip_(&self, path: Path, fill_rule: CanvasFillRule)
pub(crate) fn is_point_in_path( &self, global: &GlobalScope, x: f64, y: f64, fill_rule: CanvasFillRule, ) -> bool
pub(crate) fn is_point_in_path_( &self, _global: &GlobalScope, path: Path, 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, ) -> DomRoot<DOMMatrix>
Sourcepub(crate) fn set_transform_(&self, transform: &DOMMatrix2DInit) -> ErrorResult
pub(crate) fn set_transform_(&self, transform: &DOMMatrix2DInit) -> ErrorResult
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, ) -> ErrorResult
pub(crate) fn arc_to( &self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, r: f64, ) -> ErrorResult
Sourcepub(crate) fn ellipse(
&self,
x: f64,
y: f64,
rx: f64,
ry: f64,
rotation: f64,
start: f64,
end: f64,
ccw: bool,
) -> ErrorResult
pub(crate) fn ellipse( &self, x: f64, y: f64, rx: f64, ry: f64, rotation: f64, start: f64, end: f64, ccw: bool, ) -> ErrorResult
fn fill_text_with_size( &self, global_scope: &GlobalScope, text: &str, origin: Point2D<f64>, size: f64, max_width: Option<f64>, )
fn build_unshaped_text_runs<'text>( &self, font_context: &FontContext, text: &'text str, font_group: &mut FontGroup, ) -> Vec<UnshapedTextRun<'text>>
Sourcefn find_anchor_point_for_line_of_text(
&self,
origin: Point2D<f64>,
metrics: &FontMetrics,
width: f64,
) -> Point2D<f64>
fn find_anchor_point_for_line_of_text( &self, origin: Point2D<f64>, metrics: &FontMetrics, width: f64, ) -> Point2D<f64>
Find the anchor_point for the given parameters of a line of text. See https://html.spec.whatwg.org/multipage/#text-preparation-algorithm.
Trait Implementations§
Source§impl Drop for CanvasState
impl Drop for CanvasState
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
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
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>
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>
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>
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