stylo: Store servo computed values for animation properties

MozReview-Commit-ID: IoQLN5tdIBw
This commit is contained in:
Manish Goregaokar 2016-11-30 17:34:54 -08:00 committed by Manish Goregaokar
parent f6940f686c
commit d87b710fdd
7 changed files with 275 additions and 22 deletions

View file

@ -108,7 +108,7 @@ mod bindings {
trait BuilderExt {
fn get_initial_builder(build_type: BuildType) -> Builder;
fn include<T: Into<String>>(self, file: T) -> Builder;
fn zero_size_type(self, ty: &str) -> Builder;
fn zero_size_type(self, ty: &str, structs_list: &[&str]) -> Builder;
fn borrowed_type(self, ty: &str) -> Builder;
fn mutable_borrowed_type(self, ty: &str) -> Builder;
}
@ -172,10 +172,14 @@ mod bindings {
// Not 100% sure of how safe this is, but it's what we're using
// in the XPCOM ffi too
// https://github.com/nikomatsakis/rust-memory-model/issues/2
fn zero_size_type(self, ty: &str) -> Builder {
self.hide_type(ty)
.raw_line(format!("enum {}Void {{ }}", ty))
.raw_line(format!("pub struct {0}({0}Void);", ty))
fn zero_size_type(self, ty: &str, structs_list: &[&str]) -> Builder {
if !structs_list.contains(&ty) {
self.hide_type(ty)
.raw_line(format!("enum {}Void {{ }}", ty))
.raw_line(format!("pub struct {0}({0}Void);", ty))
} else {
self
}
}
fn borrowed_type(self, ty: &str) -> Builder {
self.hide_type(format!("{}Borrowed", ty))
@ -222,6 +226,7 @@ mod bindings {
..CodegenConfig::nothing()
})
.header(add_include("nsStyleStruct.h"))
.header(add_include("mozilla/StyleAnimationValue.h"))
.include(add_include("gfxFontConstants.h"))
.include(add_include("nsThemeConstants.h"))
.include(add_include("mozilla/dom/AnimationEffectReadOnlyBinding.h"))
@ -255,6 +260,7 @@ mod bindings {
"mozilla::CSSPseudoClassType",
"mozilla::css::SheetParsingMode",
"mozilla::HalfCorner",
"mozilla::PropertyStyleAnimationValuePair",
"mozilla::TraversalRootBehavior",
"mozilla::DisplayItemClip", // Needed because bindgen generates
// specialization tests for this even
@ -398,7 +404,10 @@ mod bindings {
"gfxSize", // <- union { struct { T width; T height; }; T components[2] };
"gfxSize_Super", // Ditto.
"mozilla::ErrorResult", // Causes JSWhyMagic to be included & handled incorrectly.
"mozilla::StyleAnimationValue",
"StyleAnimationValue", // pulls in a whole bunch of stuff we don't need in the bindings
];
struct MappedGenericType {
generic: bool,
gecko: &'static str,
@ -468,6 +477,8 @@ mod bindings {
"RawGeckoDocument",
"RawGeckoElement",
"RawGeckoNode",
"RawGeckoAnimationValueList",
"RawServoAnimationValue",
"RawGeckoPresContext",
"ThreadSafeURIHolder",
"ThreadSafePrincipalHolder",
@ -547,6 +558,7 @@ mod bindings {
"RawServoDeclarationBlock",
"RawServoStyleRule",
"RawServoImportRule",
"RawServoAnimationValue",
];
struct ServoOwnedType {
name: &'static str,
@ -566,6 +578,7 @@ mod bindings {
];
let servo_borrow_types = [
"nsCSSValue",
"RawGeckoAnimationValueList",
];
for &ty in structs_types.iter() {
builder = builder.hide_type(ty)
@ -588,7 +601,7 @@ mod bindings {
.hide_type(format!("{}Strong", ty))
.raw_line(format!("pub type {0}Strong = ::gecko_bindings::sugar::ownership::Strong<{0}>;", ty))
.borrowed_type(ty)
.zero_size_type(ty);
.zero_size_type(ty, &structs_types);
}
for &ServoOwnedType { name, opaque } in servo_owned_types.iter() {
builder = builder
@ -599,7 +612,7 @@ mod bindings {
name))
.mutable_borrowed_type(name);
if opaque {
builder = builder.zero_size_type(name);
builder = builder.zero_size_type(name, &structs_types);
}
}
for &ty in servo_immutable_borrow_types.iter() {

View file

@ -6,6 +6,8 @@ type nsAString_internal = nsAString;
use gecko_bindings::structs::RawGeckoDocument;
use gecko_bindings::structs::RawGeckoElement;
use gecko_bindings::structs::RawGeckoNode;
use gecko_bindings::structs::RawGeckoAnimationValueList;
use gecko_bindings::structs::RawServoAnimationValue;
use gecko_bindings::structs::RawGeckoPresContext;
use gecko_bindings::structs::ThreadSafeURIHolder;
use gecko_bindings::structs::ThreadSafePrincipalHolder;
@ -177,6 +179,9 @@ pub type RawServoImportRuleBorrowed<'a> = &'a RawServoImportRule;
pub type RawServoImportRuleBorrowedOrNull<'a> = Option<&'a RawServoImportRule>;
enum RawServoImportRuleVoid { }
pub struct RawServoImportRule(RawServoImportRuleVoid);
pub type RawServoAnimationValueStrong = ::gecko_bindings::sugar::ownership::Strong<RawServoAnimationValue>;
pub type RawServoAnimationValueBorrowed<'a> = &'a RawServoAnimationValue;
pub type RawServoAnimationValueBorrowedOrNull<'a> = Option<&'a RawServoAnimationValue>;
pub type RawServoStyleSetOwned = ::gecko_bindings::sugar::ownership::Owned<RawServoStyleSet>;
pub type RawServoStyleSetOwnedOrNull = ::gecko_bindings::sugar::ownership::OwnedOrNull<RawServoStyleSet>;
pub type RawServoStyleSetBorrowed<'a> = &'a RawServoStyleSet;
@ -213,7 +218,19 @@ pub type nsCSSValueBorrowed<'a> = &'a nsCSSValue;
pub type nsCSSValueBorrowedOrNull<'a> = Option<&'a nsCSSValue>;
pub type nsCSSValueBorrowedMut<'a> = &'a mut nsCSSValue;
pub type nsCSSValueBorrowedMutOrNull<'a> = Option<&'a mut nsCSSValue>;
pub type RawGeckoAnimationValueListBorrowed<'a> = &'a RawGeckoAnimationValueList;
pub type RawGeckoAnimationValueListBorrowedOrNull<'a> = Option<&'a RawGeckoAnimationValueList>;
pub type RawGeckoAnimationValueListBorrowedMut<'a> = &'a mut RawGeckoAnimationValueList;
pub type RawGeckoAnimationValueListBorrowedMutOrNull<'a> = Option<&'a mut RawGeckoAnimationValueList>;
extern "C" {
pub fn Gecko_EnsureTArrayCapacity(aArray: *mut ::std::os::raw::c_void,
aCapacity: usize, aElementSize: usize);
}
extern "C" {
pub fn Gecko_ClearPODTArray(aArray: *mut ::std::os::raw::c_void,
aElementSize: usize, aElementAlign: usize);
}
extern "C" {
pub fn Servo_CssRules_AddRef(ptr: ServoCssRulesBorrowed);
}
@ -252,17 +269,15 @@ extern "C" {
extern "C" {
pub fn Servo_ImportRule_Release(ptr: RawServoImportRuleBorrowed);
}
extern "C" {
pub fn Servo_AnimationValue_AddRef(ptr: RawServoAnimationValueBorrowed);
}
extern "C" {
pub fn Servo_AnimationValue_Release(ptr: RawServoAnimationValueBorrowed);
}
extern "C" {
pub fn Servo_StyleSet_Drop(ptr: RawServoStyleSetOwned);
}
extern "C" {
pub fn Gecko_EnsureTArrayCapacity(aArray: *mut ::std::os::raw::c_void,
aCapacity: usize, aElementSize: usize);
}
extern "C" {
pub fn Gecko_ClearPODTArray(aArray: *mut ::std::os::raw::c_void,
aElementSize: usize, aElementAlign: usize);
}
extern "C" {
pub fn Gecko_AddRefPrincipalArbitraryThread(aPtr:
*mut ThreadSafePrincipalHolder);
@ -1194,6 +1209,16 @@ extern "C" {
ServoComputedValuesBorrowed)
-> ServoComputedValuesStrong;
}
extern "C" {
pub fn Servo_AnimationValues_Populate(arg1:
RawGeckoAnimationValueListBorrowedMut,
arg2:
RawServoDeclarationBlockBorrowed,
arg3: ServoComputedValuesBorrowed,
arg4:
ServoComputedValuesBorrowedOrNull,
arg5: RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Servo_ParseStyleAttribute(data: *const nsACString_internal)
-> RawServoDeclarationBlockStrong;

View file

@ -3047,6 +3047,20 @@ pub mod root {
impl Clone for StyleComplexColor {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug)]
pub struct PropertyStyleAnimationValuePair {
pub mProperty: root::nsCSSPropertyID,
pub mValue: [u64; 2usize],
pub mServoValue: root::RefPtr<root::RawServoAnimationValue>,
}
#[test]
fn bindgen_test_layout_PropertyStyleAnimationValuePair() {
assert_eq!(::std::mem::size_of::<PropertyStyleAnimationValuePair>()
, 32usize);
assert_eq!(::std::mem::align_of::<PropertyStyleAnimationValuePair>()
, 8usize);
}
#[test]
fn __bindgen_test_layout_template_1() {
assert_eq!(::std::mem::size_of::<root::mozilla::DefaultDelete<root::RawServoStyleSet>>()
@ -11596,6 +11610,24 @@ pub mod root {
assert_eq!(::std::mem::size_of::<nsCSSValueFloatColor>() , 32usize);
assert_eq!(::std::mem::align_of::<nsCSSValueFloatColor>() , 8usize);
}
#[test]
fn __bindgen_test_layout_template_8_TEMPORARY() {
assert_eq!(::std::mem::size_of::<root::mozilla::UniquePtr<root::nsCSSValueList,
root::mozilla::DefaultDelete<root::nsCSSValueList>>>()
, 8usize);
assert_eq!(::std::mem::align_of::<root::mozilla::UniquePtr<root::nsCSSValueList,
root::mozilla::DefaultDelete<root::nsCSSValueList>>>()
, 8usize);
}
#[test]
fn __bindgen_test_layout_template_9_TEMPORARY() {
assert_eq!(::std::mem::size_of::<root::mozilla::UniquePtr<root::nsCSSValuePairList,
root::mozilla::DefaultDelete<root::nsCSSValuePairList>>>()
, 8usize);
assert_eq!(::std::mem::align_of::<root::mozilla::UniquePtr<root::nsCSSValuePairList,
root::mozilla::DefaultDelete<root::nsCSSValuePairList>>>()
, 8usize);
}
#[repr(C)]
#[derive(Debug)]
pub struct nsCSSValue {
@ -11669,6 +11701,14 @@ pub mod root {
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct RawServoAnimationValue {
pub _address: u8,
}
impl Clone for RawServoAnimationValue {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct RawServoStyleSet {
pub _address: u8,
}
@ -11679,6 +11719,8 @@ pub mod root {
pub type RawGeckoElement = root::mozilla::dom::Element;
pub type RawGeckoDocument = root::nsIDocument;
pub type RawGeckoPresContext = [u64; 162usize];
pub type RawGeckoAnimationValueList =
root::nsTArray<root::mozilla::PropertyStyleAnimationValuePair>;
pub type RawGeckoNodeBorrowed = *const root::RawGeckoNode;
pub type RawGeckoNodeBorrowedOrNull = *const root::RawGeckoNode;
pub type RawGeckoElementBorrowed = *const root::RawGeckoElement;
@ -11686,6 +11728,8 @@ pub mod root {
pub type RawGeckoDocumentBorrowed = *const root::RawGeckoDocument;
pub type RawGeckoDocumentBorrowedOrNull = *const root::RawGeckoDocument;
pub type RawGeckoPresContextBorrowed = *const [u64; 162usize];
pub type RawGeckoAnimationValueListBorrowedMut =
*mut root::RawGeckoAnimationValueList;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum nsCSSTokenSerializationType {

View file

@ -3029,6 +3029,20 @@ pub mod root {
impl Clone for StyleComplexColor {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug)]
pub struct PropertyStyleAnimationValuePair {
pub mProperty: root::nsCSSPropertyID,
pub mValue: [u64; 2usize],
pub mServoValue: root::RefPtr<root::RawServoAnimationValue>,
}
#[test]
fn bindgen_test_layout_PropertyStyleAnimationValuePair() {
assert_eq!(::std::mem::size_of::<PropertyStyleAnimationValuePair>()
, 32usize);
assert_eq!(::std::mem::align_of::<PropertyStyleAnimationValuePair>()
, 8usize);
}
#[test]
fn __bindgen_test_layout_template_1() {
assert_eq!(::std::mem::size_of::<root::mozilla::DefaultDelete<root::RawServoStyleSet>>()
@ -11523,6 +11537,24 @@ pub mod root {
assert_eq!(::std::mem::size_of::<nsCSSValueFloatColor>() , 24usize);
assert_eq!(::std::mem::align_of::<nsCSSValueFloatColor>() , 8usize);
}
#[test]
fn __bindgen_test_layout_template_8_TEMPORARY() {
assert_eq!(::std::mem::size_of::<root::mozilla::UniquePtr<root::nsCSSValueList,
root::mozilla::DefaultDelete<root::nsCSSValueList>>>()
, 8usize);
assert_eq!(::std::mem::align_of::<root::mozilla::UniquePtr<root::nsCSSValueList,
root::mozilla::DefaultDelete<root::nsCSSValueList>>>()
, 8usize);
}
#[test]
fn __bindgen_test_layout_template_9_TEMPORARY() {
assert_eq!(::std::mem::size_of::<root::mozilla::UniquePtr<root::nsCSSValuePairList,
root::mozilla::DefaultDelete<root::nsCSSValuePairList>>>()
, 8usize);
assert_eq!(::std::mem::align_of::<root::mozilla::UniquePtr<root::nsCSSValuePairList,
root::mozilla::DefaultDelete<root::nsCSSValuePairList>>>()
, 8usize);
}
#[repr(C)]
#[derive(Debug)]
pub struct nsCSSValue {
@ -11596,6 +11628,14 @@ pub mod root {
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct RawServoAnimationValue {
pub _address: u8,
}
impl Clone for RawServoAnimationValue {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct RawServoStyleSet {
pub _address: u8,
}
@ -11606,6 +11646,8 @@ pub mod root {
pub type RawGeckoElement = root::mozilla::dom::Element;
pub type RawGeckoDocument = root::nsIDocument;
pub type RawGeckoPresContext = [u64; 158usize];
pub type RawGeckoAnimationValueList =
root::nsTArray<root::mozilla::PropertyStyleAnimationValuePair>;
pub type RawGeckoNodeBorrowed = *const root::RawGeckoNode;
pub type RawGeckoNodeBorrowedOrNull = *const root::RawGeckoNode;
pub type RawGeckoElementBorrowed = *const root::RawGeckoElement;
@ -11613,6 +11655,8 @@ pub mod root {
pub type RawGeckoDocumentBorrowed = *const root::RawGeckoDocument;
pub type RawGeckoDocumentBorrowedOrNull = *const root::RawGeckoDocument;
pub type RawGeckoPresContextBorrowed = *const [u64; 158usize];
pub type RawGeckoAnimationValueListBorrowedMut =
*mut root::RawGeckoAnimationValueList;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum nsCSSTokenSerializationType {

View file

@ -5,10 +5,12 @@
//! A rust helper to ease the use of Gecko's refcounted types.
use gecko_bindings::structs;
use gecko_bindings::sugar::ownership::HasArcFFI;
use heapsize::HeapSizeOf;
use std::{mem, ptr};
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use std::sync::Arc;
/// Trait for all objects that have Addref() and Release
/// methods and can be placed inside RefPtr<T>
@ -196,6 +198,14 @@ impl<T: RefCounted> structs::RefPtr<T> {
}
}
impl<T> structs::RefPtr<T> {
/// 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(other) }; // Arc::into_raw is unstable :(
}
}
impl<T: RefCounted> Drop for RefPtr<T> {
fn drop(&mut self) {
unsafe { self.release() }

View file

@ -5,7 +5,7 @@
use app_units::Au;
use cssparser::{Color as CSSParserColor, Parser, RGBA};
use euclid::{Point2D, Size2D};
use properties::PropertyDeclaration;
use properties::{DeclaredValue, PropertyDeclaration};
use properties::longhands;
use properties::longhands::background_position_x::computed_value::T as BackgroundPositionX;
use properties::longhands::background_position_y::computed_value::T as BackgroundPositionY;
@ -26,7 +26,7 @@ use super::ComputedValues;
use values::Either;
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
use values::computed::{BorderRadiusSize, LengthOrNone};
use values::computed::{CalcLengthOrPercentage, LengthOrPercentage};
use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage};
use values::computed::position::{HorizontalPosition, Position, VerticalPosition};
use values::computed::ToComputedValue;
@ -191,6 +191,17 @@ 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.
@ -230,6 +241,40 @@ impl AnimationValue {
% endfor
}
}
/// Construct an AnimationValue from a property declaration
pub fn from_declaration(decl: &PropertyDeclaration, context: &Context, initial: &ComputedValues) -> Option<Self> {
match *decl {
% for prop in data.longhands:
% if prop.animatable:
PropertyDeclaration::${prop.camel_case}(ref val) => {
let computed = match *val {
// https://bugzilla.mozilla.org/show_bug.cgi?id=1326131
DeclaredValue::WithVariables{..} => unimplemented!(),
DeclaredValue::Value(ref val) => val.to_computed_value(context),
% if not prop.style_struct.inherited:
DeclaredValue::Unset |
% endif
DeclaredValue::Initial => {
let initial_struct = initial.get_${prop.style_struct.name_lower}();
initial_struct.clone_${prop.ident}()
},
% if prop.style_struct.inherited:
DeclaredValue::Unset |
% endif
DeclaredValue::Inherit => {
let inherit_struct = context.inherited_style
.get_${prop.style_struct.name_lower}();
inherit_struct.clone_${prop.ident}()
},
};
Some(AnimationValue::${prop.camel_case}(computed))
}
% endif
% endfor
_ => None // non animatable properties will get included because of shorthands. ignore.
}
}
}
impl Interpolate for AnimationValue {