mirror of
https://github.com/servo/servo.git
synced 2025-08-08 15:05:35 +01:00
style: Use the owned slice type for basic shape polygon coordinates.
This enables destructors for tagged unions in cbindgen, implemented in: * https://github.com/eqrion/cbindgen/pull/333 Which allow us to properly generate a destructor for the cbindgen-generated StyleBasicShape (which now contains an OwnedSlice). For now, we still use the glue code to go from Box<BasicShape> to UniquePtr<BasicShape>. But that will change in the future when we generate even more stuff and remove all the glue. I could add support for copy-constructor generation to cbindgen for tagged enums, but I'm not sure if it'll end up being needed, and copy-constructing unions in C++ is always very tricky. Differential Revision: https://phabricator.services.mozilla.com/D29769
This commit is contained in:
parent
330bccd659
commit
559235edad
9 changed files with 79 additions and 218 deletions
|
@ -4046,16 +4046,15 @@ fn set_style_svg_path(
|
|||
|
||||
<%def name="impl_shape_source(ident, gecko_ffi_name)">
|
||||
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||
use crate::gecko_bindings::bindings::{Gecko_NewBasicShape, Gecko_DestroyShapeSource};
|
||||
use crate::gecko_bindings::structs::{StyleBasicShape, StyleBasicShapeType, StyleShapeSourceType};
|
||||
use crate::gecko_bindings::structs::{StyleGeometryBox, StyleShapeSource};
|
||||
use crate::gecko::values::GeckoStyleCoordConvertible;
|
||||
use crate::values::generics::basic_shape::{BasicShape, ShapeSource};
|
||||
use crate::values::generics::basic_shape::ShapeSource;
|
||||
use crate::gecko_bindings::structs::StyleShapeSourceType;
|
||||
use crate::gecko_bindings::structs::StyleGeometryBox;
|
||||
|
||||
let ref mut ${ident} = self.gecko.${gecko_ffi_name};
|
||||
|
||||
// clean up existing struct
|
||||
unsafe { Gecko_DestroyShapeSource(${ident}) };
|
||||
// clean up existing struct.
|
||||
unsafe { bindings::Gecko_DestroyShapeSource(${ident}) };
|
||||
|
||||
${ident}.mType = StyleShapeSourceType::None;
|
||||
|
||||
match v {
|
||||
|
@ -4084,72 +4083,12 @@ fn set_style_svg_path(
|
|||
}
|
||||
ShapeSource::Path(p) => set_style_svg_path(${ident}, &p.path, p.fill),
|
||||
ShapeSource::Shape(servo_shape, maybe_box) => {
|
||||
fn init_shape(${ident}: &mut StyleShapeSource, basic_shape_type: StyleBasicShapeType)
|
||||
-> &mut StyleBasicShape {
|
||||
unsafe {
|
||||
// Create StyleBasicShape in StyleShapeSource. mReferenceBox and mType
|
||||
// will be set manually later.
|
||||
Gecko_NewBasicShape(${ident}, basic_shape_type);
|
||||
&mut *${ident}.__bindgen_anon_1.mBasicShape.as_mut().mPtr
|
||||
}
|
||||
unsafe {
|
||||
${ident}.__bindgen_anon_1.mBasicShape.as_mut().mPtr =
|
||||
Box::into_raw(servo_shape);
|
||||
}
|
||||
match servo_shape {
|
||||
BasicShape::Inset(inset) => {
|
||||
let shape = init_shape(${ident}, StyleBasicShapeType::Inset);
|
||||
unsafe { shape.mCoordinates.set_len(4) };
|
||||
|
||||
// set_len() can't call constructors, so the coordinates
|
||||
// can contain any value. set_value() attempts to free
|
||||
// allocated coordinates, so we don't want to feed it
|
||||
// garbage values which it may misinterpret.
|
||||
// Instead, we use leaky_set_value to blindly overwrite
|
||||
// the garbage data without
|
||||
// attempting to clean up.
|
||||
shape.mCoordinates[0].leaky_set_null();
|
||||
inset.rect.0.to_gecko_style_coord(&mut shape.mCoordinates[0]);
|
||||
shape.mCoordinates[1].leaky_set_null();
|
||||
inset.rect.1.to_gecko_style_coord(&mut shape.mCoordinates[1]);
|
||||
shape.mCoordinates[2].leaky_set_null();
|
||||
inset.rect.2.to_gecko_style_coord(&mut shape.mCoordinates[2]);
|
||||
shape.mCoordinates[3].leaky_set_null();
|
||||
inset.rect.3.to_gecko_style_coord(&mut shape.mCoordinates[3]);
|
||||
shape.mRadius = inset.round;
|
||||
}
|
||||
BasicShape::Circle(circ) => {
|
||||
let shape = init_shape(${ident}, StyleBasicShapeType::Circle);
|
||||
unsafe { shape.mCoordinates.set_len(1) };
|
||||
shape.mCoordinates[0].leaky_set_null();
|
||||
circ.radius.to_gecko_style_coord(&mut shape.mCoordinates[0]);
|
||||
|
||||
shape.mPosition = circ.position.into();
|
||||
}
|
||||
BasicShape::Ellipse(el) => {
|
||||
let shape = init_shape(${ident}, StyleBasicShapeType::Ellipse);
|
||||
unsafe { shape.mCoordinates.set_len(2) };
|
||||
shape.mCoordinates[0].leaky_set_null();
|
||||
el.semiaxis_x.to_gecko_style_coord(&mut shape.mCoordinates[0]);
|
||||
shape.mCoordinates[1].leaky_set_null();
|
||||
el.semiaxis_y.to_gecko_style_coord(&mut shape.mCoordinates[1]);
|
||||
|
||||
shape.mPosition = el.position.into();
|
||||
}
|
||||
BasicShape::Polygon(poly) => {
|
||||
let shape = init_shape(${ident}, StyleBasicShapeType::Polygon);
|
||||
unsafe {
|
||||
shape.mCoordinates.set_len(poly.coordinates.len() as u32 * 2);
|
||||
}
|
||||
for (i, coord) in poly.coordinates.iter().enumerate() {
|
||||
shape.mCoordinates[2 * i].leaky_set_null();
|
||||
shape.mCoordinates[2 * i + 1].leaky_set_null();
|
||||
coord.0.to_gecko_style_coord(&mut shape.mCoordinates[2 * i]);
|
||||
coord.1.to_gecko_style_coord(&mut shape.mCoordinates[2 * i + 1]);
|
||||
}
|
||||
shape.mFillRule = poly.fill;
|
||||
}
|
||||
}
|
||||
|
||||
${ident}.mReferenceBox = maybe_box.map(Into::into)
|
||||
.unwrap_or(StyleGeometryBox::NoBox);
|
||||
${ident}.mReferenceBox =
|
||||
maybe_box.map(Into::into).unwrap_or(StyleGeometryBox::NoBox);
|
||||
${ident}.mType = StyleShapeSourceType::Shape;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue