Skip to content

Commit

Permalink
Bug 1304913 - Have Servo manage node data directly without FFI calls.…
Browse files Browse the repository at this point in the history
… r=Manishearth

MozReview-Commit-ID: H8f8VP18TbM
  • Loading branch information
bholley committed Sep 24, 2016
1 parent 336ad0c commit ba743f5
Show file tree
Hide file tree
Showing 6 changed files with 493 additions and 471 deletions.
37 changes: 35 additions & 2 deletions ports/geckolib/binding_tools/regen.py
Expand Up @@ -66,6 +66,10 @@
"release": {
}
},
"raw_lines": [
# We can get rid of this when the bindings move into the style crate.
"pub enum OpaqueStyleData {}",
],
"whitelist_vars": [
"NS_THEME_.*",
"NODE_.*",
Expand All @@ -77,6 +81,9 @@
"BORDER_STYLE_.*"
],
"whitelist": [
"RawGeckoNode",
"RawGeckoElement",
"RawGeckoDocument",
"Element",
"Side",
"nsTArrayHeader",
Expand Down Expand Up @@ -168,6 +175,21 @@
"gfxSize", # <- Same, union { struct { T width; T height; }; T components[2] };
"gfxSize_Super", # Ditto.
],
"servo_mapped_generic_types": [
{
"generic": True,
"gecko": "ServoUnsafeCell",
"servo": "::std::cell::UnsafeCell"
}, {
"generic": True,
"gecko": "ServoCell",
"servo": "::std::cell::Cell"
}, {
"generic": False,
"gecko": "ServoNodeData",
"servo": "OpaqueStyleData"
}
],
},
# Generation of the ffi bindings.
"bindings": {
Expand Down Expand Up @@ -206,14 +228,15 @@
"FontFamilyType", "nsIAtom", "nsStyleContext", "StyleClipPath",
"StyleBasicShapeType", "StyleBasicShape", "nsCSSShadowArray",
"nsINode", "nsIDocument", "nsIPrincipal", "nsIURI",
"RawGeckoNode", "RawGeckoElement", "RawGeckoDocument",
"ServoNodeData",
],
"servo_nullable_arc_types": [
"ServoComputedValues", "RawServoStyleSheet",
"ServoDeclarationBlock"
],
"servo_owned_types": [
"RawServoStyleSet",
"ServoNodeData",
"StyleChildrenIterator",
],
"servo_immutable_borrow_types": [
Expand Down Expand Up @@ -430,7 +453,17 @@ def zero_size_type(ty, flags):
flags.append("{}BorrowedOrNull".format(ty))
flags.append("--raw-line")
flags.append("pub type {0}BorrowedOrNull<'a> = ::sugar::ownership::Borrowed<'a, {0}>;".format(ty))
zero_size_type(ty, flags)
# Right now the only immutable borrow types are ones which we import
# from the |structs| module. As such, we don't need to create an opaque
# type with zero_size_type. If we ever introduce immutable borrow types
# which _do_ need to be opaque, we'll need a separate mode.

if "servo_mapped_generic_types" in current_target:
for ty in current_target["servo_mapped_generic_types"]:
flags.append("--blacklist-type")
flags.append("{}".format(ty["gecko"]))
flags.append("--raw-line")
flags.append("pub type {0}{2} = {1}{2};".format(ty["gecko"], ty["servo"], "<T>" if ty["generic"] else ""))

if "servo_owned_types" in current_target:
for ty in current_target["servo_owned_types"]:
Expand Down
28 changes: 5 additions & 23 deletions ports/geckolib/gecko_bindings/bindings.rs
Expand Up @@ -18,16 +18,10 @@ enum ServoDeclarationBlockVoid{ }
pub struct ServoDeclarationBlock(ServoDeclarationBlockVoid);
pub type RawGeckoNodeBorrowed<'a> = &'a RawGeckoNode;
pub type RawGeckoNodeBorrowedOrNull<'a> = ::sugar::ownership::Borrowed<'a, RawGeckoNode>;
enum RawGeckoNodeVoid{ }
pub struct RawGeckoNode(RawGeckoNodeVoid);
pub type RawGeckoElementBorrowed<'a> = &'a RawGeckoElement;
pub type RawGeckoElementBorrowedOrNull<'a> = ::sugar::ownership::Borrowed<'a, RawGeckoElement>;
enum RawGeckoElementVoid{ }
pub struct RawGeckoElement(RawGeckoElementVoid);
pub type RawGeckoDocumentBorrowed<'a> = &'a RawGeckoDocument;
pub type RawGeckoDocumentBorrowedOrNull<'a> = ::sugar::ownership::Borrowed<'a, RawGeckoDocument>;
enum RawGeckoDocumentVoid{ }
pub struct RawGeckoDocument(RawGeckoDocumentVoid);
pub type RawServoStyleSetBorrowed<'a> = &'a RawServoStyleSet;
pub type RawServoStyleSetBorrowedMut<'a> = &'a mut RawServoStyleSet;
pub type RawServoStyleSetOwned = ::sugar::ownership::Owned<RawServoStyleSet>;
Expand All @@ -36,14 +30,6 @@ pub type RawServoStyleSetBorrowedMutOrNull<'a> = ::sugar::ownership::BorrowedMut
pub type RawServoStyleSetOwnedOrNull = ::sugar::ownership::OwnedOrNull<RawServoStyleSet>;
enum RawServoStyleSetVoid{ }
pub struct RawServoStyleSet(RawServoStyleSetVoid);
pub type ServoNodeDataBorrowed<'a> = &'a ServoNodeData;
pub type ServoNodeDataBorrowedMut<'a> = &'a mut ServoNodeData;
pub type ServoNodeDataOwned = ::sugar::ownership::Owned<ServoNodeData>;
pub type ServoNodeDataBorrowedOrNull<'a> = ::sugar::ownership::Borrowed<'a, ServoNodeData>;
pub type ServoNodeDataBorrowedMutOrNull<'a> = ::sugar::ownership::BorrowedMut<'a, ServoNodeData>;
pub type ServoNodeDataOwnedOrNull = ::sugar::ownership::OwnedOrNull<ServoNodeData>;
enum ServoNodeDataVoid{ }
pub struct ServoNodeData(ServoNodeDataVoid);
pub type StyleChildrenIteratorBorrowed<'a> = &'a StyleChildrenIterator;
pub type StyleChildrenIteratorBorrowedMut<'a> = &'a mut StyleChildrenIterator;
pub type StyleChildrenIteratorOwned = ::sugar::ownership::Owned<StyleChildrenIterator>;
Expand Down Expand Up @@ -179,6 +165,10 @@ use structs::nsINode;
use structs::nsIDocument;
use structs::nsIPrincipal;
use structs::nsIURI;
use structs::RawGeckoNode;
use structs::RawGeckoElement;
use structs::RawGeckoDocument;
use structs::ServoNodeData;

extern "C" {
pub fn Gecko_EnsureTArrayCapacity(aArray: *mut ::std::os::raw::c_void,
Expand All @@ -189,7 +179,7 @@ extern "C" {
aElementSize: usize, aElementAlign: usize);
}
extern "C" {
pub fn Servo_NodeData_Drop(arg1: *mut ServoNodeData);
pub fn Servo_Node_ClearNodeData(arg1: *mut nsINode);
}
#[repr(C)]
#[derive(Debug, Copy)]
Expand Down Expand Up @@ -387,14 +377,6 @@ extern "C" {
pub fn Gecko_GetServoDeclarationBlock(element: RawGeckoElementBorrowed)
-> ServoDeclarationBlockBorrowedOrNull;
}
extern "C" {
pub fn Gecko_GetNodeData(node: RawGeckoNodeBorrowed)
-> ServoNodeDataBorrowedOrNull;
}
extern "C" {
pub fn Gecko_SetNodeData(node: RawGeckoNodeBorrowed,
data: ServoNodeDataOwned);
}
extern "C" {
pub fn Gecko_Atomize(aString: *const ::std::os::raw::c_char, aLength: u32)
-> *mut nsIAtom;
Expand Down

0 comments on commit ba743f5

Please sign in to comment.