diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-11-11 14:47:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-11 14:47:56 -0500 |
commit | 905f714bb4b2959f1735cc7469969696eac56d47 (patch) | |
tree | 39073c7c0990269cd976fe0be6da6156b2992065 /components/script/canvas_state.rs | |
parent | 06e58212cbca2ff6b24f0ad6e1e1c01237da480d (diff) | |
parent | ec2961920b74fbe0345f72e6007c6d42ae852019 (diff) | |
download | servo-905f714bb4b2959f1735cc7469969696eac56d47.tar.gz servo-905f714bb4b2959f1735cc7469969696eac56d47.zip |
Auto merge of #24524 - bblanke:consolidate-size-helpers, r=jdm
Make offscreen canvas rendering context use offscreen canvas' size; Consolidate size helpers
<!-- Please describe your changes on the following line: -->
Addresses issues raised in the review of PR #24518 and includes changes to 17 tests' metadata for those that now PASS.
Contains fixes in PR #24518:
Updated the offscreen canvas rendering context to use the offscreen canvas' size. This involved upgrading several methods to accept u64 sizes.
Additionally, the code in OffscreenCanvas::SetWidth() and OffscreenCanvas::SetHeight() was updated to send CanvasMsg::Recreate to the canvas paint thread.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #24465 and fix #24536
<!-- Either: -->
- [X] There are tests for these changes – 17 were updated to PASS
Diffstat (limited to 'components/script/canvas_state.rs')
-rw-r--r-- | components/script/canvas_state.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/components/script/canvas_state.rs b/components/script/canvas_state.rs index 90630fb07c3..4b47308fa46 100644 --- a/components/script/canvas_state.rs +++ b/components/script/canvas_state.rs @@ -24,6 +24,7 @@ use crate::dom::imagedata::ImageData; use crate::dom::node::{Node, NodeDamage}; use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope; use crate::dom::textmetrics::TextMetrics; +use crate::euclidext::Size2DExt; use crate::unpremultiplytable::UNPREMULTIPLY_TABLE; use canvas_traits::canvas::{Canvas2dMsg, CanvasId, CanvasMsg}; use canvas_traits::canvas::{CompositionOrBlending, FillOrStrokeStyle, FillRule}; @@ -180,6 +181,19 @@ impl CanvasState { .unwrap() } + // https://html.spec.whatwg.org/multipage/#concept-canvas-set-bitmap-dimensions + pub fn set_bitmap_dimensions(&self, size: Size2D<u64>) { + self.reset_to_initial_state(); + self.ipc_renderer + .send(CanvasMsg::Recreate(size, self.get_canvas_id())) + .unwrap(); + } + + pub fn reset_to_initial_state(&self) { + self.saved_states.borrow_mut().clear(); + *self.state.borrow_mut() = CanvasContextState::new(); + } + fn create_drawable_rect(&self, x: f64, y: f64, w: f64, h: f64) -> Option<Rect<f32>> { if !([x, y, w, h].iter().all(|val| val.is_finite())) { return None; @@ -300,7 +314,7 @@ impl CanvasState { } } - pub fn get_rect(&self, canvas_size: Size2D<u32>, rect: Rect<u32>) -> Vec<u8> { + pub fn get_rect(&self, canvas_size: Size2D<u64>, rect: Rect<u64>) -> Vec<u8> { assert!(self.origin_is_clean()); assert!(Rect::from_size(canvas_size).contains_rect(&rect)); @@ -1019,7 +1033,7 @@ impl CanvasState { // https://html.spec.whatwg.org/multipage/#dom-context-2d-getimagedata pub fn get_image_data( &self, - canvas_size: Size2D<u32>, + canvas_size: Size2D<u64>, global: &GlobalScope, sx: i32, sy: i32, @@ -1038,7 +1052,7 @@ impl CanvasState { } let (origin, size) = adjust_size_sign(Point2D::new(sx, sy), Size2D::new(sw, sh)); - let read_rect = match pixels::clip(origin, size, canvas_size) { + let read_rect = match pixels::clip(origin, size.to_u64(), canvas_size) { Some(rect) => rect, None => { // All the pixels are outside the canvas surface. @@ -1057,7 +1071,7 @@ impl CanvasState { // https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata pub fn put_image_data( &self, - canvas_size: Size2D<u32>, + canvas_size: Size2D<u64>, imagedata: &ImageData, dx: i32, dy: i32, @@ -1078,7 +1092,7 @@ impl CanvasState { #[allow(unsafe_code)] pub fn put_image_data_( &self, - canvas_size: Size2D<u32>, + canvas_size: Size2D<u64>, imagedata: &ImageData, dx: i32, dy: i32, @@ -1106,7 +1120,7 @@ impl CanvasState { Point2D::new(dirty_x, dirty_y), Size2D::new(dirty_width, dirty_height), ); - let src_rect = match pixels::clip(src_origin, src_size, imagedata_size) { + let src_rect = match pixels::clip(src_origin, src_size.to_u64(), imagedata_size.to_u64()) { Some(rect) => rect, None => return, }; |