mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Add bindings for owned types, use for servostyleset
This commit is contained in:
parent
db7156526f
commit
8bed07292c
5 changed files with 56 additions and 19 deletions
|
@ -154,12 +154,9 @@ COMPILATION_TARGETS = {
|
||||||
"ServoComputedValues", "RawServoStyleSheet",
|
"ServoComputedValues", "RawServoStyleSheet",
|
||||||
"ServoDeclarationBlock"
|
"ServoDeclarationBlock"
|
||||||
],
|
],
|
||||||
"servo_borrowed_types": [
|
"servo_owned_types": [
|
||||||
"RawServoStyleSet",
|
"RawServoStyleSet",
|
||||||
],
|
],
|
||||||
"servo_borrowed_mut_types": [
|
|
||||||
"RawServoStyleSet",
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"atoms": {
|
"atoms": {
|
||||||
|
@ -331,18 +328,20 @@ def build(objdir, target_name, debug, debugger, kind_name=None,
|
||||||
flags.append("{}Borrowed".format(ty))
|
flags.append("{}Borrowed".format(ty))
|
||||||
flags.append("--raw-line")
|
flags.append("--raw-line")
|
||||||
flags.append("pub type {0}Borrowed<'a> = ::sugar::refptr::Borrowed<'a, {0}>;".format(ty))
|
flags.append("pub type {0}Borrowed<'a> = ::sugar::refptr::Borrowed<'a, {0}>;".format(ty))
|
||||||
if "servo_borrowed_types" in current_target:
|
if "servo_owned_types" in current_target:
|
||||||
for ty in current_target["servo_borrowed_types"]:
|
for ty in current_target["servo_owned_types"]:
|
||||||
flags.append("-blacklist-type")
|
flags.append("-blacklist-type")
|
||||||
flags.append("{}Borrowed".format(ty))
|
flags.append("{}Borrowed".format(ty))
|
||||||
flags.append("-raw-line")
|
flags.append("-raw-line")
|
||||||
flags.append("pub type {0}Borrowed<'a> = &'a {0};".format(ty))
|
flags.append("pub type {0}Borrowed<'a> = &'a {0};".format(ty))
|
||||||
if "servo_borrowed_mut_types" in current_target:
|
|
||||||
for ty in current_target["servo_borrowed_mut_types"]:
|
|
||||||
flags.append("-blacklist-type")
|
flags.append("-blacklist-type")
|
||||||
flags.append("{}BorrowedMut".format(ty))
|
flags.append("{}BorrowedMut".format(ty))
|
||||||
flags.append("-raw-line")
|
flags.append("-raw-line")
|
||||||
flags.append("pub type {0}BorrowedMut<'a> = &'a mut {0};".format(ty))
|
flags.append("pub type {0}BorrowedMut<'a> = &'a mut {0};".format(ty))
|
||||||
|
flags.append("-blacklist-type")
|
||||||
|
flags.append("{}Owned".format(ty))
|
||||||
|
flags.append("-raw-line")
|
||||||
|
flags.append("pub type {0}Owned = ::sugar::refptr::Owned<{0}>;".format(ty))
|
||||||
if "structs_types" in current_target:
|
if "structs_types" in current_target:
|
||||||
for ty in current_target["structs_types"]:
|
for ty in current_target["structs_types"]:
|
||||||
ty_fragments = ty.split("::")
|
ty_fragments = ty.split("::")
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use euclid::size::TypedSize2D;
|
use euclid::size::TypedSize2D;
|
||||||
use gecko_bindings::bindings::RawServoStyleSet;
|
use gecko_bindings::bindings::RawServoStyleSet;
|
||||||
use gecko_bindings::sugar::refptr::{HasSimpleFFI, HasFFI};
|
use gecko_bindings::sugar::refptr::{HasBoxFFI, HasFFI, HasSimpleFFI};
|
||||||
use num_cpus;
|
use num_cpus;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -94,6 +94,7 @@ unsafe impl HasFFI for PerDocumentStyleData {
|
||||||
type FFIType = RawServoStyleSet;
|
type FFIType = RawServoStyleSet;
|
||||||
}
|
}
|
||||||
unsafe impl HasSimpleFFI for PerDocumentStyleData {}
|
unsafe impl HasSimpleFFI for PerDocumentStyleData {}
|
||||||
|
unsafe impl HasBoxFFI for PerDocumentStyleData {}
|
||||||
|
|
||||||
impl Drop for PerDocumentStyleData {
|
impl Drop for PerDocumentStyleData {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ pub type ServoDeclarationBlockStrong = ::sugar::refptr::Strong<ServoDeclarationB
|
||||||
pub type ServoDeclarationBlockBorrowed<'a> = ::sugar::refptr::Borrowed<'a, ServoDeclarationBlock>;
|
pub type ServoDeclarationBlockBorrowed<'a> = ::sugar::refptr::Borrowed<'a, ServoDeclarationBlock>;
|
||||||
pub type RawServoStyleSetBorrowed<'a> = &'a RawServoStyleSet;
|
pub type RawServoStyleSetBorrowed<'a> = &'a RawServoStyleSet;
|
||||||
pub type RawServoStyleSetBorrowedMut<'a> = &'a mut RawServoStyleSet;
|
pub type RawServoStyleSetBorrowedMut<'a> = &'a mut RawServoStyleSet;
|
||||||
|
pub type RawServoStyleSetOwned = ::sugar::refptr::Owned<RawServoStyleSet>;
|
||||||
use structs::nsStyleFont;
|
use structs::nsStyleFont;
|
||||||
unsafe impl Send for nsStyleFont {}
|
unsafe impl Send for nsStyleFont {}
|
||||||
unsafe impl Sync for nsStyleFont {}
|
unsafe impl Sync for nsStyleFont {}
|
||||||
|
@ -472,9 +473,9 @@ extern "C" {
|
||||||
pub fn Servo_StyleSheet_Release(sheet: RawServoStyleSheetBorrowed);
|
pub fn Servo_StyleSheet_Release(sheet: RawServoStyleSheetBorrowed);
|
||||||
pub fn Servo_StyleSheet_HasRules(sheet: RawServoStyleSheetBorrowed)
|
pub fn Servo_StyleSheet_HasRules(sheet: RawServoStyleSheetBorrowed)
|
||||||
-> bool;
|
-> bool;
|
||||||
pub fn Servo_StyleSet_Init() -> *mut RawServoStyleSet;
|
pub fn Servo_StyleSet_Init() -> RawServoStyleSetOwned;
|
||||||
pub fn Servo_StyleSet_Drop(set: *mut RawServoStyleSet);
|
pub fn Servo_StyleSet_Drop(set: RawServoStyleSetOwned);
|
||||||
pub fn Servo_StyleSet_AppendStyleSheet(set: *mut RawServoStyleSet,
|
pub fn Servo_StyleSet_AppendStyleSheet(set: RawServoStyleSetBorrowedMut,
|
||||||
sheet: RawServoStyleSheetBorrowed);
|
sheet: RawServoStyleSheetBorrowed);
|
||||||
pub fn Servo_StyleSet_PrependStyleSheet(set: RawServoStyleSetBorrowedMut,
|
pub fn Servo_StyleSet_PrependStyleSheet(set: RawServoStyleSetBorrowedMut,
|
||||||
sheet:
|
sheet:
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::mem::{forget, transmute};
|
use std::mem::{forget, transmute};
|
||||||
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -32,6 +33,14 @@ pub unsafe trait HasSimpleFFI : HasFFI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Indicates that the given Servo type is passed over FFI
|
||||||
|
/// as a Box
|
||||||
|
pub unsafe trait HasBoxFFI : HasSimpleFFI {
|
||||||
|
fn into_ffi(self: Box<Self>) -> Owned<Self::FFIType> {
|
||||||
|
unsafe { transmute(self) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Helper trait for conversions between FFI Strong/Borrowed types and Arcs
|
/// Helper trait for conversions between FFI Strong/Borrowed types and Arcs
|
||||||
///
|
///
|
||||||
/// Should be implemented by types which are passed over FFI as Arcs
|
/// Should be implemented by types which are passed over FFI as Arcs
|
||||||
|
@ -138,3 +147,30 @@ unsafe impl<T: HasArcFFI> FFIArcHelpers for Arc<T> {
|
||||||
unsafe { ptr::read(borrowedptr) }
|
unsafe { ptr::read(borrowedptr) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
/// Gecko-FFI-safe owned pointer
|
||||||
|
/// Cannot be null
|
||||||
|
pub struct Owned<T> {
|
||||||
|
ptr: *mut T,
|
||||||
|
_marker: PhantomData<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Owned<T> {
|
||||||
|
pub fn into_box<U>(self) -> Box<T> where U: HasBoxFFI<FFIType = T> {
|
||||||
|
unsafe { transmute(self) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Deref for Owned<T> {
|
||||||
|
type Target = T;
|
||||||
|
fn deref(&self) -> &T {
|
||||||
|
unsafe { &*self.ptr }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> DerefMut for Owned<T> {
|
||||||
|
fn deref_mut(&mut self) -> &mut T {
|
||||||
|
unsafe { &mut *self.ptr }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ use env_logger;
|
||||||
use euclid::Size2D;
|
use euclid::Size2D;
|
||||||
use gecko_bindings::bindings::{RawGeckoDocument, RawGeckoElement, RawGeckoNode};
|
use gecko_bindings::bindings::{RawGeckoDocument, RawGeckoElement, RawGeckoNode};
|
||||||
use gecko_bindings::bindings::{RawServoStyleSet, RawServoStyleSetBorrowedMut};
|
use gecko_bindings::bindings::{RawServoStyleSet, RawServoStyleSetBorrowedMut};
|
||||||
|
use gecko_bindings::bindings::RawServoStyleSetOwned;
|
||||||
use gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
|
use gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
|
||||||
use gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
|
use gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
|
||||||
use gecko_bindings::bindings::{ServoDeclarationBlock, ServoNodeData, ThreadSafePrincipalHolder};
|
use gecko_bindings::bindings::{ServoDeclarationBlock, ServoNodeData, ThreadSafePrincipalHolder};
|
||||||
|
@ -19,7 +20,8 @@ use gecko_bindings::ptr::{GeckoArcPrincipal, GeckoArcURI};
|
||||||
use gecko_bindings::structs::ServoElementSnapshot;
|
use gecko_bindings::structs::ServoElementSnapshot;
|
||||||
use gecko_bindings::structs::nsRestyleHint;
|
use gecko_bindings::structs::nsRestyleHint;
|
||||||
use gecko_bindings::structs::{SheetParsingMode, nsIAtom};
|
use gecko_bindings::structs::{SheetParsingMode, nsIAtom};
|
||||||
use gecko_bindings::sugar::refptr::{FFIArcHelpers, HasArcFFI, HasSimpleFFI, HasFFI, Strong};
|
use gecko_bindings::sugar::refptr::{FFIArcHelpers, HasArcFFI, HasBoxFFI};
|
||||||
|
use gecko_bindings::sugar::refptr::{HasSimpleFFI, HasFFI, Strong};
|
||||||
use gecko_string_cache::Atom;
|
use gecko_string_cache::Atom;
|
||||||
use snapshot::GeckoElementSnapshot;
|
use snapshot::GeckoElementSnapshot;
|
||||||
use std::mem::transmute;
|
use std::mem::transmute;
|
||||||
|
@ -336,16 +338,14 @@ pub extern "C" fn Servo_ComputedValues_Release(ptr: ServoComputedValuesBorrowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_StyleSet_Init() -> *mut RawServoStyleSet {
|
pub extern "C" fn Servo_StyleSet_Init() -> RawServoStyleSetOwned {
|
||||||
let data = Box::new(PerDocumentStyleData::new());
|
let data = Box::new(PerDocumentStyleData::new());
|
||||||
Box::into_raw(data) as *mut RawServoStyleSet
|
data.into_ffi()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_StyleSet_Drop(data: *mut RawServoStyleSet) -> () {
|
pub extern "C" fn Servo_StyleSet_Drop(data: RawServoStyleSetOwned) -> () {
|
||||||
unsafe {
|
let _ = data.into_box::<PerDocumentStyleData>();
|
||||||
let _ = Box::<PerDocumentStyleData>::from_raw(data as *mut PerDocumentStyleData);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GeckoDeclarationBlock {
|
pub struct GeckoDeclarationBlock {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue