Bug 1357335 - Use Into<T> for webrender bindings conversions r=kats

Types also implement Copy, Clone now to make this easier.

MozReview-Commit-ID: GEVsCEw2o6K

--HG--
extra : rebase_source : b42ddaab3b7ab0a31006e78aff45ddb6e4160845
extra : amend_source : 82a7e1d272b397c8ab1d0346fd5a708117b897a3
This commit is contained in:
Ryan Hunt 2017-04-18 04:18:35 -04:00
Родитель 9a7952f7f9
Коммит 2d446d69ea
1 изменённых файлов: 176 добавлений и 165 удалений

Просмотреть файл

@ -119,8 +119,8 @@ pub enum WrGradientExtendMode {
Repeat, Repeat,
} }
impl WrGradientExtendMode { impl Into<ExtendMode> for WrGradientExtendMode {
pub fn to_gradient_extend_mode(self) -> ExtendMode { fn into(self) -> ExtendMode {
match self { match self {
WrGradientExtendMode::Clamp => ExtendMode::Clamp, WrGradientExtendMode::Clamp => ExtendMode::Clamp,
WrGradientExtendMode::Repeat => ExtendMode::Repeat, WrGradientExtendMode::Repeat => ExtendMode::Repeat,
@ -129,20 +129,20 @@ impl WrGradientExtendMode {
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy)]
struct WrItemRange { struct WrItemRange {
start: usize, start: usize,
length: usize, length: usize,
} }
impl WrItemRange { impl Into<ItemRange> for WrItemRange {
fn to_item_range(&self) -> ItemRange { fn into(self) -> ItemRange {
ItemRange { ItemRange {
start: self.start, start: self.start,
length: self.length, length: self.length,
} }
} }
} }
impl From<ItemRange> for WrItemRange { impl From<ItemRange> for WrItemRange {
fn from(item_range: ItemRange) -> Self { fn from(item_range: ItemRange) -> Self {
WrItemRange { WrItemRange {
@ -153,32 +153,33 @@ impl From<ItemRange> for WrItemRange {
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone)] #[derive(Debug, Clone, Copy)]
pub struct WrPoint { pub struct WrPoint {
x: f32, x: f32,
y: f32, y: f32,
} }
impl WrPoint { impl<U> Into<TypedPoint2D<f32, U>> for WrPoint {
pub fn to_point<U>(&self) -> TypedPoint2D<f32, U> { fn into(self) -> TypedPoint2D<f32, U> {
TypedPoint2D::new(self.x, self.y) TypedPoint2D::new(self.x, self.y)
} }
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct WrSize { pub struct WrSize {
width: f32, width: f32,
height: f32, height: f32,
} }
impl WrSize { impl<U> Into<TypedSize2D<f32, U>> for WrSize {
pub fn to_size<U>(&self) -> TypedSize2D<f32, U> { fn into(self) -> TypedSize2D<f32, U> {
TypedSize2D::new(self.width, self.height) TypedSize2D::new(self.width, self.height)
} }
} }
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug, Clone, Copy)]
pub struct WrRect { pub struct WrRect {
x: f32, x: f32,
y: f32, y: f32,
@ -186,8 +187,8 @@ pub struct WrRect {
height: f32, height: f32,
} }
impl WrRect { impl<U> Into<TypedRect<f32, U>> for WrRect {
pub fn to_rect<U>(&self) -> TypedRect<f32, U> { fn into(self) -> TypedRect<f32, U> {
TypedRect::new(TypedPoint2D::new(self.x, self.y), TypedRect::new(TypedPoint2D::new(self.x, self.y),
TypedSize2D::new(self.width, self.height)) TypedSize2D::new(self.width, self.height))
} }
@ -204,13 +205,22 @@ impl<U> From<TypedRect<f32, U>> for WrRect {
} }
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug, Clone, Copy)]
pub struct WrMatrix { pub struct WrMatrix {
values: [f32; 16], values: [f32; 16],
} }
impl WrMatrix { impl<'a, U, E> Into<TypedMatrix4D<f32, U, E>> for &'a WrMatrix {
pub fn to_transform<U, E>(&self) -> TypedMatrix4D<f32, U, E> { fn into(self) -> TypedMatrix4D<f32, U, E> {
TypedMatrix4D::row_major(
self.values[0], self.values[1], self.values[2], self.values[3],
self.values[4], self.values[5], self.values[6], self.values[7],
self.values[8], self.values[9], self.values[10], self.values[11],
self.values[12], self.values[13], self.values[14], self.values[15])
}
}
impl<U, E> Into<TypedMatrix4D<f32, U, E>> for WrMatrix {
fn into(self) -> TypedMatrix4D<f32, U, E> {
TypedMatrix4D::row_major( TypedMatrix4D::row_major(
self.values[0], self.values[1], self.values[2], self.values[3], self.values[0], self.values[1], self.values[2], self.values[3],
self.values[4], self.values[5], self.values[6], self.values[7], self.values[4], self.values[5], self.values[6], self.values[7],
@ -220,6 +230,7 @@ impl WrMatrix {
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct WrColor { pub struct WrColor {
r: f32, r: f32,
g: f32, g: f32,
@ -227,65 +238,62 @@ pub struct WrColor {
a: f32, a: f32,
} }
impl WrColor { impl Into<ColorF> for WrColor {
pub fn to_color(&self) -> ColorF { fn into(self) -> ColorF {
ColorF::new(self.r, self.g, self.b, self.a) ColorF::new(self.r, self.g, self.b, self.a)
} }
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone)] #[derive(Debug, Clone, Copy)]
pub struct WrGlyphInstance { pub struct WrGlyphInstance {
index: u32, index: u32,
point: WrPoint, point: WrPoint,
} }
impl WrGlyphInstance { impl<'a> Into<GlyphInstance> for &'a WrGlyphInstance {
pub fn to_glyph_instance(&self) -> GlyphInstance { fn into(self) -> GlyphInstance {
GlyphInstance { GlyphInstance {
index: self.index, index: self.index,
point: self.point.to_point(), point: self.point.into(),
} }
} }
pub fn to_glyph_instances(glyphs: &[WrGlyphInstance]) -> Vec<GlyphInstance> {
glyphs.iter().map(|x| x.to_glyph_instance()).collect()
}
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct WrGradientStop { pub struct WrGradientStop {
offset: f32, offset: f32,
color: WrColor, color: WrColor,
} }
impl WrGradientStop { impl<'a> Into<GradientStop> for &'a WrGradientStop {
pub fn to_gradient_stop(&self) -> GradientStop { fn into(self) -> GradientStop {
GradientStop { GradientStop {
offset: self.offset, offset: self.offset,
color: self.color.to_color(), color: self.color.into(),
} }
} }
pub fn to_gradient_stops(stops: &[WrGradientStop]) -> Vec<GradientStop> {
stops.iter().map(|x| x.to_gradient_stop()).collect()
}
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct WrBorderSide { pub struct WrBorderSide {
color: WrColor, color: WrColor,
style: WrBorderStyle, style: WrBorderStyle,
} }
impl WrBorderSide { impl Into<BorderSide> for WrBorderSide {
pub fn to_border_side(&self) -> BorderSide { fn into(self) -> BorderSide {
BorderSide { BorderSide {
color: self.color.to_color(), color: self.color.into(),
style: self.style, style: self.style,
} }
} }
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct WrBorderRadius { pub struct WrBorderRadius {
pub top_left: WrSize, pub top_left: WrSize,
pub top_right: WrSize, pub top_right: WrSize,
@ -293,18 +301,19 @@ pub struct WrBorderRadius {
pub bottom_right: WrSize, pub bottom_right: WrSize,
} }
impl WrBorderRadius { impl Into<BorderRadius> for WrBorderRadius {
pub fn to_border_radius(&self) -> BorderRadius { fn into(self) -> BorderRadius {
BorderRadius { BorderRadius {
top_left: self.top_left.to_size(), top_left: self.top_left.into(),
top_right: self.top_right.to_size(), top_right: self.top_right.into(),
bottom_left: self.bottom_left.to_size(), bottom_left: self.bottom_left.into(),
bottom_right: self.bottom_right.to_size(), bottom_right: self.bottom_right.into(),
} }
} }
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct WrBorderWidths pub struct WrBorderWidths
{ {
left: f32, left: f32,
@ -313,9 +322,8 @@ pub struct WrBorderWidths
bottom: f32, bottom: f32,
} }
impl WrBorderWidths impl Into<BorderWidths> for WrBorderWidths {
{ fn into(self) -> BorderWidths {
pub fn to_border_widths(&self) -> BorderWidths {
BorderWidths { BorderWidths {
left: self.left, left: self.left,
top: self.top, top: self.top,
@ -326,6 +334,7 @@ impl WrBorderWidths
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct WrNinePatchDescriptor pub struct WrNinePatchDescriptor
{ {
width: u32, width: u32,
@ -333,18 +342,18 @@ pub struct WrNinePatchDescriptor
slice: WrSideOffsets2Du32, slice: WrSideOffsets2Du32,
} }
impl WrNinePatchDescriptor impl Into<NinePatchDescriptor> for WrNinePatchDescriptor {
{ fn into(self) -> NinePatchDescriptor {
pub fn to_nine_patch_descriptor(&self) -> NinePatchDescriptor {
NinePatchDescriptor { NinePatchDescriptor {
width: self.width, width: self.width,
height: self.height, height: self.height,
slice: self.slice.to_side_offsets_2d(), slice: self.slice.into(),
} }
} }
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct WrSideOffsets2D<T> pub struct WrSideOffsets2D<T>
{ {
top: T, top: T,
@ -353,9 +362,8 @@ pub struct WrSideOffsets2D<T>
left: T, left: T,
} }
impl<T: Copy> WrSideOffsets2D<T> impl<T: Copy> Into<SideOffsets2D<T>> for WrSideOffsets2D<T> {
{ fn into(self) -> SideOffsets2D<T> {
pub fn to_side_offsets_2d(&self) -> SideOffsets2D<T> {
SideOffsets2D::new(self.top, self.right, self.bottom, self.left) SideOffsets2D::new(self.top, self.right, self.bottom, self.left)
} }
} }
@ -369,9 +377,8 @@ pub enum WrRepeatMode
Space, Space,
} }
impl WrRepeatMode impl Into<RepeatMode> for WrRepeatMode {
{ fn into(self) -> RepeatMode {
pub fn to_repeat_mode(self) -> RepeatMode {
match self { match self {
WrRepeatMode::Stretch => RepeatMode::Stretch, WrRepeatMode::Stretch => RepeatMode::Stretch,
WrRepeatMode::Repeat => RepeatMode::Repeat, WrRepeatMode::Repeat => RepeatMode::Repeat,
@ -382,17 +389,27 @@ impl WrRepeatMode
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct WrImageMask { pub struct WrImageMask {
image: WrImageKey, image: WrImageKey,
rect: WrRect, rect: WrRect,
repeat: bool, repeat: bool,
} }
impl WrImageMask { impl Into<ImageMask> for WrImageMask {
pub fn to_image_mask(&self) -> ImageMask { fn into(self) -> ImageMask {
ImageMask { ImageMask {
image: self.image, image: self.image,
rect: self.rect.to_rect(), rect: self.rect.into(),
repeat: self.repeat,
}
}
}
impl<'a> Into<ImageMask> for &'a WrImageMask {
fn into(self) -> ImageMask {
ImageMask {
image: self.image,
rect: self.rect.into(),
repeat: self.repeat, repeat: self.repeat,
} }
} }
@ -408,38 +425,37 @@ impl From<ImageMask> for WrImageMask {
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct WrComplexClipRegion { pub struct WrComplexClipRegion {
rect: WrRect, rect: WrRect,
radii: WrBorderRadius, radii: WrBorderRadius,
} }
impl WrComplexClipRegion { impl<'a> Into<ComplexClipRegion> for &'a WrComplexClipRegion {
pub fn to_complex_clip_region(&self) -> ComplexClipRegion { fn into(self) -> ComplexClipRegion {
ComplexClipRegion { ComplexClipRegion {
rect: self.rect.to_rect(), rect: self.rect.into(),
radii: self.radii.to_border_radius(), radii: self.radii.into(),
} }
} }
pub fn to_complex_clip_regions(complex_clips: &[WrComplexClipRegion])
-> Vec<ComplexClipRegion> {
complex_clips.iter().map(|x| x.to_complex_clip_region()).collect()
}
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct WrClipRegion { pub struct WrClipRegion {
main: WrRect, main: WrRect,
complex: WrItemRange, complex: WrItemRange,
image_mask: WrImageMask, image_mask: WrImageMask,
has_image_mask: bool, has_image_mask: bool,
} }
impl WrClipRegion {
pub fn to_clip_region(&self) -> ClipRegion { impl Into<ClipRegion> for WrClipRegion {
fn into(self) -> ClipRegion {
ClipRegion { ClipRegion {
main: self.main.to_rect(), main: self.main.into(),
complex: self.complex.to_item_range(), complex: self.complex.into(),
image_mask: if self.has_image_mask { image_mask: if self.has_image_mask {
Some(self.image_mask.to_image_mask()) Some(self.image_mask.into())
} else { } else {
None None
}, },
@ -568,8 +584,8 @@ pub struct WrImageDescriptor {
pub is_opaque: bool, pub is_opaque: bool,
} }
impl WrImageDescriptor { impl<'a> Into<ImageDescriptor> for &'a WrImageDescriptor {
pub fn to_descriptor(&self) -> ImageDescriptor { fn into(self) -> ImageDescriptor {
ImageDescriptor { ImageDescriptor {
width: self.width, width: self.width,
height: self.height, height: self.height,
@ -862,7 +878,7 @@ pub extern "C" fn wr_api_add_image(api: &mut WrAPI,
assert!(unsafe { is_in_compositor_thread() }); assert!(unsafe { is_in_compositor_thread() });
let copied_bytes = bytes.as_slice().to_owned(); let copied_bytes = bytes.as_slice().to_owned();
api.add_image(image_key, api.add_image(image_key,
descriptor.to_descriptor(), descriptor.into(),
ImageData::new(copied_bytes), ImageData::new(copied_bytes),
None); None);
} }
@ -875,7 +891,7 @@ pub extern "C" fn wr_api_add_blob_image(api: &mut WrAPI,
assert!(unsafe { is_in_compositor_thread() }); assert!(unsafe { is_in_compositor_thread() });
let copied_bytes = bytes.as_slice().to_owned(); let copied_bytes = bytes.as_slice().to_owned();
api.add_image(image_key, api.add_image(image_key,
descriptor.to_descriptor(), descriptor.into(),
ImageData::new_blob_image(copied_bytes), ImageData::new_blob_image(copied_bytes),
None); None);
} }
@ -887,7 +903,7 @@ pub extern "C" fn wr_api_add_external_image_handle(api: &mut WrAPI,
external_image_id: u64) { external_image_id: u64) {
assert!(unsafe { is_in_compositor_thread() }); assert!(unsafe { is_in_compositor_thread() });
api.add_image(image_key, api.add_image(image_key,
descriptor.to_descriptor(), descriptor.into(),
ImageData::External(ExternalImageData { ImageData::External(ExternalImageData {
id: ExternalImageId(external_image_id), id: ExternalImageId(external_image_id),
image_type: ExternalImageType::Texture2DHandle image_type: ExternalImageType::Texture2DHandle
@ -902,7 +918,7 @@ pub extern "C" fn wr_api_add_external_image_buffer(api: &mut WrAPI,
external_image_id: u64) { external_image_id: u64) {
assert!(unsafe { is_in_compositor_thread() }); assert!(unsafe { is_in_compositor_thread() });
api.add_image(image_key, api.add_image(image_key,
descriptor.to_descriptor(), descriptor.into(),
ImageData::External(ExternalImageData { ImageData::External(ExternalImageData {
id: ExternalImageId(external_image_id), id: ExternalImageId(external_image_id),
image_type: ExternalImageType::ExternalBuffer image_type: ExternalImageType::ExternalBuffer
@ -919,7 +935,7 @@ pub extern "C" fn wr_api_update_image(api: &mut WrAPI,
let copied_bytes = bytes.as_slice().to_owned(); let copied_bytes = bytes.as_slice().to_owned();
api.update_image(key, api.update_image(key,
descriptor.to_descriptor(), descriptor.into(),
ImageData::new(copied_bytes), ImageData::new(copied_bytes),
None); None);
} }
@ -1016,7 +1032,7 @@ pub extern "C" fn wr_api_generate_frame_with_properties(api: &mut WrAPI,
for element in transform_slice.iter() { for element in transform_slice.iter() {
let prop = PropertyValue { let prop = PropertyValue {
key: PropertyBindingKey::new(element.id), key: PropertyBindingKey::new(element.id),
value: element.transform.to_transform(), value: element.transform.into(),
}; };
properties.transforms.push(prop); properties.transforms.push(prop);
@ -1164,15 +1180,12 @@ pub extern "C" fn wr_dp_new_clip_region(state: &mut WrState,
-> WrClipRegion { -> WrClipRegion {
assert!(unsafe { is_in_main_thread() }); assert!(unsafe { is_in_main_thread() });
let main = main.to_rect(); let main = main.into();
let complex = let complex_slice = unsafe { slice::from_raw_parts(complex, complex_count) };
WrComplexClipRegion::to_complex_clip_regions(unsafe { let complex_vector = complex_slice.iter().map(|x| x.into()).collect();
slice::from_raw_parts(complex, let mask = unsafe { image_mask.as_ref() }.map(|x| x.into());
complex_count)
});
let mask = unsafe { image_mask.as_ref().map(|x| x.to_image_mask()) };
let clip_region = state.frame_builder.dl_builder.new_clip_region(&main, complex, mask); let clip_region = state.frame_builder.dl_builder.new_clip_region(&main, complex_vector, mask);
clip_region.into() clip_region.into()
} }
@ -1187,7 +1200,7 @@ pub extern "C" fn wr_dp_push_stacking_context(state: &mut WrState,
assert!(unsafe { is_in_main_thread() }); assert!(unsafe { is_in_main_thread() });
state.z_index += 1; state.z_index += 1;
let bounds = bounds.to_rect(); let bounds = bounds.into();
let mut filters: Vec<FilterOp> = Vec::new(); let mut filters: Vec<FilterOp> = Vec::new();
let opacity = unsafe { opacity.as_ref() }; let opacity = unsafe { opacity.as_ref() };
@ -1202,7 +1215,7 @@ pub extern "C" fn wr_dp_push_stacking_context(state: &mut WrState,
let transform = unsafe { transform.as_ref() }; let transform = unsafe { transform.as_ref() };
let transform_binding = match transform { let transform_binding = match transform {
Some(transform) => PropertyBinding::Value(transform.to_transform()), Some(transform) => PropertyBinding::Value(transform.into()),
None => PropertyBinding::Binding(PropertyBindingKey::new(animation_id)), None => PropertyBinding::Binding(PropertyBindingKey::new(animation_id)),
}; };
@ -1229,16 +1242,9 @@ pub extern "C" fn wr_dp_push_scroll_layer(state: &mut WrState,
content_rect: WrRect, content_rect: WrRect,
clip_rect: WrRect, clip_rect: WrRect,
mask: *const WrImageMask) { mask: *const WrImageMask) {
let content_rect = content_rect.to_rect(); let content_rect = content_rect.into();
let clip_rect = clip_rect.to_rect(); let clip_rect = clip_rect.into();
let mask = unsafe { mask.as_ref() }; let mask = unsafe { mask.as_ref() }.map(|x| x.into());
let mask = mask.map(|&WrImageMask { image, ref rect, repeat }| {
ImageMask {
image: image,
rect: rect.to_rect(),
repeat: repeat,
}
});
let clip_region = state.frame_builder.dl_builder.new_clip_region(&clip_rect, vec![], mask); let clip_region = state.frame_builder.dl_builder.new_clip_region(&clip_rect, vec![], mask);
state.frame_builder.dl_builder.push_clip_node(clip_region, content_rect, None); state.frame_builder.dl_builder.push_clip_node(clip_region, content_rect, None);
} }
@ -1256,7 +1262,7 @@ pub extern "C" fn wr_dp_push_iframe(state: &mut WrState,
pipeline_id: WrPipelineId) { pipeline_id: WrPipelineId) {
assert!(unsafe { is_in_main_thread() }); assert!(unsafe { is_in_main_thread() });
state.frame_builder.dl_builder.push_iframe(rect.to_rect(), clip.to_clip_region(), pipeline_id); state.frame_builder.dl_builder.push_iframe(rect.into(), clip.into(), pipeline_id);
} }
#[no_mangle] #[no_mangle]
@ -1266,9 +1272,9 @@ pub extern "C" fn wr_dp_push_rect(state: &mut WrState,
color: WrColor) { color: WrColor) {
assert!(unsafe { is_in_main_thread() }); assert!(unsafe { is_in_main_thread() });
state.frame_builder.dl_builder.push_rect(rect.to_rect(), state.frame_builder.dl_builder.push_rect(rect.into(),
clip.to_clip_region(), clip.into(),
color.to_color()); color.into());
} }
#[no_mangle] #[no_mangle]
@ -1281,12 +1287,12 @@ pub extern "C" fn wr_dp_push_image(state: &mut WrState,
key: WrImageKey) { key: WrImageKey) {
assert!(unsafe { is_in_main_thread() }); assert!(unsafe { is_in_main_thread() });
let bounds = bounds.to_rect(); let bounds = bounds.into();
state.frame_builder.dl_builder.push_image(bounds, state.frame_builder.dl_builder.push_image(bounds,
clip.to_clip_region(), clip.into(),
stretch_size.to_size(), stretch_size.into(),
tile_spacing.to_size(), tile_spacing.into(),
image_rendering, image_rendering,
key); key);
} }
@ -1303,14 +1309,13 @@ pub extern "C" fn wr_dp_push_text(state: &mut WrState,
assert!(unsafe { is_in_main_thread() }); assert!(unsafe { is_in_main_thread() });
let glyph_slice = unsafe { slice::from_raw_parts(glyphs, glyph_count as usize) }; let glyph_slice = unsafe { slice::from_raw_parts(glyphs, glyph_count as usize) };
let mut glyph_vector = Vec::new(); let glyph_vector: Vec<_> = glyph_slice.iter().map(|x| x.into()).collect();
glyph_vector.extend_from_slice(&WrGlyphInstance::to_glyph_instances(glyph_slice));
let colorf = ColorF::new(color.r, color.g, color.b, color.a); let colorf = ColorF::new(color.r, color.g, color.b, color.a);
let glyph_options = None; // TODO let glyph_options = None; // TODO
state.frame_builder.dl_builder.push_text(bounds.to_rect(), state.frame_builder.dl_builder.push_text(bounds.into(),
clip.to_clip_region(), clip.into(),
&glyph_vector, &glyph_vector,
font_key, font_key,
colorf, colorf,
@ -1332,16 +1337,16 @@ pub extern "C" fn wr_dp_push_border(state: &mut WrState,
assert!(unsafe { is_in_main_thread() }); assert!(unsafe { is_in_main_thread() });
let border_details = BorderDetails::Normal(NormalBorder { let border_details = BorderDetails::Normal(NormalBorder {
left: left.to_border_side(), left: left.into(),
right: right.to_border_side(), right: right.into(),
top: top.to_border_side(), top: top.into(),
bottom: bottom.to_border_side(), bottom: bottom.into(),
radius: radius.to_border_radius(), radius: radius.into(),
}); });
state.frame_builder.dl_builder.push_border( state.frame_builder.dl_builder.push_border(
rect.to_rect(), rect.into(),
clip.to_clip_region(), clip.into(),
widths.to_border_widths(), widths.into(),
border_details); border_details);
} }
@ -1358,15 +1363,15 @@ pub extern "C" fn wr_dp_push_border_image(state: &mut WrState,
assert!( unsafe { is_in_main_thread() }); assert!( unsafe { is_in_main_thread() });
let border_details = BorderDetails::Image(ImageBorder { let border_details = BorderDetails::Image(ImageBorder {
image_key: image, image_key: image,
patch: patch.to_nine_patch_descriptor(), patch: patch.into(),
outset: outset.to_side_offsets_2d(), outset: outset.into(),
repeat_horizontal: repeat_horizontal.to_repeat_mode(), repeat_horizontal: repeat_horizontal.into(),
repeat_vertical: repeat_vertical.to_repeat_mode(), repeat_vertical: repeat_vertical.into(),
}); });
state.frame_builder.dl_builder.push_border( state.frame_builder.dl_builder.push_border(
rect.to_rect(), rect.into(),
clip.to_clip_region(), clip.into(),
widths.to_border_widths(), widths.into(),
border_details); border_details);
} }
@ -1378,17 +1383,20 @@ pub extern "C" fn wr_dp_push_border_gradient(state: &mut WrState, rect: WrRect,
extend_mode: WrGradientExtendMode, extend_mode: WrGradientExtendMode,
outset: WrSideOffsets2Df32) { outset: WrSideOffsets2Df32) {
assert!( unsafe { is_in_main_thread() }); assert!( unsafe { is_in_main_thread() });
let stops = WrGradientStop::to_gradient_stops(unsafe { slice::from_raw_parts(stops, stops_count) });
let stops_slice = unsafe { slice::from_raw_parts(stops, stops_count) };
let stops_vector = stops_slice.iter().map(|x| x.into()).collect();
let border_details = BorderDetails::Gradient(GradientBorder { let border_details = BorderDetails::Gradient(GradientBorder {
gradient: state.frame_builder.dl_builder.create_gradient( gradient: state.frame_builder.dl_builder.create_gradient(
start_point.to_point(), end_point.to_point(), start_point.into(), end_point.into(),
stops, extend_mode.to_gradient_extend_mode()), stops_vector, extend_mode.into()),
outset: outset.to_side_offsets_2d(), outset: outset.into(),
}); });
state.frame_builder.dl_builder.push_border( state.frame_builder.dl_builder.push_border(
rect.to_rect(), rect.into(),
clip.to_clip_region(), clip.into(),
widths.to_border_widths(), widths.into(),
border_details); border_details);
} }
@ -1401,18 +1409,21 @@ pub extern "C" fn wr_dp_push_border_radial_gradient(state: &mut WrState, rect: W
extend_mode: WrGradientExtendMode, extend_mode: WrGradientExtendMode,
outset: WrSideOffsets2Df32) { outset: WrSideOffsets2Df32) {
assert!( unsafe { is_in_main_thread() }); assert!( unsafe { is_in_main_thread() });
let stops = WrGradientStop::to_gradient_stops(unsafe { slice::from_raw_parts(stops, stops_count) });
let stops_slice = unsafe { slice::from_raw_parts(stops, stops_count) };
let stops_vector = stops_slice.iter().map(|x| x.into()).collect();
let border_details = BorderDetails::RadialGradient(RadialGradientBorder { let border_details = BorderDetails::RadialGradient(RadialGradientBorder {
gradient: state.frame_builder.dl_builder.create_radial_gradient(center.to_point(), gradient: state.frame_builder.dl_builder.create_radial_gradient(center.into(),
radius.to_size(), radius.into(),
stops, stops_vector,
extend_mode.to_gradient_extend_mode()), extend_mode.into()),
outset: outset.to_side_offsets_2d(), outset: outset.into(),
}); });
state.frame_builder.dl_builder.push_border( state.frame_builder.dl_builder.push_border(
rect.to_rect(), rect.into(),
clip.to_clip_region(), clip.into(),
widths.to_border_widths(), widths.into(),
border_details); border_details);
} }
@ -1429,18 +1440,18 @@ pub extern "C" fn wr_dp_push_linear_gradient(state: &mut WrState,
tile_spacing: WrSize) { tile_spacing: WrSize) {
assert!(unsafe { is_in_main_thread() }); assert!(unsafe { is_in_main_thread() });
let stops = let stops_slice = unsafe { slice::from_raw_parts(stops, stops_count) };
WrGradientStop::to_gradient_stops(unsafe { slice::from_raw_parts(stops, stops_count) }); let stops_vector = stops_slice.iter().map(|x| x.into()).collect();
let gradient = state.frame_builder.dl_builder.create_gradient(start_point.to_point(), let gradient = state.frame_builder.dl_builder.create_gradient(start_point.into(),
end_point.to_point(), end_point.into(),
stops, stops_vector,
extend_mode.to_gradient_extend_mode()); extend_mode.into());
let rect = rect.to_rect(); let rect = rect.into();
let tile_size = tile_size.to_size(); let tile_size = tile_size.into();
let tile_spacing = tile_spacing.to_size(); let tile_spacing = tile_spacing.into();
state.frame_builder.dl_builder.push_gradient(rect, state.frame_builder.dl_builder.push_gradient(rect,
clip.to_clip_region(), clip.into(),
gradient, gradient,
tile_size, tile_size,
tile_spacing); tile_spacing);
@ -1459,18 +1470,18 @@ pub extern "C" fn wr_dp_push_radial_gradient(state: &mut WrState,
tile_spacing: WrSize) { tile_spacing: WrSize) {
assert!(unsafe { is_in_main_thread() }); assert!(unsafe { is_in_main_thread() });
let stops = let stops_slice = unsafe { slice::from_raw_parts(stops, stops_count) };
WrGradientStop::to_gradient_stops(unsafe { slice::from_raw_parts(stops, stops_count) }); let stops_vector = stops_slice.iter().map(|x| x.into()).collect();
let gradient = state.frame_builder.dl_builder.create_radial_gradient(center.to_point(), let gradient = state.frame_builder.dl_builder.create_radial_gradient(center.into(),
radius.to_size(), radius.into(),
stops, stops_vector,
extend_mode.to_gradient_extend_mode()); extend_mode.into());
let rect = rect.to_rect(); let rect = rect.into();
let tile_size = tile_size.to_size(); let tile_size = tile_size.into();
let tile_spacing = tile_spacing.to_size(); let tile_spacing = tile_spacing.into();
state.frame_builder.dl_builder.push_radial_gradient(rect, state.frame_builder.dl_builder.push_radial_gradient(rect,
clip.to_clip_region(), clip.into(),
gradient, gradient,
tile_size, tile_size,
tile_spacing); tile_spacing);
@ -1489,11 +1500,11 @@ pub extern "C" fn wr_dp_push_box_shadow(state: &mut WrState,
clip_mode: WrBoxShadowClipMode) { clip_mode: WrBoxShadowClipMode) {
assert!(unsafe { is_in_main_thread() }); assert!(unsafe { is_in_main_thread() });
state.frame_builder.dl_builder.push_box_shadow(rect.to_rect(), state.frame_builder.dl_builder.push_box_shadow(rect.into(),
clip.to_clip_region(), clip.into(),
box_bounds.to_rect(), box_bounds.into(),
offset.to_point(), offset.into(),
color.to_color(), color.into(),
blur_radius, blur_radius,
spread_radius, spread_radius,
border_radius, border_radius,