aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXidorn Quan <me@upsuper.org>2017-02-22 18:21:04 +1100
committerXidorn Quan <me@upsuper.org>2017-02-23 10:22:39 +1100
commit0cac27689197b112b68effc330f5e101dc5b5fa4 (patch)
treee450e319e02926880bb87b89afd423ff1a3645ac
parent07debf5dc02e48ede1652100377a4c51979ca7e6 (diff)
downloadservo-0cac27689197b112b68effc330f5e101dc5b5fa4.tar.gz
servo-0cac27689197b112b68effc330f5e101dc5b5fa4.zip
Simplify defining arc ffi types
-rw-r--r--components/style/gecko/arc_types.rs58
-rw-r--r--components/style/gecko/conversions.rs37
-rw-r--r--components/style/gecko/mod.rs1
-rw-r--r--components/style/properties/helpers/animated_properties.mako.rs11
-rw-r--r--ports/geckolib/glue.rs71
-rwxr-xr-xtests/unit/stylo/check_bindings.py1
6 files changed, 61 insertions, 118 deletions
diff --git a/components/style/gecko/arc_types.rs b/components/style/gecko/arc_types.rs
new file mode 100644
index 00000000000..72f044c1c71
--- /dev/null
+++ b/components/style/gecko/arc_types.rs
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+//! This file lists all arc FFI types and defines corresponding addref
+//! and release functions. This list corresponds to ServoArcTypeList.h
+//! file in Gecko.
+
+#![allow(non_snake_case, missing_docs)]
+
+use gecko_bindings::bindings::{RawServoStyleSheet, RawServoStyleRule, RawServoImportRule};
+use gecko_bindings::bindings::{ServoComputedValues, ServoCssRules};
+use gecko_bindings::structs::{RawServoAnimationValue, RawServoDeclarationBlock};
+use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI};
+use parking_lot::RwLock;
+use properties::{ComputedValues, PropertyDeclarationBlock};
+use properties::animated_properties::AnimationValue;
+use stylesheets::{CssRules, Stylesheet, StyleRule, ImportRule};
+
+macro_rules! impl_arc_ffi {
+ ($servo_type:ty => $gecko_type:ty [$addref:ident, $release:ident]) => {
+ unsafe impl HasFFI for $servo_type {
+ type FFIType = $gecko_type;
+ }
+ unsafe impl HasArcFFI for $servo_type {}
+
+ #[no_mangle]
+ pub unsafe extern "C" fn $addref(obj: &$gecko_type) -> () {
+ <$servo_type>::addref(obj);
+ }
+
+ #[no_mangle]
+ pub unsafe extern "C" fn $release(obj: &$gecko_type) -> () {
+ <$servo_type>::release(obj);
+ }
+ }
+}
+
+impl_arc_ffi!(RwLock<CssRules> => ServoCssRules
+ [Servo_CssRules_AddRef, Servo_CssRules_Release]);
+
+impl_arc_ffi!(Stylesheet => RawServoStyleSheet
+ [Servo_StyleSheet_AddRef, Servo_StyleSheet_Release]);
+
+impl_arc_ffi!(ComputedValues => ServoComputedValues
+ [Servo_ComputedValues_AddRef, Servo_ComputedValues_Release]);
+
+impl_arc_ffi!(RwLock<PropertyDeclarationBlock> => RawServoDeclarationBlock
+ [Servo_DeclarationBlock_AddRef, Servo_DeclarationBlock_Release]);
+
+impl_arc_ffi!(RwLock<StyleRule> => RawServoStyleRule
+ [Servo_StyleRule_AddRef, Servo_StyleRule_Release]);
+
+impl_arc_ffi!(RwLock<ImportRule> => RawServoImportRule
+ [Servo_ImportRule_AddRef, Servo_ImportRule_Release]);
+
+impl_arc_ffi!(AnimationValue => RawServoAnimationValue
+ [Servo_AnimationValue_AddRef, Servo_AnimationValue_Release]);
diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs
index 7262a2f7f85..a88d7c66d95 100644
--- a/components/style/gecko/conversions.rs
+++ b/components/style/gecko/conversions.rs
@@ -11,47 +11,12 @@
use app_units::Au;
use gecko::values::convert_rgba_to_nscolor;
use gecko_bindings::bindings::{Gecko_CreateGradient, Gecko_SetGradientImageValue, Gecko_SetUrlImageValue};
-use gecko_bindings::bindings::{RawServoStyleSheet, RawServoStyleRule, RawServoImportRule};
-use gecko_bindings::bindings::{ServoComputedValues, ServoCssRules};
use gecko_bindings::structs::{nsStyleCoord_CalcValue, nsStyleImage};
-use gecko_bindings::structs::RawServoDeclarationBlock;
use gecko_bindings::structs::nsresult;
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut};
-use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI};
-use parking_lot::RwLock;
-use properties::{ComputedValues, PropertyDeclarationBlock};
-use stylesheets::{CssRules, RulesMutateError, Stylesheet, StyleRule, ImportRule};
+use stylesheets::RulesMutateError;
use values::computed::{CalcLengthOrPercentage, Gradient, Image, LengthOrPercentage, LengthOrPercentageOrAuto};
-unsafe impl HasFFI for Stylesheet {
- type FFIType = RawServoStyleSheet;
-}
-unsafe impl HasArcFFI for Stylesheet {}
-unsafe impl HasFFI for ComputedValues {
- type FFIType = ServoComputedValues;
-}
-unsafe impl HasArcFFI for ComputedValues {}
-
-unsafe impl HasFFI for RwLock<PropertyDeclarationBlock> {
- type FFIType = RawServoDeclarationBlock;
-}
-unsafe impl HasArcFFI for RwLock<PropertyDeclarationBlock> {}
-
-unsafe impl HasFFI for RwLock<CssRules> {
- type FFIType = ServoCssRules;
-}
-unsafe impl HasArcFFI for RwLock<CssRules> {}
-
-unsafe impl HasFFI for RwLock<StyleRule> {
- type FFIType = RawServoStyleRule;
-}
-unsafe impl HasArcFFI for RwLock<StyleRule> {}
-
-unsafe impl HasFFI for RwLock<ImportRule> {
- type FFIType = RawServoImportRule;
-}
-unsafe impl HasArcFFI for RwLock<ImportRule> {}
-
impl From<CalcLengthOrPercentage> for nsStyleCoord_CalcValue {
fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue {
let has_percentage = other.percentage.is_some();
diff --git a/components/style/gecko/mod.rs b/components/style/gecko/mod.rs
index ca87d081ef7..625fa77bbfd 100644
--- a/components/style/gecko/mod.rs
+++ b/components/style/gecko/mod.rs
@@ -4,6 +4,7 @@
//! Gecko-specific style-system bits.
+pub mod arc_types;
pub mod conversions;
pub mod data;
pub mod media_queries;
diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs
index 3c05fc06e31..209f3ec86bc 100644
--- a/components/style/properties/helpers/animated_properties.mako.rs
+++ b/components/style/properties/helpers/animated_properties.mako.rs
@@ -232,17 +232,6 @@ impl AnimatedProperty {
}
}
-
-% if product == "gecko":
- use gecko_bindings::structs::RawServoAnimationValue;
- use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI};
-
- unsafe impl HasFFI for AnimationValue {
- type FFIType = RawServoAnimationValue;
- }
- unsafe impl HasArcFFI for AnimationValue {}
-% endif
-
/// An enum to represent a single computed value belonging to an animated
/// property in order to be interpolated with another one. When interpolating,
/// both values need to belong to the same property.
diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs
index 54aac9b4694..ac590088932 100644
--- a/ports/geckolib/glue.rs
+++ b/ports/geckolib/glue.rs
@@ -332,17 +332,6 @@ pub extern "C" fn Servo_AnimationValues_Populate(anim: RawGeckoAnimationValueLis
}
}
-
-#[no_mangle]
-pub extern "C" fn Servo_AnimationValue_AddRef(anim: RawServoAnimationValueBorrowed) -> () {
- unsafe { AnimationValue::addref(anim) };
-}
-
-#[no_mangle]
-pub extern "C" fn Servo_AnimationValue_Release(anim: RawServoAnimationValueBorrowed) -> () {
- unsafe { AnimationValue::release(anim) };
-}
-
#[no_mangle]
pub extern "C" fn Servo_StyleWorkerThreadCount() -> u32 {
*NUM_THREADS as u32
@@ -531,16 +520,6 @@ pub extern "C" fn Servo_StyleSheet_GetRules(sheet: RawServoStyleSheetBorrowed) -
}
#[no_mangle]
-pub extern "C" fn Servo_StyleSheet_AddRef(sheet: RawServoStyleSheetBorrowed) -> () {
- unsafe { Stylesheet::addref(sheet) };
-}
-
-#[no_mangle]
-pub extern "C" fn Servo_StyleSheet_Release(sheet: RawServoStyleSheetBorrowed) -> () {
- unsafe { Stylesheet::release(sheet) };
-}
-
-#[no_mangle]
pub extern "C" fn Servo_CssRules_ListTypes(rules: ServoCssRulesBorrowed,
result: nsTArrayBorrowed_uintptr_t) -> () {
let rules = RwLock::<CssRules>::as_arc(&rules).read();
@@ -589,26 +568,6 @@ pub extern "C" fn Servo_CssRules_DeleteRule(rules: ServoCssRulesBorrowed, index:
}
#[no_mangle]
-pub extern "C" fn Servo_CssRules_AddRef(rules: ServoCssRulesBorrowed) -> () {
- unsafe { RwLock::<CssRules>::addref(rules) };
-}
-
-#[no_mangle]
-pub extern "C" fn Servo_CssRules_Release(rules: ServoCssRulesBorrowed) -> () {
- unsafe { RwLock::<CssRules>::release(rules) };
-}
-
-#[no_mangle]
-pub extern "C" fn Servo_StyleRule_AddRef(rule: RawServoStyleRuleBorrowed) -> () {
- unsafe { RwLock::<StyleRule>::addref(rule) };
-}
-
-#[no_mangle]
-pub extern "C" fn Servo_StyleRule_Release(rule: RawServoStyleRuleBorrowed) -> () {
- unsafe { RwLock::<StyleRule>::release(rule) };
-}
-
-#[no_mangle]
pub extern "C" fn Servo_StyleRule_Debug(rule: RawServoStyleRuleBorrowed, result: *mut nsACString) -> () {
let rule = RwLock::<StyleRule>::as_arc(&rule);
let result = unsafe { result.as_mut().unwrap() };
@@ -642,16 +601,6 @@ pub extern "C" fn Servo_StyleRule_GetSelectorText(rule: RawServoStyleRuleBorrowe
}
#[no_mangle]
-pub extern "C" fn Servo_ImportRule_AddRef(rule: RawServoImportRuleBorrowed) -> () {
- unsafe { RwLock::<ImportRule>::addref(rule) };
-}
-
-#[no_mangle]
-pub extern "C" fn Servo_ImportRule_Release(rule: RawServoImportRuleBorrowed) -> () {
- unsafe { RwLock::<ImportRule>::release(rule) };
-}
-
-#[no_mangle]
pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null: ServoComputedValuesBorrowedOrNull,
pseudo_tag: *mut nsIAtom,
raw_data: RawServoStyleSetBorrowed)
@@ -727,16 +676,6 @@ pub extern "C" fn Servo_ComputedValues_Inherit(
style.into_strong()
}
-#[no_mangle]
-pub extern "C" fn Servo_ComputedValues_AddRef(ptr: ServoComputedValuesBorrowed) {
- unsafe { ComputedValues::addref(ptr) };
-}
-
-#[no_mangle]
-pub extern "C" fn Servo_ComputedValues_Release(ptr: ServoComputedValuesBorrowed) {
- unsafe { ComputedValues::release(ptr) };
-}
-
/// See the comment in `Device` to see why it's ok to pass an owned reference to
/// the pres context (hint: the context outlives the StyleSet, that holds the
/// device alive).
@@ -815,16 +754,6 @@ pub extern "C" fn Servo_DeclarationBlock_Clone(declarations: RawServoDeclaration
}
#[no_mangle]
-pub extern "C" fn Servo_DeclarationBlock_AddRef(declarations: RawServoDeclarationBlockBorrowed) {
- unsafe { RwLock::<PropertyDeclarationBlock>::addref(declarations) };
-}
-
-#[no_mangle]
-pub extern "C" fn Servo_DeclarationBlock_Release(declarations: RawServoDeclarationBlockBorrowed) {
- unsafe { RwLock::<PropertyDeclarationBlock>::release(declarations) };
-}
-
-#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_Equals(a: RawServoDeclarationBlockBorrowed,
b: RawServoDeclarationBlockBorrowed)
-> bool {
diff --git a/tests/unit/stylo/check_bindings.py b/tests/unit/stylo/check_bindings.py
index 28246639e57..db5a11cc3a7 100755
--- a/tests/unit/stylo/check_bindings.py
+++ b/tests/unit/stylo/check_bindings.py
@@ -33,5 +33,6 @@ with open(INPUT_FILE, "r") as bindings, open(OUTPUT_FILE, "w+") as tests:
tests.write("}\n")
with open(GLUE_FILE, "r") as glue, open(GLUE_OUTPUT_FILE, "w+") as glue_output:
+ glue_output.write("pub use style::gecko::arc_types::*;")
for line in glue:
glue_output.write(line.replace("pub extern \"C\" fn", "pub unsafe extern \"C\" fn"))