stylo: Remove usage of ServoComputedValues from binding functions

This commit is contained in:
Manish Goregaokar 2017-07-18 23:17:34 -07:00 committed by Manish Goregaokar
parent 9776d070ea
commit 3c3e4399da
7 changed files with 71 additions and 46 deletions

View file

@ -13,13 +13,14 @@ use gecko_bindings::bindings::{RawServoKeyframe, RawServoKeyframesRule};
use gecko_bindings::bindings::{RawServoMediaRule, RawServoNamespaceRule, RawServoPageRule};
use gecko_bindings::bindings::{RawServoRuleNode, RawServoRuleNodeStrong, RawServoDocumentRule};
use gecko_bindings::bindings::ServoCssRules;
use gecko_bindings::structs::{RawServoAnimationValue, RawServoDeclarationBlock, RawServoStyleRule, RawServoMediaList};
use gecko_bindings::structs::{RawServoStyleSheetContents, ServoStyleContext};
use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI};
use gecko_bindings::structs::{RawServoAnimationValue, RawServoDeclarationBlock, RawServoStyleRule};
use gecko_bindings::structs::{RawServoMediaList, RawServoStyleSheetContents};
use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI, Strong};
use media_queries::MediaList;
use properties::{ComputedValues, PropertyDeclarationBlock};
use properties::animated_properties::AnimationValue;
use rule_tree::StrongRuleNode;
use servo_arc::{Arc, ArcBorrow};
use shared_lock::Locked;
use std::{mem, ptr};
use stylesheets::{CssRules, StylesheetContents, StyleRule, ImportRule, KeyframesRule, MediaRule};
@ -51,9 +52,6 @@ impl_arc_ffi!(Locked<CssRules> => ServoCssRules
impl_arc_ffi!(StylesheetContents => RawServoStyleSheetContents
[Servo_StyleSheetContents_AddRef, Servo_StyleSheetContents_Release]);
impl_arc_ffi!(ComputedValues => ServoStyleContext
[Servo_StyleContext_AddRef, Servo_StyleContext_Release]);
impl_arc_ffi!(Locked<PropertyDeclarationBlock> => RawServoDeclarationBlock
[Servo_DeclarationBlock_AddRef, Servo_DeclarationBlock_Release]);
@ -114,3 +112,28 @@ pub unsafe extern "C" fn Servo_RuleNode_Release(obj: &RawServoRuleNode) {
let ptr = StrongRuleNode::from_ffi(&obj);
ptr::read(ptr as *const StrongRuleNode);
}
// ServoStyleContext is not an opaque type on any side of FFI.
// This means that doing the HasArcFFI type trick is actually unsound,
// since it gives us a way to construct an Arc<ServoStyleContext> from
// an &ServoStyleContext, which in general is not allowed. So we
// implement the restricted set of arc type functionality we need.
#[no_mangle]
pub unsafe extern "C" fn Servo_StyleContext_AddRef(obj: &ComputedValues) {
mem::forget(ArcBorrow::from_ref(obj).clone_arc());
}
#[no_mangle]
pub unsafe extern "C" fn Servo_StyleContext_Release(obj: &ComputedValues) {
ArcBorrow::from_ref(obj).with_arc(|a: &Arc<ComputedValues>| {
let _: Arc<ComputedValues> = ptr::read(a);
});
}
impl From<Arc<ComputedValues>> for Strong<ComputedValues> {
fn from(arc: Arc<ComputedValues>) -> Self {
unsafe { mem::transmute(Arc::into_raw_offset(arc)) }
}
}

View file

@ -5,7 +5,7 @@ use gecko_bindings::structs::nsStyleTransformMatrix;
use gecko_bindings::structs::nsTArray;
type nsACString_internal = nsACString;
type nsAString_internal = nsAString;
pub type ServoStyleContextBorrowed<'a> = &'a ServoStyleContext;
pub type ServoStyleContextBorrowed<'a> = &'a ::properties::ComputedValues;
pub type ServoStyleContextBorrowedOrNull<'a> = Option<&'a ::properties::ComputedValues>;
pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues;
pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>;
@ -2322,7 +2322,7 @@ extern "C" {
}
extern "C" {
pub fn Servo_ComputedValues_SpecifiesAnimationsOrTransitions(computed_values:
ServoComputedValuesBorrowed)
ServoStyleContextBorrowed)
-> bool;
}
extern "C" {
@ -2705,7 +2705,7 @@ extern "C" {
}
extern "C" {
pub fn Servo_ComputedValues_GetStyleBits(values:
ServoComputedValuesBorrowed)
ServoStyleContextBorrowed)
-> u64;
}
extern "C" {
@ -2717,7 +2717,7 @@ extern "C" {
}
extern "C" {
pub fn Servo_ComputedValues_GetStyleRuleList(values:
ServoComputedValuesBorrowed,
ServoStyleContextBorrowed,
rules:
RawGeckoServoStyleRuleListBorrowedMut);
}
@ -2804,17 +2804,17 @@ extern "C" {
}
extern "C" {
pub fn Servo_GetCustomPropertyValue(computed_values:
ServoComputedValuesBorrowed,
ServoStyleContextBorrowed,
name: *const nsAString,
value: *mut nsAString) -> bool;
}
extern "C" {
pub fn Servo_GetCustomPropertiesCount(computed_values:
ServoComputedValuesBorrowed)
ServoStyleContextBorrowed)
-> u32;
}
extern "C" {
pub fn Servo_GetCustomPropertyNameAt(arg1: ServoComputedValuesBorrowed,
pub fn Servo_GetCustomPropertyNameAt(arg1: ServoStyleContextBorrowed,
index: u32, name: *mut nsAString)
-> bool;
}

View file

@ -16,7 +16,7 @@ pub type ServoRuleNode = Option<::rule_tree::StrongRuleNode>;
pub type ServoVisitedStyle = Option<::servo_arc::RawOffsetArc<::properties::ComputedValues>>;
pub type ServoComputedValueFlags = ::properties::computed_value_flags::ComputedValueFlags;
pub type ServoRawOffsetArc<T> = ::servo_arc::RawOffsetArc<T>;
pub type ServoStyleContextStrong = ::gecko_bindings::sugar::ownership::Strong<ServoStyleContext>;
pub type ServoStyleContextStrong = ::gecko_bindings::sugar::ownership::Strong<::properties::ComputedValues>;
#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
pub mod root {

View file

@ -16,7 +16,7 @@ pub type ServoRuleNode = Option<::rule_tree::StrongRuleNode>;
pub type ServoVisitedStyle = Option<::servo_arc::RawOffsetArc<::properties::ComputedValues>>;
pub type ServoComputedValueFlags = ::properties::computed_value_flags::ComputedValueFlags;
pub type ServoRawOffsetArc<T> = ::servo_arc::RawOffsetArc<T>;
pub type ServoStyleContextStrong = ::gecko_bindings::sugar::ownership::Strong<ServoStyleContext>;
pub type ServoStyleContextStrong = ::gecko_bindings::sugar::ownership::Strong<::properties::ComputedValues>;
#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
pub mod root {