mirror of
https://github.com/servo/servo.git
synced 2025-08-11 16:35:33 +01:00
style: Remove HasArcFFI for AnimationValue
See previous patches for context. Differential Revision: https://phabricator.services.mozilla.com/D177622
This commit is contained in:
parent
779aa9d30e
commit
9370172552
3 changed files with 56 additions and 71 deletions
|
@ -10,12 +10,12 @@
|
|||
|
||||
use crate::gecko::url::CssUrlData;
|
||||
use crate::gecko_bindings::structs::{
|
||||
RawServoAnimationValue, RawServoContainerRule, RawServoCounterStyleRule,
|
||||
RawServoDeclarationBlock, RawServoFontFaceRule, RawServoFontFeatureValuesRule,
|
||||
RawServoFontPaletteValuesRule, RawServoImportRule, RawServoKeyframe, RawServoKeyframesRule,
|
||||
RawServoLayerBlockRule, RawServoLayerStatementRule, RawServoMediaList, RawServoMediaRule,
|
||||
RawServoMozDocumentRule, RawServoNamespaceRule, RawServoPageRule, RawServoStyleRule,
|
||||
RawServoSupportsRule, ServoCssRules,
|
||||
RawServoContainerRule, RawServoCounterStyleRule, RawServoDeclarationBlock,
|
||||
RawServoFontFaceRule, RawServoFontFeatureValuesRule, RawServoFontPaletteValuesRule,
|
||||
RawServoImportRule, RawServoKeyframe, RawServoKeyframesRule, RawServoLayerBlockRule,
|
||||
RawServoLayerStatementRule, RawServoMediaList, RawServoMediaRule, RawServoMozDocumentRule,
|
||||
RawServoNamespaceRule, RawServoPageRule, RawServoStyleRule, RawServoSupportsRule,
|
||||
ServoCssRules,
|
||||
};
|
||||
use crate::gecko_bindings::sugar::ownership::HasArcFFI;
|
||||
use crate::media_queries::MediaList;
|
||||
|
@ -60,9 +60,6 @@ impl_arc_ffi!(Locked<StyleRule> => RawServoStyleRule
|
|||
impl_arc_ffi!(Locked<ImportRule> => RawServoImportRule
|
||||
[Servo_ImportRule_AddRef, Servo_ImportRule_Release]);
|
||||
|
||||
impl_arc_ffi!(AnimationValue => RawServoAnimationValue
|
||||
[Servo_AnimationValue_AddRef, Servo_AnimationValue_Release]);
|
||||
|
||||
impl_arc_ffi!(Locked<Keyframe> => RawServoKeyframe
|
||||
[Servo_Keyframe_AddRef, Servo_Keyframe_Release]);
|
||||
|
||||
|
@ -137,3 +134,8 @@ impl_simple_arc_ffi!(
|
|||
Servo_ComputedStyle_AddRef,
|
||||
Servo_ComputedStyle_Release
|
||||
);
|
||||
impl_simple_arc_ffi!(
|
||||
AnimationValue,
|
||||
Servo_AnimationValue_AddRef,
|
||||
Servo_AnimationValue_Release
|
||||
);
|
||||
|
|
|
@ -825,14 +825,12 @@ impl<'le> GeckoElement<'le> {
|
|||
let mut map = FxHashMap::with_capacity_and_hasher(collection_length, Default::default());
|
||||
|
||||
for i in 0..collection_length {
|
||||
let raw_end_value = unsafe { Gecko_ElementTransitions_EndValueAt(self.0, i).as_ref() };
|
||||
|
||||
let end_value = AnimationValue::arc_from_borrowed(&raw_end_value)
|
||||
.expect("AnimationValue not found in ElementTransitions");
|
||||
|
||||
let end_value = unsafe {
|
||||
Arc::from_raw_addrefed(Gecko_ElementTransitions_EndValueAt(self.0, i))
|
||||
};
|
||||
let property = end_value.id();
|
||||
debug_assert!(!property.is_logical());
|
||||
map.insert(property, end_value.clone_arc());
|
||||
map.insert(property, end_value);
|
||||
}
|
||||
map
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::gecko_bindings::{bindings, structs};
|
|||
use crate::Atom;
|
||||
use servo_arc::Arc;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::ops::Deref;
|
||||
use std::{fmt, mem, ptr};
|
||||
use std::fmt::Write;
|
||||
|
||||
|
@ -40,18 +40,6 @@ impl<T: RefCounted> fmt::Debug for RefPtr<T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// A RefPtr that we know is uniquely owned.
|
||||
///
|
||||
/// This is basically Box<T>, with the additional guarantee that the box can be
|
||||
/// safely interpreted as a RefPtr<T> (with refcount 1)
|
||||
///
|
||||
/// This is useful when you wish to create a refptr and mutate it temporarily,
|
||||
/// while it is still uniquely owned.
|
||||
pub struct UniqueRefPtr<T: RefCounted>(RefPtr<T>);
|
||||
|
||||
// There is no safe conversion from &T to RefPtr<T> (like Gecko has)
|
||||
// because this lets you break UniqueRefPtr's guarantee
|
||||
|
||||
impl<T: RefCounted> RefPtr<T> {
|
||||
/// Create a new RefPtr from an already addrefed pointer obtained from FFI.
|
||||
///
|
||||
|
@ -59,7 +47,7 @@ impl<T: RefCounted> RefPtr<T> {
|
|||
pub unsafe fn from_addrefed(ptr: *mut T) -> Self {
|
||||
debug_assert!(!ptr.is_null());
|
||||
RefPtr {
|
||||
ptr: ptr,
|
||||
ptr,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
@ -125,23 +113,6 @@ impl<T: RefCounted> RefPtr<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: RefCounted> UniqueRefPtr<T> {
|
||||
/// Create a unique refptr from an already addrefed pointer obtained from
|
||||
/// FFI.
|
||||
///
|
||||
/// The refcount must be one.
|
||||
///
|
||||
/// The pointer must be valid and non null
|
||||
pub unsafe fn from_addrefed(ptr: *mut T) -> Self {
|
||||
UniqueRefPtr(RefPtr::from_addrefed(ptr))
|
||||
}
|
||||
|
||||
/// Convert to a RefPtr so that it can be used.
|
||||
pub fn get(self) -> RefPtr<T> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: RefCounted> Deref for RefPtr<T> {
|
||||
type Target = T;
|
||||
fn deref(&self) -> &T {
|
||||
|
@ -150,19 +121,6 @@ impl<T: RefCounted> Deref for RefPtr<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: RefCounted> Deref for UniqueRefPtr<T> {
|
||||
type Target = T;
|
||||
fn deref(&self) -> &T {
|
||||
unsafe { &*self.0.ptr }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: RefCounted> DerefMut for UniqueRefPtr<T> {
|
||||
fn deref_mut(&mut self) -> &mut T {
|
||||
unsafe { &mut *self.0.ptr }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: RefCounted> structs::RefPtr<T> {
|
||||
/// Produces a Rust-side RefPtr from an FFI RefPtr, bumping the refcount.
|
||||
///
|
||||
|
@ -226,24 +184,51 @@ impl<T: RefCounted> structs::RefPtr<T> {
|
|||
}
|
||||
|
||||
impl<T> structs::RefPtr<T> {
|
||||
/// Sets the contents to an `Arc<T>`, releasing the old value in `self` if
|
||||
/// necessary.
|
||||
pub fn set_arc<U>(&mut self, other: Arc<U>)
|
||||
/// Returns a new, null refptr.
|
||||
pub fn null() -> Self {
|
||||
Self {
|
||||
mRawPtr: ptr::null_mut(),
|
||||
_phantom_0: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new RefPtr from an arc.
|
||||
pub fn from_arc(s: Arc<T>) -> Self {
|
||||
Self {
|
||||
mRawPtr: Arc::into_raw(s) as *mut _,
|
||||
_phantom_0: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new RefPtr from an arc.
|
||||
pub fn from_arc_ffi<U>(s: Arc<U>) -> Self
|
||||
where
|
||||
U: HasArcFFI<FFIType = T>,
|
||||
{
|
||||
Self {
|
||||
mRawPtr: unsafe { mem::transmute(Arc::into_raw_offset(s)) },
|
||||
_phantom_0: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the contents to an Arc<T>.
|
||||
pub fn set_arc(&mut self, other: Arc<T>) {
|
||||
unsafe {
|
||||
if !self.mRawPtr.is_null() {
|
||||
let _ = Arc::from_raw(self.mRawPtr);
|
||||
}
|
||||
self.mRawPtr = Arc::into_raw(other) as *mut _;
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the contents to an Arc<U>.
|
||||
pub fn set_arc_ffi<U>(&mut self, other: Arc<U>)
|
||||
where
|
||||
U: HasArcFFI<FFIType = T>,
|
||||
{
|
||||
unsafe {
|
||||
U::release_opt(self.mRawPtr.as_ref());
|
||||
}
|
||||
self.set_arc_leaky(other);
|
||||
}
|
||||
|
||||
/// Sets the contents to an Arc<T>
|
||||
/// will leak existing contents
|
||||
pub fn set_arc_leaky<U>(&mut self, other: Arc<U>)
|
||||
where
|
||||
U: HasArcFFI<FFIType = T>,
|
||||
{
|
||||
*self = unsafe { mem::transmute(Arc::into_raw_offset(other)) };
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue