mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Format remaining files
This commit is contained in:
parent
bf47f90da6
commit
cb07debcb6
252 changed files with 5944 additions and 3744 deletions
|
@ -39,7 +39,7 @@ impl<'a> CanvasData<'a> {
|
|||
size: Size2D<u32>,
|
||||
webrender_api_sender: webrender_api::RenderApiSender,
|
||||
antialias: AntialiasMode,
|
||||
canvas_id: CanvasId
|
||||
canvas_id: CanvasId,
|
||||
) -> CanvasData<'a> {
|
||||
let draw_target = CanvasData::create(size);
|
||||
let path_builder = draw_target.create_path_builder();
|
||||
|
@ -63,7 +63,7 @@ impl<'a> CanvasData<'a> {
|
|||
image_size: Size2D<f64>,
|
||||
dest_rect: Rect<f64>,
|
||||
source_rect: Rect<f64>,
|
||||
smoothing_enabled: bool
|
||||
smoothing_enabled: bool,
|
||||
) {
|
||||
// We round up the floating pixel values to draw the pixels
|
||||
let source_rect = source_rect.ceil();
|
||||
|
@ -75,14 +75,22 @@ impl<'a> CanvasData<'a> {
|
|||
};
|
||||
|
||||
let writer = |draw_target: &DrawTarget| {
|
||||
write_image(&draw_target, image_data, source_rect.size, dest_rect,
|
||||
smoothing_enabled, self.state.draw_options.composition,
|
||||
self.state.draw_options.alpha);
|
||||
write_image(
|
||||
&draw_target,
|
||||
image_data,
|
||||
source_rect.size,
|
||||
dest_rect,
|
||||
smoothing_enabled,
|
||||
self.state.draw_options.composition,
|
||||
self.state.draw_options.alpha,
|
||||
);
|
||||
};
|
||||
|
||||
if self.need_to_draw_shadow() {
|
||||
let rect = Rect::new(Point2D::new(dest_rect.origin.x as f32, dest_rect.origin.y as f32),
|
||||
Size2D::new(dest_rect.size.width as f32, dest_rect.size.height as f32));
|
||||
let rect = Rect::new(
|
||||
Point2D::new(dest_rect.origin.x as f32, dest_rect.origin.y as f32),
|
||||
Size2D::new(dest_rect.size.width as f32, dest_rect.size.height as f32),
|
||||
);
|
||||
|
||||
self.draw_with_shadow(&rect, writer);
|
||||
} else {
|
||||
|
@ -103,7 +111,10 @@ impl<'a> CanvasData<'a> {
|
|||
}
|
||||
|
||||
pub fn fill_text(&self, text: String, x: f64, y: f64, max_width: Option<f64>) {
|
||||
error!("Unimplemented canvas2d.fillText. Values received: {}, {}, {}, {:?}.", text, x, y, max_width);
|
||||
error!(
|
||||
"Unimplemented canvas2d.fillText. Values received: {}, {}, {}, {:?}.",
|
||||
text, x, y, max_width
|
||||
);
|
||||
}
|
||||
|
||||
pub fn fill_rect(&self, rect: &Rect<f32>) {
|
||||
|
@ -111,7 +122,8 @@ impl<'a> CanvasData<'a> {
|
|||
return; // Paint nothing if gradient size is zero.
|
||||
}
|
||||
|
||||
let draw_rect = Rect::new(rect.origin,
|
||||
let draw_rect = Rect::new(
|
||||
rect.origin,
|
||||
match self.state.fill_style {
|
||||
Pattern::Surface(ref surface) => {
|
||||
let surface_size = surface.size();
|
||||
|
@ -119,21 +131,29 @@ impl<'a> CanvasData<'a> {
|
|||
(true, true) => rect.size,
|
||||
(true, false) => Size2D::new(rect.size.width, surface_size.height as f32),
|
||||
(false, true) => Size2D::new(surface_size.width as f32, rect.size.height),
|
||||
(false, false) => Size2D::new(surface_size.width as f32, surface_size.height as f32),
|
||||
(false, false) => {
|
||||
Size2D::new(surface_size.width as f32, surface_size.height as f32)
|
||||
},
|
||||
}
|
||||
},
|
||||
_ => rect.size,
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if self.need_to_draw_shadow() {
|
||||
self.draw_with_shadow(&draw_rect, |new_draw_target: &DrawTarget| {
|
||||
new_draw_target.fill_rect(&draw_rect, self.state.fill_style.to_pattern_ref(),
|
||||
Some(&self.state.draw_options));
|
||||
new_draw_target.fill_rect(
|
||||
&draw_rect,
|
||||
self.state.fill_style.to_pattern_ref(),
|
||||
Some(&self.state.draw_options),
|
||||
);
|
||||
});
|
||||
} else {
|
||||
self.drawtarget.fill_rect(&draw_rect, self.state.fill_style.to_pattern_ref(),
|
||||
Some(&self.state.draw_options));
|
||||
self.drawtarget.fill_rect(
|
||||
&draw_rect,
|
||||
self.state.fill_style.to_pattern_ref(),
|
||||
Some(&self.state.draw_options),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,27 +168,40 @@ impl<'a> CanvasData<'a> {
|
|||
|
||||
if self.need_to_draw_shadow() {
|
||||
self.draw_with_shadow(&rect, |new_draw_target: &DrawTarget| {
|
||||
new_draw_target.stroke_rect(rect, self.state.stroke_style.to_pattern_ref(),
|
||||
&self.state.stroke_opts, &self.state.draw_options);
|
||||
new_draw_target.stroke_rect(
|
||||
rect,
|
||||
self.state.stroke_style.to_pattern_ref(),
|
||||
&self.state.stroke_opts,
|
||||
&self.state.draw_options,
|
||||
);
|
||||
});
|
||||
} else if rect.size.width == 0. || rect.size.height == 0. {
|
||||
let cap = match self.state.stroke_opts.line_join {
|
||||
JoinStyle::Round => CapStyle::Round,
|
||||
_ => CapStyle::Butt
|
||||
_ => CapStyle::Butt,
|
||||
};
|
||||
|
||||
let stroke_opts =
|
||||
StrokeOptions::new(self.state.stroke_opts.line_width,
|
||||
self.state.stroke_opts.line_join,
|
||||
cap,
|
||||
self.state.stroke_opts.miter_limit,
|
||||
self.state.stroke_opts.mDashPattern);
|
||||
self.drawtarget.stroke_line(rect.origin, rect.bottom_right(),
|
||||
self.state.stroke_style.to_pattern_ref(),
|
||||
&stroke_opts, &self.state.draw_options);
|
||||
let stroke_opts = StrokeOptions::new(
|
||||
self.state.stroke_opts.line_width,
|
||||
self.state.stroke_opts.line_join,
|
||||
cap,
|
||||
self.state.stroke_opts.miter_limit,
|
||||
self.state.stroke_opts.mDashPattern,
|
||||
);
|
||||
self.drawtarget.stroke_line(
|
||||
rect.origin,
|
||||
rect.bottom_right(),
|
||||
self.state.stroke_style.to_pattern_ref(),
|
||||
&stroke_opts,
|
||||
&self.state.draw_options,
|
||||
);
|
||||
} else {
|
||||
self.drawtarget.stroke_rect(rect, self.state.stroke_style.to_pattern_ref(),
|
||||
&self.state.stroke_opts, &self.state.draw_options);
|
||||
self.drawtarget.stroke_rect(
|
||||
rect,
|
||||
self.state.stroke_style.to_pattern_ref(),
|
||||
&self.state.stroke_opts,
|
||||
&self.state.draw_options,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,9 +218,11 @@ impl<'a> CanvasData<'a> {
|
|||
return; // Paint nothing if gradient size is zero.
|
||||
}
|
||||
|
||||
self.drawtarget.fill(&self.path_builder.finish(),
|
||||
self.state.fill_style.to_pattern_ref(),
|
||||
&self.state.draw_options);
|
||||
self.drawtarget.fill(
|
||||
&self.path_builder.finish(),
|
||||
self.state.fill_style.to_pattern_ref(),
|
||||
&self.state.draw_options,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn stroke(&self) {
|
||||
|
@ -195,10 +230,12 @@ impl<'a> CanvasData<'a> {
|
|||
return; // Paint nothing if gradient size is zero.
|
||||
}
|
||||
|
||||
self.drawtarget.stroke(&self.path_builder.finish(),
|
||||
self.state.stroke_style.to_pattern_ref(),
|
||||
&self.state.stroke_opts,
|
||||
&self.state.draw_options);
|
||||
self.drawtarget.stroke(
|
||||
&self.path_builder.finish(),
|
||||
self.state.stroke_style.to_pattern_ref(),
|
||||
&self.state.stroke_opts,
|
||||
&self.state.draw_options,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn clip(&self) {
|
||||
|
@ -210,7 +247,7 @@ impl<'a> CanvasData<'a> {
|
|||
x: f64,
|
||||
y: f64,
|
||||
_fill_rule: FillRule,
|
||||
chan: IpcSender<bool>
|
||||
chan: IpcSender<bool>,
|
||||
) {
|
||||
let path = self.path_builder.finish();
|
||||
let result = path.contains_point(x, y, &self.state.transform);
|
||||
|
@ -227,19 +264,22 @@ impl<'a> CanvasData<'a> {
|
|||
}
|
||||
|
||||
pub fn rect(&self, rect: &Rect<f32>) {
|
||||
self.path_builder.move_to(Point2D::new(rect.origin.x, rect.origin.y));
|
||||
self.path_builder.line_to(Point2D::new(rect.origin.x + rect.size.width, rect.origin.y));
|
||||
self.path_builder.line_to(Point2D::new(rect.origin.x + rect.size.width,
|
||||
rect.origin.y + rect.size.height));
|
||||
self.path_builder.line_to(Point2D::new(rect.origin.x, rect.origin.y + rect.size.height));
|
||||
self.path_builder
|
||||
.move_to(Point2D::new(rect.origin.x, rect.origin.y));
|
||||
self.path_builder
|
||||
.line_to(Point2D::new(rect.origin.x + rect.size.width, rect.origin.y));
|
||||
self.path_builder.line_to(Point2D::new(
|
||||
rect.origin.x + rect.size.width,
|
||||
rect.origin.y + rect.size.height,
|
||||
));
|
||||
self.path_builder.line_to(Point2D::new(
|
||||
rect.origin.x,
|
||||
rect.origin.y + rect.size.height,
|
||||
));
|
||||
self.path_builder.close();
|
||||
}
|
||||
|
||||
pub fn quadratic_curve_to(
|
||||
&self,
|
||||
cp: &Point2D<AzFloat>,
|
||||
endpoint: &Point2D<AzFloat>
|
||||
) {
|
||||
pub fn quadratic_curve_to(&self, cp: &Point2D<AzFloat>, endpoint: &Point2D<AzFloat>) {
|
||||
self.path_builder.quadratic_curve_to(cp, endpoint)
|
||||
}
|
||||
|
||||
|
@ -247,7 +287,7 @@ impl<'a> CanvasData<'a> {
|
|||
&self,
|
||||
cp1: &Point2D<AzFloat>,
|
||||
cp2: &Point2D<AzFloat>,
|
||||
endpoint: &Point2D<AzFloat>
|
||||
endpoint: &Point2D<AzFloat>,
|
||||
) {
|
||||
self.path_builder.bezier_curve_to(cp1, cp2, endpoint)
|
||||
}
|
||||
|
@ -258,17 +298,13 @@ impl<'a> CanvasData<'a> {
|
|||
radius: AzFloat,
|
||||
start_angle: AzFloat,
|
||||
end_angle: AzFloat,
|
||||
ccw: bool
|
||||
ccw: bool,
|
||||
) {
|
||||
self.path_builder.arc(*center, radius, start_angle, end_angle, ccw)
|
||||
self.path_builder
|
||||
.arc(*center, radius, start_angle, end_angle, ccw)
|
||||
}
|
||||
|
||||
pub fn arc_to(
|
||||
&self,
|
||||
cp1: &Point2D<AzFloat>,
|
||||
cp2: &Point2D<AzFloat>,
|
||||
radius: AzFloat
|
||||
) {
|
||||
pub fn arc_to(&self, cp1: &Point2D<AzFloat>, cp2: &Point2D<AzFloat>, radius: AzFloat) {
|
||||
let cp0 = self.path_builder.get_current_point();
|
||||
let cp1 = *cp1;
|
||||
let cp2 = *cp2;
|
||||
|
@ -314,9 +350,17 @@ impl<'a> CanvasData<'a> {
|
|||
let angle_end = (tp2.y - cy).atan2(tp2.x - cx);
|
||||
|
||||
self.line_to(&tp1);
|
||||
if [cx, cy, angle_start, angle_end].iter().all(|x| x.is_finite()) {
|
||||
self.arc(&Point2D::new(cx, cy), radius,
|
||||
angle_start, angle_end, anticlockwise);
|
||||
if [cx, cy, angle_start, angle_end]
|
||||
.iter()
|
||||
.all(|x| x.is_finite())
|
||||
{
|
||||
self.arc(
|
||||
&Point2D::new(cx, cy),
|
||||
radius,
|
||||
angle_start,
|
||||
angle_end,
|
||||
anticlockwise,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,9 +372,17 @@ impl<'a> CanvasData<'a> {
|
|||
rotation_angle: AzFloat,
|
||||
start_angle: AzFloat,
|
||||
end_angle: AzFloat,
|
||||
ccw: bool
|
||||
ccw: bool,
|
||||
) {
|
||||
self.path_builder.ellipse(*center, radius_x, radius_y, rotation_angle, start_angle, end_angle, ccw);
|
||||
self.path_builder.ellipse(
|
||||
*center,
|
||||
radius_x,
|
||||
radius_y,
|
||||
rotation_angle,
|
||||
start_angle,
|
||||
end_angle,
|
||||
ccw,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn set_fill_style(&mut self, style: FillOrStrokeStyle) {
|
||||
|
@ -371,7 +423,9 @@ impl<'a> CanvasData<'a> {
|
|||
}
|
||||
|
||||
pub fn set_global_composition(&mut self, op: CompositionOrBlending) {
|
||||
self.state.draw_options.set_composition_op(op.to_azure_style());
|
||||
self.state
|
||||
.draw_options
|
||||
.set_composition_op(op.to_azure_style());
|
||||
}
|
||||
|
||||
pub fn create(size: Size2D<u32>) -> DrawTarget {
|
||||
|
@ -398,7 +452,13 @@ impl<'a> CanvasData<'a> {
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn send_pixels(&mut self, chan: IpcSender<Option<ByteBuf>>) {
|
||||
let data = unsafe { self.drawtarget.snapshot().get_data_surface().data().to_vec() };
|
||||
let data = unsafe {
|
||||
self.drawtarget
|
||||
.snapshot()
|
||||
.get_data_surface()
|
||||
.data()
|
||||
.to_vec()
|
||||
};
|
||||
chan.send(Some(data.into())).unwrap();
|
||||
}
|
||||
|
||||
|
@ -414,9 +474,9 @@ impl<'a> CanvasData<'a> {
|
|||
is_opaque: false,
|
||||
allow_mipmaps: false,
|
||||
};
|
||||
let data = webrender_api::ImageData::Raw(Arc::new(
|
||||
unsafe { self.drawtarget.snapshot().get_data_surface().data().into() },
|
||||
));
|
||||
let data = webrender_api::ImageData::Raw(Arc::new(unsafe {
|
||||
self.drawtarget.snapshot().get_data_surface().data().into()
|
||||
}));
|
||||
|
||||
let mut txn = webrender_api::Transaction::new();
|
||||
|
||||
|
@ -424,15 +484,17 @@ impl<'a> CanvasData<'a> {
|
|||
Some(image_key) => {
|
||||
debug!("Updating image {:?}.", image_key);
|
||||
txn.update_image(image_key, descriptor, data, None);
|
||||
}
|
||||
},
|
||||
None => {
|
||||
self.image_key = Some(self.webrender_api.generate_image_key());
|
||||
debug!("New image {:?}.", self.image_key);
|
||||
txn.add_image(self.image_key.unwrap(), descriptor, data, None);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
if let Some(image_key) = mem::replace(&mut self.very_old_image_key, self.old_image_key.take()) {
|
||||
if let Some(image_key) =
|
||||
mem::replace(&mut self.very_old_image_key, self.old_image_key.take())
|
||||
{
|
||||
txn.delete_image(image_key);
|
||||
}
|
||||
|
||||
|
@ -449,12 +511,15 @@ impl<'a> CanvasData<'a> {
|
|||
assert_eq!(imagedata.len() % 4, 0);
|
||||
assert_eq!(rect.size.area() as usize, imagedata.len() / 4);
|
||||
pixels::byte_swap_and_premultiply_inplace(&mut imagedata);
|
||||
let source_surface = self.drawtarget.create_source_surface_from_data(
|
||||
&imagedata,
|
||||
rect.size.to_i32(),
|
||||
rect.size.width as i32 * 4,
|
||||
SurfaceFormat::B8G8R8A8,
|
||||
).unwrap();
|
||||
let source_surface = self
|
||||
.drawtarget
|
||||
.create_source_surface_from_data(
|
||||
&imagedata,
|
||||
rect.size.to_i32(),
|
||||
rect.size.width as i32 * 4,
|
||||
SurfaceFormat::B8G8R8A8,
|
||||
)
|
||||
.unwrap();
|
||||
self.drawtarget.copy_surface(
|
||||
source_surface,
|
||||
Rect::from_size(rect.size.to_i32()),
|
||||
|
@ -481,15 +546,19 @@ impl<'a> CanvasData<'a> {
|
|||
// https://html.spec.whatwg.org/multipage/#when-shadows-are-drawn
|
||||
fn need_to_draw_shadow(&self) -> bool {
|
||||
self.state.shadow_color.a != 0.0f32 &&
|
||||
(self.state.shadow_offset_x != 0.0f64 ||
|
||||
self.state.shadow_offset_y != 0.0f64 ||
|
||||
self.state.shadow_blur != 0.0f64)
|
||||
(self.state.shadow_offset_x != 0.0f64 ||
|
||||
self.state.shadow_offset_y != 0.0f64 ||
|
||||
self.state.shadow_blur != 0.0f64)
|
||||
}
|
||||
|
||||
fn create_draw_target_for_shadow(&self, source_rect: &Rect<f32>) -> DrawTarget {
|
||||
let draw_target = self.drawtarget.create_similar_draw_target(&Size2D::new(source_rect.size.width as i32,
|
||||
source_rect.size.height as i32),
|
||||
self.drawtarget.get_format());
|
||||
let draw_target = self.drawtarget.create_similar_draw_target(
|
||||
&Size2D::new(
|
||||
source_rect.size.width as i32,
|
||||
source_rect.size.height as i32,
|
||||
),
|
||||
self.drawtarget.get_format(),
|
||||
);
|
||||
let matrix = Transform2D::identity()
|
||||
.pre_translate(-source_rect.origin.to_vector().cast())
|
||||
.pre_mul(&self.state.transform);
|
||||
|
@ -498,19 +567,26 @@ impl<'a> CanvasData<'a> {
|
|||
}
|
||||
|
||||
fn draw_with_shadow<F>(&self, rect: &Rect<f32>, draw_shadow_source: F)
|
||||
where F: FnOnce(&DrawTarget)
|
||||
where
|
||||
F: FnOnce(&DrawTarget),
|
||||
{
|
||||
let shadow_src_rect = self.state.transform.transform_rect(rect);
|
||||
let new_draw_target = self.create_draw_target_for_shadow(&shadow_src_rect);
|
||||
draw_shadow_source(&new_draw_target);
|
||||
self.drawtarget.draw_surface_with_shadow(new_draw_target.snapshot(),
|
||||
&Point2D::new(shadow_src_rect.origin.x as AzFloat,
|
||||
shadow_src_rect.origin.y as AzFloat),
|
||||
&self.state.shadow_color,
|
||||
&Vector2D::new(self.state.shadow_offset_x as AzFloat,
|
||||
self.state.shadow_offset_y as AzFloat),
|
||||
(self.state.shadow_blur / 2.0f64) as AzFloat,
|
||||
self.state.draw_options.composition);
|
||||
self.drawtarget.draw_surface_with_shadow(
|
||||
new_draw_target.snapshot(),
|
||||
&Point2D::new(
|
||||
shadow_src_rect.origin.x as AzFloat,
|
||||
shadow_src_rect.origin.y as AzFloat,
|
||||
),
|
||||
&self.state.shadow_color,
|
||||
&Vector2D::new(
|
||||
self.state.shadow_offset_x as AzFloat,
|
||||
self.state.shadow_offset_y as AzFloat,
|
||||
),
|
||||
(self.state.shadow_blur / 2.0f64) as AzFloat,
|
||||
self.state.draw_options.composition,
|
||||
);
|
||||
}
|
||||
|
||||
/// It reads image data from the canvas
|
||||
|
@ -519,11 +595,19 @@ impl<'a> CanvasData<'a> {
|
|||
#[allow(unsafe_code)]
|
||||
pub fn read_pixels(&self, read_rect: Rect<u32>, canvas_size: Size2D<u32>) -> Vec<u8> {
|
||||
let canvas_rect = Rect::from_size(canvas_size);
|
||||
if canvas_rect.intersection(&read_rect).map_or(true, |rect| rect.is_empty()) {
|
||||
if canvas_rect
|
||||
.intersection(&read_rect)
|
||||
.map_or(true, |rect| rect.is_empty())
|
||||
{
|
||||
return vec![];
|
||||
}
|
||||
let data_surface = self.drawtarget.snapshot().get_data_surface();
|
||||
pixels::get_rect(unsafe { data_surface.data() }, canvas_size.to_u32(), read_rect.to_u32()).into_owned()
|
||||
pixels::get_rect(
|
||||
unsafe { data_surface.data() },
|
||||
canvas_size.to_u32(),
|
||||
read_rect.to_u32(),
|
||||
)
|
||||
.into_owned()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -562,7 +646,13 @@ impl<'a> CanvasPaintState<'a> {
|
|||
draw_options: DrawOptions::new(1.0, CompositionOp::Over, antialias),
|
||||
fill_style: Pattern::Color(ColorPattern::new(Color::black())),
|
||||
stroke_style: Pattern::Color(ColorPattern::new(Color::black())),
|
||||
stroke_opts: StrokeOptions::new(1.0, JoinStyle::MiterOrBevel, CapStyle::Butt, 10.0, &[]),
|
||||
stroke_opts: StrokeOptions::new(
|
||||
1.0,
|
||||
JoinStyle::MiterOrBevel,
|
||||
CapStyle::Butt,
|
||||
10.0,
|
||||
&[],
|
||||
),
|
||||
transform: Transform2D::identity(),
|
||||
shadow_offset_x: 0.0,
|
||||
shadow_offset_y: 0.0,
|
||||
|
@ -594,10 +684,10 @@ fn write_image(
|
|||
dest_rect: Rect<f64>,
|
||||
smoothing_enabled: bool,
|
||||
composition_op: CompositionOp,
|
||||
global_alpha: f32
|
||||
global_alpha: f32,
|
||||
) {
|
||||
if image_data.is_empty() {
|
||||
return
|
||||
return;
|
||||
}
|
||||
let image_rect = Rect::new(Point2D::zero(), image_size);
|
||||
|
||||
|
@ -612,12 +702,14 @@ fn write_image(
|
|||
};
|
||||
let image_size = image_size.to_i32();
|
||||
|
||||
let source_surface = draw_target.create_source_surface_from_data(
|
||||
&image_data,
|
||||
image_size,
|
||||
image_size.width * 4,
|
||||
SurfaceFormat::B8G8R8A8,
|
||||
).unwrap();
|
||||
let source_surface = draw_target
|
||||
.create_source_surface_from_data(
|
||||
&image_data,
|
||||
image_size,
|
||||
image_size.width * 4,
|
||||
SurfaceFormat::B8G8R8A8,
|
||||
)
|
||||
.unwrap();
|
||||
let draw_surface_options = DrawSurfaceOptions::new(filter, true);
|
||||
let draw_options = DrawOptions::new(global_alpha, composition_op, AntialiasMode::None);
|
||||
draw_target.draw_surface(
|
||||
|
@ -635,8 +727,7 @@ pub trait PointToi32 {
|
|||
|
||||
impl PointToi32 for Point2D<f64> {
|
||||
fn to_i32(&self) -> Point2D<i32> {
|
||||
Point2D::new(self.x.to_i32().unwrap(),
|
||||
self.y.to_i32().unwrap())
|
||||
Point2D::new(self.x.to_i32().unwrap(), self.y.to_i32().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -646,8 +737,7 @@ pub trait SizeToi32 {
|
|||
|
||||
impl SizeToi32 for Size2D<f64> {
|
||||
fn to_i32(&self) -> Size2D<i32> {
|
||||
Size2D::new(self.width.to_i32().unwrap(),
|
||||
self.height.to_i32().unwrap())
|
||||
Size2D::new(self.width.to_i32().unwrap(), self.height.to_i32().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -658,19 +748,24 @@ pub trait RectToi32 {
|
|||
|
||||
impl RectToi32 for Rect<f64> {
|
||||
fn to_i32(&self) -> Rect<i32> {
|
||||
Rect::new(Point2D::new(self.origin.x.to_i32().unwrap(),
|
||||
self.origin.y.to_i32().unwrap()),
|
||||
Size2D::new(self.size.width.to_i32().unwrap(),
|
||||
self.size.height.to_i32().unwrap()))
|
||||
Rect::new(
|
||||
Point2D::new(
|
||||
self.origin.x.to_i32().unwrap(),
|
||||
self.origin.y.to_i32().unwrap(),
|
||||
),
|
||||
Size2D::new(
|
||||
self.size.width.to_i32().unwrap(),
|
||||
self.size.height.to_i32().unwrap(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fn ceil(&self) -> Rect<f64> {
|
||||
Rect::new(Point2D::new(self.origin.x.ceil(),
|
||||
self.origin.y.ceil()),
|
||||
Size2D::new(self.size.width.ceil(),
|
||||
self.size.height.ceil()))
|
||||
Rect::new(
|
||||
Point2D::new(self.origin.x.ceil(), self.origin.y.ceil()),
|
||||
Size2D::new(self.size.width.ceil(), self.size.height.ceil()),
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub trait ToAzureStyle {
|
||||
|
@ -682,12 +777,13 @@ impl ToAzureStyle for Rect<f64> {
|
|||
type Target = Rect<AzFloat>;
|
||||
|
||||
fn to_azure_style(self) -> Rect<AzFloat> {
|
||||
Rect::new(Point2D::new(self.origin.x as AzFloat, self.origin.y as AzFloat),
|
||||
Size2D::new(self.size.width as AzFloat, self.size.height as AzFloat))
|
||||
Rect::new(
|
||||
Point2D::new(self.origin.x as AzFloat, self.origin.y as AzFloat),
|
||||
Size2D::new(self.size.width as AzFloat, self.size.height as AzFloat),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl ToAzureStyle for LineCapStyle {
|
||||
type Target = CapStyle;
|
||||
|
||||
|
@ -717,17 +813,17 @@ impl ToAzureStyle for CompositionStyle {
|
|||
|
||||
fn to_azure_style(self) -> CompositionOp {
|
||||
match self {
|
||||
CompositionStyle::SrcIn => CompositionOp::In,
|
||||
CompositionStyle::SrcOut => CompositionOp::Out,
|
||||
CompositionStyle::SrcOver => CompositionOp::Over,
|
||||
CompositionStyle::SrcAtop => CompositionOp::Atop,
|
||||
CompositionStyle::DestIn => CompositionOp::DestIn,
|
||||
CompositionStyle::DestOut => CompositionOp::DestOut,
|
||||
CompositionStyle::SrcIn => CompositionOp::In,
|
||||
CompositionStyle::SrcOut => CompositionOp::Out,
|
||||
CompositionStyle::SrcOver => CompositionOp::Over,
|
||||
CompositionStyle::SrcAtop => CompositionOp::Atop,
|
||||
CompositionStyle::DestIn => CompositionOp::DestIn,
|
||||
CompositionStyle::DestOut => CompositionOp::DestOut,
|
||||
CompositionStyle::DestOver => CompositionOp::DestOver,
|
||||
CompositionStyle::DestAtop => CompositionOp::DestAtop,
|
||||
CompositionStyle::Copy => CompositionOp::Source,
|
||||
CompositionStyle::Lighter => CompositionOp::Add,
|
||||
CompositionStyle::Xor => CompositionOp::Xor,
|
||||
CompositionStyle::Copy => CompositionOp::Source,
|
||||
CompositionStyle::Lighter => CompositionOp::Add,
|
||||
CompositionStyle::Xor => CompositionOp::Xor,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -737,20 +833,20 @@ impl ToAzureStyle for BlendingStyle {
|
|||
|
||||
fn to_azure_style(self) -> CompositionOp {
|
||||
match self {
|
||||
BlendingStyle::Multiply => CompositionOp::Multiply,
|
||||
BlendingStyle::Screen => CompositionOp::Screen,
|
||||
BlendingStyle::Overlay => CompositionOp::Overlay,
|
||||
BlendingStyle::Darken => CompositionOp::Darken,
|
||||
BlendingStyle::Lighten => CompositionOp::Lighten,
|
||||
BlendingStyle::Multiply => CompositionOp::Multiply,
|
||||
BlendingStyle::Screen => CompositionOp::Screen,
|
||||
BlendingStyle::Overlay => CompositionOp::Overlay,
|
||||
BlendingStyle::Darken => CompositionOp::Darken,
|
||||
BlendingStyle::Lighten => CompositionOp::Lighten,
|
||||
BlendingStyle::ColorDodge => CompositionOp::ColorDodge,
|
||||
BlendingStyle::ColorBurn => CompositionOp::ColorBurn,
|
||||
BlendingStyle::HardLight => CompositionOp::HardLight,
|
||||
BlendingStyle::SoftLight => CompositionOp::SoftLight,
|
||||
BlendingStyle::ColorBurn => CompositionOp::ColorBurn,
|
||||
BlendingStyle::HardLight => CompositionOp::HardLight,
|
||||
BlendingStyle::SoftLight => CompositionOp::SoftLight,
|
||||
BlendingStyle::Difference => CompositionOp::Difference,
|
||||
BlendingStyle::Exclusion => CompositionOp::Exclusion,
|
||||
BlendingStyle::Hue => CompositionOp::Hue,
|
||||
BlendingStyle::Exclusion => CompositionOp::Exclusion,
|
||||
BlendingStyle::Hue => CompositionOp::Hue,
|
||||
BlendingStyle::Saturation => CompositionOp::Saturation,
|
||||
BlendingStyle::Color => CompositionOp::Color,
|
||||
BlendingStyle::Color => CompositionOp::Color,
|
||||
BlendingStyle::Luminosity => CompositionOp::Luminosity,
|
||||
}
|
||||
}
|
||||
|
@ -778,32 +874,49 @@ impl ToAzurePattern for FillOrStrokeStyle {
|
|||
Pattern::Color(ColorPattern::new(color.to_azure_style()))
|
||||
},
|
||||
FillOrStrokeStyle::LinearGradient(ref linear_gradient_style) => {
|
||||
let gradient_stops: Vec<GradientStop> = linear_gradient_style.stops.iter().map(|s| {
|
||||
GradientStop {
|
||||
let gradient_stops: Vec<GradientStop> = linear_gradient_style
|
||||
.stops
|
||||
.iter()
|
||||
.map(|s| GradientStop {
|
||||
offset: s.offset as AzFloat,
|
||||
color: s.color.to_azure_style()
|
||||
}
|
||||
}).collect();
|
||||
color: s.color.to_azure_style(),
|
||||
})
|
||||
.collect();
|
||||
|
||||
Pattern::LinearGradient(LinearGradientPattern::new(
|
||||
&Point2D::new(linear_gradient_style.x0 as AzFloat, linear_gradient_style.y0 as AzFloat),
|
||||
&Point2D::new(linear_gradient_style.x1 as AzFloat, linear_gradient_style.y1 as AzFloat),
|
||||
&Point2D::new(
|
||||
linear_gradient_style.x0 as AzFloat,
|
||||
linear_gradient_style.y0 as AzFloat,
|
||||
),
|
||||
&Point2D::new(
|
||||
linear_gradient_style.x1 as AzFloat,
|
||||
linear_gradient_style.y1 as AzFloat,
|
||||
),
|
||||
drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp),
|
||||
&Transform2D::identity(),
|
||||
))
|
||||
},
|
||||
FillOrStrokeStyle::RadialGradient(ref radial_gradient_style) => {
|
||||
let gradient_stops: Vec<GradientStop> = radial_gradient_style.stops.iter().map(|s| {
|
||||
GradientStop {
|
||||
let gradient_stops: Vec<GradientStop> = radial_gradient_style
|
||||
.stops
|
||||
.iter()
|
||||
.map(|s| GradientStop {
|
||||
offset: s.offset as AzFloat,
|
||||
color: s.color.to_azure_style()
|
||||
}
|
||||
}).collect();
|
||||
color: s.color.to_azure_style(),
|
||||
})
|
||||
.collect();
|
||||
|
||||
Pattern::RadialGradient(RadialGradientPattern::new(
|
||||
&Point2D::new(radial_gradient_style.x0 as AzFloat, radial_gradient_style.y0 as AzFloat),
|
||||
&Point2D::new(radial_gradient_style.x1 as AzFloat, radial_gradient_style.y1 as AzFloat),
|
||||
radial_gradient_style.r0 as AzFloat, radial_gradient_style.r1 as AzFloat,
|
||||
&Point2D::new(
|
||||
radial_gradient_style.x0 as AzFloat,
|
||||
radial_gradient_style.y0 as AzFloat,
|
||||
),
|
||||
&Point2D::new(
|
||||
radial_gradient_style.x1 as AzFloat,
|
||||
radial_gradient_style.y1 as AzFloat,
|
||||
),
|
||||
radial_gradient_style.r0 as AzFloat,
|
||||
radial_gradient_style.r1 as AzFloat,
|
||||
drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp),
|
||||
&Transform2D::identity(),
|
||||
))
|
||||
|
@ -822,7 +935,7 @@ impl ToAzurePattern for FillOrStrokeStyle {
|
|||
surface_style.repeat_y,
|
||||
&Transform2D::identity(),
|
||||
))
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -831,9 +944,11 @@ impl ToAzureStyle for RGBA {
|
|||
type Target = Color;
|
||||
|
||||
fn to_azure_style(self) -> Color {
|
||||
Color::rgba(self.red_f32() as AzFloat,
|
||||
self.green_f32() as AzFloat,
|
||||
self.blue_f32() as AzFloat,
|
||||
self.alpha_f32() as AzFloat)
|
||||
Color::rgba(
|
||||
self.red_f32() as AzFloat,
|
||||
self.green_f32() as AzFloat,
|
||||
self.blue_f32() as AzFloat,
|
||||
self.alpha_f32() as AzFloat,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,13 +12,13 @@ use std::collections::HashMap;
|
|||
use std::thread;
|
||||
use webrender_api;
|
||||
|
||||
pub struct CanvasPaintThread <'a> {
|
||||
pub struct CanvasPaintThread<'a> {
|
||||
canvases: HashMap<CanvasId, CanvasData<'a>>,
|
||||
next_canvas_id: CanvasId,
|
||||
}
|
||||
|
||||
impl<'a> CanvasPaintThread <'a> {
|
||||
fn new() -> CanvasPaintThread <'a> {
|
||||
impl<'a> CanvasPaintThread<'a> {
|
||||
fn new() -> CanvasPaintThread<'a> {
|
||||
CanvasPaintThread {
|
||||
canvases: HashMap::new(),
|
||||
next_canvas_id: CanvasId(0),
|
||||
|
@ -29,52 +29,49 @@ impl<'a> CanvasPaintThread <'a> {
|
|||
/// communicate with it.
|
||||
pub fn start() -> IpcSender<CanvasMsg> {
|
||||
let (sender, receiver) = ipc::channel::<CanvasMsg>().unwrap();
|
||||
thread::Builder::new().name("CanvasThread".to_owned()).spawn(move || {
|
||||
let mut canvas_paint_thread = CanvasPaintThread::new();
|
||||
loop {
|
||||
match receiver.recv() {
|
||||
Ok(msg) => {
|
||||
match msg {
|
||||
thread::Builder::new()
|
||||
.name("CanvasThread".to_owned())
|
||||
.spawn(move || {
|
||||
let mut canvas_paint_thread = CanvasPaintThread::new();
|
||||
loop {
|
||||
match receiver.recv() {
|
||||
Ok(msg) => match msg {
|
||||
CanvasMsg::Canvas2d(message, canvas_id) => {
|
||||
canvas_paint_thread.process_canvas_2d_message(message, canvas_id);
|
||||
},
|
||||
CanvasMsg::Close(canvas_id) =>{
|
||||
CanvasMsg::Close(canvas_id) => {
|
||||
canvas_paint_thread.canvases.remove(&canvas_id);
|
||||
},
|
||||
CanvasMsg::Create(creator, size, webrenderer_api_sender, antialias) => {
|
||||
let canvas_id = canvas_paint_thread.create_canvas(
|
||||
size,
|
||||
webrenderer_api_sender,
|
||||
antialias
|
||||
antialias,
|
||||
);
|
||||
creator.send(canvas_id).unwrap();
|
||||
},
|
||||
CanvasMsg::Recreate(size, canvas_id) =>{
|
||||
CanvasMsg::Recreate(size, canvas_id) => {
|
||||
canvas_paint_thread.canvas(canvas_id).recreate(size);
|
||||
},
|
||||
CanvasMsg::FromScript(message, canvas_id) => {
|
||||
match message {
|
||||
FromScriptMsg::SendPixels(chan) => {
|
||||
canvas_paint_thread.canvas(canvas_id).send_pixels(chan);
|
||||
}
|
||||
}
|
||||
CanvasMsg::FromScript(message, canvas_id) => match message {
|
||||
FromScriptMsg::SendPixels(chan) => {
|
||||
canvas_paint_thread.canvas(canvas_id).send_pixels(chan);
|
||||
},
|
||||
},
|
||||
CanvasMsg::FromLayout(message, canvas_id) => {
|
||||
match message {
|
||||
FromLayoutMsg::SendData(chan) => {
|
||||
canvas_paint_thread.canvas(canvas_id).send_data(chan);
|
||||
}
|
||||
}
|
||||
CanvasMsg::FromLayout(message, canvas_id) => match message {
|
||||
FromLayoutMsg::SendData(chan) => {
|
||||
canvas_paint_thread.canvas(canvas_id).send_data(chan);
|
||||
},
|
||||
},
|
||||
CanvasMsg::Exit => break,
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
warn!("Error on CanvasPaintThread receive ({})", e);
|
||||
},
|
||||
Err(e) => {
|
||||
warn!("Error on CanvasPaintThread receive ({})", e);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}).expect("Thread spawning failed");
|
||||
})
|
||||
.expect("Thread spawning failed");
|
||||
|
||||
sender
|
||||
}
|
||||
|
@ -83,7 +80,7 @@ impl<'a> CanvasPaintThread <'a> {
|
|||
&mut self,
|
||||
size: Size2D<u32>,
|
||||
webrender_api_sender: webrender_api::RenderApiSender,
|
||||
antialias: bool
|
||||
antialias: bool,
|
||||
) -> CanvasId {
|
||||
let antialias = if antialias {
|
||||
AntialiasMode::Default
|
||||
|
@ -105,33 +102,17 @@ impl<'a> CanvasPaintThread <'a> {
|
|||
Canvas2dMsg::FillText(text, x, y, max_width) => {
|
||||
self.canvas(canvas_id).fill_text(text, x, y, max_width)
|
||||
},
|
||||
Canvas2dMsg::FillRect(ref rect) => {
|
||||
self.canvas(canvas_id).fill_rect(rect)
|
||||
},
|
||||
Canvas2dMsg::StrokeRect(ref rect) => {
|
||||
self.canvas(canvas_id).stroke_rect(rect)
|
||||
},
|
||||
Canvas2dMsg::ClearRect(ref rect) => {
|
||||
self.canvas(canvas_id).clear_rect(rect)
|
||||
},
|
||||
Canvas2dMsg::BeginPath => {
|
||||
self.canvas(canvas_id).begin_path()
|
||||
},
|
||||
Canvas2dMsg::ClosePath => {
|
||||
self.canvas(canvas_id).close_path()
|
||||
},
|
||||
Canvas2dMsg::Fill => {
|
||||
self.canvas(canvas_id).fill()
|
||||
},
|
||||
Canvas2dMsg::Stroke => {
|
||||
self.canvas(canvas_id).stroke()
|
||||
},
|
||||
Canvas2dMsg::Clip => {
|
||||
self.canvas(canvas_id).clip()
|
||||
},
|
||||
Canvas2dMsg::IsPointInPath(x, y, fill_rule, chan) => {
|
||||
self.canvas(canvas_id).is_point_in_path(x, y, fill_rule, chan)
|
||||
},
|
||||
Canvas2dMsg::FillRect(ref rect) => self.canvas(canvas_id).fill_rect(rect),
|
||||
Canvas2dMsg::StrokeRect(ref rect) => self.canvas(canvas_id).stroke_rect(rect),
|
||||
Canvas2dMsg::ClearRect(ref rect) => self.canvas(canvas_id).clear_rect(rect),
|
||||
Canvas2dMsg::BeginPath => self.canvas(canvas_id).begin_path(),
|
||||
Canvas2dMsg::ClosePath => self.canvas(canvas_id).close_path(),
|
||||
Canvas2dMsg::Fill => self.canvas(canvas_id).fill(),
|
||||
Canvas2dMsg::Stroke => self.canvas(canvas_id).stroke(),
|
||||
Canvas2dMsg::Clip => self.canvas(canvas_id).clip(),
|
||||
Canvas2dMsg::IsPointInPath(x, y, fill_rule, chan) => self
|
||||
.canvas(canvas_id)
|
||||
.is_point_in_path(x, y, fill_rule, chan),
|
||||
Canvas2dMsg::DrawImage(
|
||||
imagedata,
|
||||
image_size,
|
||||
|
@ -156,12 +137,11 @@ impl<'a> CanvasPaintThread <'a> {
|
|||
image_size,
|
||||
dest_rect,
|
||||
source_rect,
|
||||
smoothing
|
||||
smoothing,
|
||||
) => {
|
||||
let image_data = self.canvas(canvas_id).read_pixels(
|
||||
source_rect.to_u32(),
|
||||
image_size.to_u32(),
|
||||
);
|
||||
let image_data = self
|
||||
.canvas(canvas_id)
|
||||
.read_pixels(source_rect.to_u32(), image_size.to_u32());
|
||||
self.canvas(other_canvas_id).draw_image(
|
||||
image_data.into(),
|
||||
source_rect.size,
|
||||
|
@ -170,68 +150,34 @@ impl<'a> CanvasPaintThread <'a> {
|
|||
smoothing,
|
||||
);
|
||||
},
|
||||
Canvas2dMsg::MoveTo(ref point) => {
|
||||
self.canvas(canvas_id).move_to(point)
|
||||
},
|
||||
Canvas2dMsg::LineTo(ref point) => {
|
||||
self.canvas(canvas_id).line_to(point)
|
||||
},
|
||||
Canvas2dMsg::Rect(ref rect) => {
|
||||
self.canvas(canvas_id).rect(rect)
|
||||
},
|
||||
Canvas2dMsg::MoveTo(ref point) => self.canvas(canvas_id).move_to(point),
|
||||
Canvas2dMsg::LineTo(ref point) => self.canvas(canvas_id).line_to(point),
|
||||
Canvas2dMsg::Rect(ref rect) => self.canvas(canvas_id).rect(rect),
|
||||
Canvas2dMsg::QuadraticCurveTo(ref cp, ref pt) => {
|
||||
self.canvas(canvas_id).quadratic_curve_to(cp, pt)
|
||||
}
|
||||
self.canvas(canvas_id).quadratic_curve_to(cp, pt)
|
||||
},
|
||||
Canvas2dMsg::BezierCurveTo(ref cp1, ref cp2, ref pt) => {
|
||||
self.canvas(canvas_id).bezier_curve_to(cp1, cp2, pt)
|
||||
}
|
||||
self.canvas(canvas_id).bezier_curve_to(cp1, cp2, pt)
|
||||
},
|
||||
Canvas2dMsg::Arc(ref center, radius, start, end, ccw) => {
|
||||
self.canvas(canvas_id).arc(center, radius, start, end, ccw)
|
||||
}
|
||||
self.canvas(canvas_id).arc(center, radius, start, end, ccw)
|
||||
},
|
||||
Canvas2dMsg::ArcTo(ref cp1, ref cp2, radius) => {
|
||||
self.canvas(canvas_id).arc_to(cp1, cp2, radius)
|
||||
}
|
||||
Canvas2dMsg::Ellipse(ref center, radius_x, radius_y, rotation, start, end, ccw) => {
|
||||
self.canvas(canvas_id).ellipse(
|
||||
center,
|
||||
radius_x,
|
||||
radius_y,
|
||||
rotation,
|
||||
start,
|
||||
end,
|
||||
ccw
|
||||
)
|
||||
}
|
||||
Canvas2dMsg::RestoreContext => {
|
||||
self.canvas(canvas_id).restore_context_state()
|
||||
},
|
||||
Canvas2dMsg::SaveContext => {
|
||||
self.canvas(canvas_id).save_context_state()
|
||||
},
|
||||
Canvas2dMsg::SetFillStyle(style) => {
|
||||
self.canvas(canvas_id).set_fill_style(style)
|
||||
},
|
||||
Canvas2dMsg::SetStrokeStyle(style) => {
|
||||
self.canvas(canvas_id).set_stroke_style(style)
|
||||
},
|
||||
Canvas2dMsg::SetLineWidth(width) => {
|
||||
self.canvas(canvas_id).set_line_width(width)
|
||||
},
|
||||
Canvas2dMsg::SetLineCap(cap) => {
|
||||
self.canvas(canvas_id).set_line_cap(cap)
|
||||
},
|
||||
Canvas2dMsg::SetLineJoin(join) => {
|
||||
self.canvas(canvas_id).set_line_join(join)
|
||||
},
|
||||
Canvas2dMsg::SetMiterLimit(limit) => {
|
||||
self.canvas(canvas_id).set_miter_limit(limit)
|
||||
},
|
||||
Canvas2dMsg::SetTransform(ref matrix) => {
|
||||
self.canvas(canvas_id).set_transform(matrix)
|
||||
},
|
||||
Canvas2dMsg::SetGlobalAlpha(alpha) => {
|
||||
self.canvas(canvas_id).set_global_alpha(alpha)
|
||||
},
|
||||
Canvas2dMsg::Ellipse(ref center, radius_x, radius_y, rotation, start, end, ccw) => self
|
||||
.canvas(canvas_id)
|
||||
.ellipse(center, radius_x, radius_y, rotation, start, end, ccw),
|
||||
Canvas2dMsg::RestoreContext => self.canvas(canvas_id).restore_context_state(),
|
||||
Canvas2dMsg::SaveContext => self.canvas(canvas_id).save_context_state(),
|
||||
Canvas2dMsg::SetFillStyle(style) => self.canvas(canvas_id).set_fill_style(style),
|
||||
Canvas2dMsg::SetStrokeStyle(style) => self.canvas(canvas_id).set_stroke_style(style),
|
||||
Canvas2dMsg::SetLineWidth(width) => self.canvas(canvas_id).set_line_width(width),
|
||||
Canvas2dMsg::SetLineCap(cap) => self.canvas(canvas_id).set_line_cap(cap),
|
||||
Canvas2dMsg::SetLineJoin(join) => self.canvas(canvas_id).set_line_join(join),
|
||||
Canvas2dMsg::SetMiterLimit(limit) => self.canvas(canvas_id).set_miter_limit(limit),
|
||||
Canvas2dMsg::SetTransform(ref matrix) => self.canvas(canvas_id).set_transform(matrix),
|
||||
Canvas2dMsg::SetGlobalAlpha(alpha) => self.canvas(canvas_id).set_global_alpha(alpha),
|
||||
Canvas2dMsg::SetGlobalComposition(op) => {
|
||||
self.canvas(canvas_id).set_global_composition(op)
|
||||
},
|
||||
|
@ -240,7 +186,8 @@ impl<'a> CanvasPaintThread <'a> {
|
|||
sender.send(&pixels).unwrap();
|
||||
},
|
||||
Canvas2dMsg::PutImageData(rect, receiver) => {
|
||||
self.canvas(canvas_id).put_image_data(receiver.recv().unwrap(), rect);
|
||||
self.canvas(canvas_id)
|
||||
.put_image_data(receiver.recv().unwrap(), rect);
|
||||
},
|
||||
Canvas2dMsg::SetShadowOffsetX(value) => {
|
||||
self.canvas(canvas_id).set_shadow_offset_x(value)
|
||||
|
@ -248,12 +195,10 @@ impl<'a> CanvasPaintThread <'a> {
|
|||
Canvas2dMsg::SetShadowOffsetY(value) => {
|
||||
self.canvas(canvas_id).set_shadow_offset_y(value)
|
||||
},
|
||||
Canvas2dMsg::SetShadowBlur(value) => {
|
||||
self.canvas(canvas_id).set_shadow_blur(value)
|
||||
},
|
||||
Canvas2dMsg::SetShadowColor(ref color) => {
|
||||
self.canvas(canvas_id).set_shadow_color(color.to_azure_style())
|
||||
},
|
||||
Canvas2dMsg::SetShadowBlur(value) => self.canvas(canvas_id).set_shadow_blur(value),
|
||||
Canvas2dMsg::SetShadowColor(ref color) => self
|
||||
.canvas(canvas_id)
|
||||
.set_shadow_color(color.to_azure_style()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ impl GLContextFactory {
|
|||
&self,
|
||||
webgl_version: WebGLVersion,
|
||||
size: Size2D<u32>,
|
||||
attributes: GLContextAttributes
|
||||
attributes: GLContextAttributes,
|
||||
) -> Result<GLContextWrapper, &'static str> {
|
||||
Ok(match *self {
|
||||
GLContextFactory::Native(ref handle, ref dispatcher) => {
|
||||
|
@ -63,7 +63,7 @@ impl GLContextFactory {
|
|||
Some(handle),
|
||||
dispatcher,
|
||||
)?)
|
||||
}
|
||||
},
|
||||
GLContextFactory::OSMesa(ref handle) => {
|
||||
GLContextWrapper::OSMesa(GLContext::new_shared_with_dispatcher(
|
||||
// FIXME(nox): Why are those i32 values?
|
||||
|
@ -75,7 +75,7 @@ impl GLContextFactory {
|
|||
Some(handle),
|
||||
None,
|
||||
)?)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ impl GLContextFactory {
|
|||
&self,
|
||||
webgl_version: WebGLVersion,
|
||||
size: Size2D<u32>,
|
||||
attributes: GLContextAttributes
|
||||
attributes: GLContextAttributes,
|
||||
) -> Result<GLContextWrapper, &'static str> {
|
||||
Ok(match *self {
|
||||
GLContextFactory::Native(..) => {
|
||||
|
@ -98,7 +98,7 @@ impl GLContextFactory {
|
|||
None,
|
||||
None,
|
||||
)?)
|
||||
}
|
||||
},
|
||||
GLContextFactory::OSMesa(_) => {
|
||||
GLContextWrapper::OSMesa(GLContext::new_shared_with_dispatcher(
|
||||
// FIXME(nox): Why are those i32 values?
|
||||
|
@ -110,7 +110,7 @@ impl GLContextFactory {
|
|||
None,
|
||||
None,
|
||||
)?)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,6 @@ impl GLContextFactory {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// GLContextWrapper used to abstract NativeGLContext and OSMesaContext types
|
||||
pub enum GLContextWrapper {
|
||||
Native(GLContext<NativeGLContext>),
|
||||
|
@ -134,10 +133,10 @@ impl GLContextWrapper {
|
|||
match *self {
|
||||
GLContextWrapper::Native(ref ctx) => {
|
||||
ctx.make_current().unwrap();
|
||||
}
|
||||
},
|
||||
GLContextWrapper::OSMesa(ref ctx) => {
|
||||
ctx.make_current().unwrap();
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,10 +144,10 @@ impl GLContextWrapper {
|
|||
match *self {
|
||||
GLContextWrapper::Native(ref ctx) => {
|
||||
ctx.unbind().unwrap();
|
||||
}
|
||||
},
|
||||
GLContextWrapper::OSMesa(ref ctx) => {
|
||||
ctx.unbind().unwrap();
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,26 +155,22 @@ impl GLContextWrapper {
|
|||
&self,
|
||||
cmd: WebGLCommand,
|
||||
backtrace: WebGLCommandBacktrace,
|
||||
state: &mut GLState
|
||||
state: &mut GLState,
|
||||
) {
|
||||
match *self {
|
||||
GLContextWrapper::Native(ref ctx) => {
|
||||
WebGLImpl::apply(ctx, state, cmd, backtrace);
|
||||
}
|
||||
},
|
||||
GLContextWrapper::OSMesa(ref ctx) => {
|
||||
WebGLImpl::apply(ctx, state, cmd, backtrace);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn gl(&self) -> &gl::Gl {
|
||||
match *self {
|
||||
GLContextWrapper::Native(ref ctx) => {
|
||||
ctx.gl()
|
||||
}
|
||||
GLContextWrapper::OSMesa(ref ctx) => {
|
||||
ctx.gl()
|
||||
}
|
||||
GLContextWrapper::Native(ref ctx) => ctx.gl(),
|
||||
GLContextWrapper::OSMesa(ref ctx) => ctx.gl(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,23 +179,29 @@ impl GLContextWrapper {
|
|||
GLContextWrapper::Native(ref ctx) => {
|
||||
let (real_size, texture_id) = {
|
||||
let draw_buffer = ctx.borrow_draw_buffer().unwrap();
|
||||
(draw_buffer.size(), draw_buffer.get_bound_texture_id().unwrap())
|
||||
(
|
||||
draw_buffer.size(),
|
||||
draw_buffer.get_bound_texture_id().unwrap(),
|
||||
)
|
||||
};
|
||||
|
||||
let limits = ctx.borrow_limits().clone();
|
||||
|
||||
(real_size, texture_id, limits)
|
||||
}
|
||||
},
|
||||
GLContextWrapper::OSMesa(ref ctx) => {
|
||||
let (real_size, texture_id) = {
|
||||
let draw_buffer = ctx.borrow_draw_buffer().unwrap();
|
||||
(draw_buffer.size(), draw_buffer.get_bound_texture_id().unwrap())
|
||||
(
|
||||
draw_buffer.size(),
|
||||
draw_buffer.get_bound_texture_id().unwrap(),
|
||||
)
|
||||
};
|
||||
|
||||
let limits = ctx.borrow_limits().clone();
|
||||
|
||||
(real_size, texture_id, limits)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,11 +210,11 @@ impl GLContextWrapper {
|
|||
GLContextWrapper::Native(ref mut ctx) => {
|
||||
// FIXME(nox): Why are those i32 values?
|
||||
ctx.resize(size.to_i32())
|
||||
}
|
||||
},
|
||||
GLContextWrapper::OSMesa(ref mut ctx) => {
|
||||
// FIXME(nox): Why are those i32 values?
|
||||
ctx.resize(size.to_i32())
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -222,7 +223,7 @@ impl GLContextWrapper {
|
|||
/// It's used in Windows to allow WGL GLContext sharing.
|
||||
#[derive(Clone)]
|
||||
pub struct MainThreadDispatcher {
|
||||
compositor_proxy: Arc<Mutex<CompositorProxy>>
|
||||
compositor_proxy: Arc<Mutex<CompositorProxy>>,
|
||||
}
|
||||
|
||||
impl MainThreadDispatcher {
|
||||
|
@ -234,6 +235,9 @@ impl MainThreadDispatcher {
|
|||
}
|
||||
impl GLContextDispatcher for MainThreadDispatcher {
|
||||
fn dispatch(&self, f: Box<Fn() + Send>) {
|
||||
self.compositor_proxy.lock().unwrap().send(compositor_thread::Msg::Dispatch(f));
|
||||
self.compositor_proxy
|
||||
.lock()
|
||||
.unwrap()
|
||||
.send(compositor_thread::Msg::Dispatch(f));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,8 @@ extern crate euclid;
|
|||
extern crate fnv;
|
||||
extern crate gleam;
|
||||
extern crate ipc_channel;
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate num_traits;
|
||||
extern crate offscreen_gl_context;
|
||||
extern crate pixels;
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue