mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Handle Calc refcounting
This commit is contained in:
parent
8fddc46020
commit
704d7a01c9
9 changed files with 58 additions and 34 deletions
|
@ -80,9 +80,9 @@ pub mod data;
|
||||||
pub mod dom;
|
pub mod dom;
|
||||||
pub mod element_state;
|
pub mod element_state;
|
||||||
pub mod error_reporting;
|
pub mod error_reporting;
|
||||||
|
pub mod font_face;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub mod gecko_conversions;
|
pub mod gecko_conversions;
|
||||||
pub mod font_face;
|
|
||||||
pub mod keyframes;
|
pub mod keyframes;
|
||||||
pub mod logical_geometry;
|
pub mod logical_geometry;
|
||||||
pub mod matching;
|
pub mod matching;
|
||||||
|
|
|
@ -132,6 +132,7 @@ unsafe impl Send for nsStyleUnion {}
|
||||||
unsafe impl Sync for nsStyleUnion {}
|
unsafe impl Sync for nsStyleUnion {}
|
||||||
impl HeapSizeOf for nsStyleUnion { fn heap_size_of_children(&self) -> usize { 0 } }
|
impl HeapSizeOf for nsStyleUnion { fn heap_size_of_children(&self) -> usize { 0 } }
|
||||||
use structs::nsStyleCoord_CalcValue as CalcValue;
|
use structs::nsStyleCoord_CalcValue as CalcValue;
|
||||||
|
use structs::nsStyleCoord_Calc as Calc;
|
||||||
use structs::SheetParsingMode;
|
use structs::SheetParsingMode;
|
||||||
use structs::nsMainThreadPtrHandle;
|
use structs::nsMainThreadPtrHandle;
|
||||||
use structs::nsMainThreadPtrHolder;
|
use structs::nsMainThreadPtrHolder;
|
||||||
|
@ -269,6 +270,8 @@ extern "C" {
|
||||||
pub fn Gecko_SetStyleCoordCalcValue(unit: *mut nsStyleUnit,
|
pub fn Gecko_SetStyleCoordCalcValue(unit: *mut nsStyleUnit,
|
||||||
value: *mut nsStyleUnion,
|
value: *mut nsStyleUnion,
|
||||||
calc: CalcValue);
|
calc: CalcValue);
|
||||||
|
pub fn Gecko_AddRefCalcArbitraryThread(aPtr: *mut Calc);
|
||||||
|
pub fn Gecko_ReleaseCalcArbitraryThread(aPtr: *mut Calc);
|
||||||
pub fn Servo_StylesheetFromUTF8Bytes(bytes: *const u8, length: u32,
|
pub fn Servo_StylesheetFromUTF8Bytes(bytes: *const u8, length: u32,
|
||||||
parsing_mode: SheetParsingMode,
|
parsing_mode: SheetParsingMode,
|
||||||
base: *mut ThreadSafeURIHolder,
|
base: *mut ThreadSafeURIHolder,
|
||||||
|
|
|
@ -4885,12 +4885,11 @@ fn bindgen_test_layout_nsStyleCoord_CalcValue() {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct nsStyleCoord_Calc {
|
pub struct nsStyleCoord_Calc {
|
||||||
pub _base: nsStyleCoord_CalcValue,
|
pub _base: nsStyleCoord_CalcValue,
|
||||||
pub mRefCnt: nsAutoRefCnt,
|
pub mRefCnt: ThreadSafeAutoRefCnt,
|
||||||
pub _mOwningThread: nsAutoOwningThread,
|
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn bindgen_test_layout_nsStyleCoord_Calc() {
|
fn bindgen_test_layout_nsStyleCoord_Calc() {
|
||||||
assert_eq!(::std::mem::size_of::<nsStyleCoord_Calc>() , 32usize);
|
assert_eq!(::std::mem::size_of::<nsStyleCoord_Calc>() , 24usize);
|
||||||
assert_eq!(::std::mem::align_of::<nsStyleCoord_Calc>() , 8usize);
|
assert_eq!(::std::mem::align_of::<nsStyleCoord_Calc>() , 8usize);
|
||||||
}
|
}
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
|
|
|
@ -4864,12 +4864,11 @@ fn bindgen_test_layout_nsStyleCoord_CalcValue() {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct nsStyleCoord_Calc {
|
pub struct nsStyleCoord_Calc {
|
||||||
pub _base: nsStyleCoord_CalcValue,
|
pub _base: nsStyleCoord_CalcValue,
|
||||||
pub mRefCnt: nsAutoRefCnt,
|
pub mRefCnt: ThreadSafeAutoRefCnt,
|
||||||
pub _mOwningThread: nsAutoOwningThread,
|
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn bindgen_test_layout_nsStyleCoord_Calc() {
|
fn bindgen_test_layout_nsStyleCoord_Calc() {
|
||||||
assert_eq!(::std::mem::size_of::<nsStyleCoord_Calc>() , 32usize);
|
assert_eq!(::std::mem::size_of::<nsStyleCoord_Calc>() , 24usize);
|
||||||
assert_eq!(::std::mem::align_of::<nsStyleCoord_Calc>() , 8usize);
|
assert_eq!(::std::mem::align_of::<nsStyleCoord_Calc>() , 8usize);
|
||||||
}
|
}
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use structs::{nsStyleCoord_CalcValue, nsStyleCoord_Calc, nsStyleUnit, nsStyleUnion};
|
use bindings::{Gecko_ResetStyleCoord, Gecko_SetStyleCoordCalcValue, Gecko_AddRefCalcArbitraryThread};
|
||||||
use bindings::{Gecko_ResetStyleCoord, Gecko_SetStyleCoordCalcValue};
|
use std::mem::transmute;
|
||||||
|
use structs::{nsStyleCoord_CalcValue, nsStyleCoord_Calc, nsStyleUnit, nsStyleUnion, nsStyleCoord};
|
||||||
|
|
||||||
// Functions here are unsafe because it is possible to use the wrong nsStyleUnit
|
// Functions here are unsafe because it is possible to use the wrong nsStyleUnit
|
||||||
// FIXME we should be pairing up nsStyleUnion and nsStyleUnit somehow
|
// FIXME we should be pairing up nsStyleUnion and nsStyleUnit somehow
|
||||||
|
@ -29,6 +30,25 @@ impl nsStyleUnion {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn get_calc(&self) -> nsStyleCoord_CalcValue {
|
pub unsafe fn get_calc(&self) -> nsStyleCoord_CalcValue {
|
||||||
(*(*self.mPointer.as_ref() as *const nsStyleCoord_Calc))._base
|
(*self.as_calc())._base
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn addref_opt(&mut self, unit: &nsStyleUnit) {
|
||||||
|
if *unit == nsStyleUnit::eStyleUnit_Calc {
|
||||||
|
Gecko_AddRefCalcArbitraryThread(self.as_calc_mut());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn as_calc_mut(&mut self) -> &mut nsStyleCoord_Calc {
|
||||||
|
transmute(*self.mPointer.as_mut() as *mut nsStyleCoord_Calc)
|
||||||
|
}
|
||||||
|
pub unsafe fn as_calc(&self) -> &nsStyleCoord_Calc {
|
||||||
|
transmute(*self.mPointer.as_ref() as *const nsStyleCoord_Calc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl nsStyleCoord {
|
||||||
|
pub unsafe fn addref_opt(&mut self) {
|
||||||
|
self.mValue.addref_opt(&self.mUnit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,7 @@ COMPILATION_TARGETS = {
|
||||||
"nsStyleCoord", "nsStyleGradientStop", "nsStyleImageLayers",
|
"nsStyleCoord", "nsStyleGradientStop", "nsStyleImageLayers",
|
||||||
"nsStyleImageLayers::Layer", "nsStyleImageLayers::LayerType",
|
"nsStyleImageLayers::Layer", "nsStyleImageLayers::LayerType",
|
||||||
"nsStyleUnit", "nsStyleUnion", "nsStyleCoord::CalcValue",
|
"nsStyleUnit", "nsStyleUnion", "nsStyleCoord::CalcValue",
|
||||||
|
"nsStyleCoord::Calc",
|
||||||
|
|
||||||
"SheetParsingMode", "nsMainThreadPtrHandle",
|
"SheetParsingMode", "nsMainThreadPtrHandle",
|
||||||
"nsMainThreadPtrHolder", "nscolor", "nsFont", "FontFamilyList",
|
"nsMainThreadPtrHolder", "nscolor", "nsFont", "FontFamilyList",
|
||||||
|
|
|
@ -35,7 +35,7 @@ use style::properties::{CascadePropertyFn, ServoComputedValues, ComputedValues};
|
||||||
use style::properties::longhands;
|
use style::properties::longhands;
|
||||||
use style::properties::style_struct_traits::*;
|
use style::properties::style_struct_traits::*;
|
||||||
use values::{StyleCoordHelpers, GeckoStyleCoordConvertible, convert_nscolor_to_rgba};
|
use values::{StyleCoordHelpers, GeckoStyleCoordConvertible, convert_nscolor_to_rgba};
|
||||||
use values::{convert_rgba_to_nscolor, debug_assert_unit_is_safe_to_copy};
|
use values::convert_rgba_to_nscolor;
|
||||||
use values::round_border_to_device_pixels;
|
use values::round_border_to_device_pixels;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -317,9 +317,10 @@ def set_gecko_property(ffi_name, expr):
|
||||||
&mut self.gecko.${union_ffi_name});
|
&mut self.gecko.${union_ffi_name});
|
||||||
}
|
}
|
||||||
fn copy_${ident}_from(&mut self, other: &Self) {
|
fn copy_${ident}_from(&mut self, other: &Self) {
|
||||||
debug_assert_unit_is_safe_to_copy(self.gecko.${unit_ffi_name});
|
unsafe { self.gecko.${union_ffi_name}.reset(&mut self.gecko.${unit_ffi_name}) };
|
||||||
self.gecko.${unit_ffi_name} = other.gecko.${unit_ffi_name};
|
self.gecko.${unit_ffi_name} = other.gecko.${unit_ffi_name};
|
||||||
self.gecko.${union_ffi_name} = other.gecko.${union_ffi_name};
|
self.gecko.${union_ffi_name} = other.gecko.${union_ffi_name};
|
||||||
|
unsafe { self.gecko.${union_ffi_name}.addref_opt(&self.gecko.${unit_ffi_name}) };
|
||||||
}
|
}
|
||||||
% if need_clone:
|
% if need_clone:
|
||||||
fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
|
fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
|
||||||
|
@ -347,12 +348,14 @@ ${impl_split_style_coord(ident,
|
||||||
&mut self.gecko.${y_union_ffi_name});
|
&mut self.gecko.${y_union_ffi_name});
|
||||||
}
|
}
|
||||||
fn copy_${ident}_from(&mut self, other: &Self) {
|
fn copy_${ident}_from(&mut self, other: &Self) {
|
||||||
debug_assert_unit_is_safe_to_copy(self.gecko.${x_unit_ffi_name});
|
unsafe { self.gecko.${x_union_ffi_name}.reset(&mut self.gecko.${x_unit_ffi_name}) };
|
||||||
debug_assert_unit_is_safe_to_copy(self.gecko.${y_unit_ffi_name});
|
unsafe { self.gecko.${y_union_ffi_name}.reset(&mut self.gecko.${y_unit_ffi_name}) };
|
||||||
self.gecko.${x_unit_ffi_name} = other.gecko.${x_unit_ffi_name};
|
self.gecko.${x_unit_ffi_name} = other.gecko.${x_unit_ffi_name};
|
||||||
self.gecko.${x_union_ffi_name} = other.gecko.${x_union_ffi_name};
|
self.gecko.${x_union_ffi_name} = other.gecko.${x_union_ffi_name};
|
||||||
self.gecko.${y_unit_ffi_name} = other.gecko.${y_unit_ffi_name};
|
self.gecko.${y_unit_ffi_name} = other.gecko.${y_unit_ffi_name};
|
||||||
self.gecko.${y_union_ffi_name} = other.gecko.${y_union_ffi_name};
|
self.gecko.${y_union_ffi_name} = other.gecko.${y_union_ffi_name};
|
||||||
|
unsafe { self.gecko.${x_union_ffi_name}.addref_opt(&self.gecko.${x_unit_ffi_name}) };
|
||||||
|
unsafe { self.gecko.${y_union_ffi_name}.addref_opt(&self.gecko.${y_unit_ffi_name}) };
|
||||||
}
|
}
|
||||||
% if need_clone:
|
% if need_clone:
|
||||||
fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
|
fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
|
||||||
|
@ -628,9 +631,10 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_z_index_from(&mut self, other: &Self) {
|
fn copy_z_index_from(&mut self, other: &Self) {
|
||||||
debug_assert_unit_is_safe_to_copy(self.gecko.mZIndex.mUnit);
|
unsafe { self.gecko.mZIndex.mValue.reset(&mut self.gecko.mZIndex.mUnit) };
|
||||||
self.gecko.mZIndex.mUnit = other.gecko.mZIndex.mUnit;
|
self.gecko.mZIndex.mUnit = other.gecko.mZIndex.mUnit;
|
||||||
self.gecko.mZIndex.mValue = other.gecko.mZIndex.mValue;
|
self.gecko.mZIndex.mValue = other.gecko.mZIndex.mValue;
|
||||||
|
unsafe { self.gecko.mZIndex.mValue.addref_opt(&self.gecko.mZIndex.mUnit) };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clone_z_index(&self) -> longhands::z_index::computed_value::T {
|
fn clone_z_index(&self) -> longhands::z_index::computed_value::T {
|
||||||
|
|
|
@ -43,10 +43,10 @@ pub trait StyleCoordHelpers {
|
||||||
impl StyleCoordHelpers for nsStyleCoord {
|
impl StyleCoordHelpers for nsStyleCoord {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn copy_from(&mut self, other: &Self) {
|
fn copy_from(&mut self, other: &Self) {
|
||||||
debug_assert_unit_is_safe_to_copy(self.mUnit);
|
unsafe { self.mValue.reset(&mut self.mUnit) };
|
||||||
debug_assert_unit_is_safe_to_copy(other.mUnit);
|
|
||||||
self.mUnit = other.mUnit;
|
self.mUnit = other.mUnit;
|
||||||
self.mValue = other.mValue;
|
self.mValue = other.mValue;
|
||||||
|
unsafe { self.addref_opt(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -263,6 +263,7 @@ impl GeckoStyleCoordConvertible for LengthOrPercentageOrNone {
|
||||||
|
|
||||||
impl<T: GeckoStyleCoordConvertible> GeckoStyleCoordConvertible for Option<T> {
|
impl<T: GeckoStyleCoordConvertible> GeckoStyleCoordConvertible for Option<T> {
|
||||||
fn to_gecko_style_coord(&self, unit: &mut nsStyleUnit, union: &mut nsStyleUnion) {
|
fn to_gecko_style_coord(&self, unit: &mut nsStyleUnit, union: &mut nsStyleUnion) {
|
||||||
|
unsafe { union.reset(unit) };
|
||||||
if let Some(ref me) = *self {
|
if let Some(ref me) = *self {
|
||||||
me.to_gecko_style_coord(unit, union);
|
me.to_gecko_style_coord(unit, union);
|
||||||
} else {
|
} else {
|
||||||
|
@ -280,6 +281,7 @@ impl GeckoStyleCoordConvertible for Angle {
|
||||||
fn to_gecko_style_coord(&self,
|
fn to_gecko_style_coord(&self,
|
||||||
unit: &mut nsStyleUnit,
|
unit: &mut nsStyleUnit,
|
||||||
union: &mut nsStyleUnion) {
|
union: &mut nsStyleUnion) {
|
||||||
|
unsafe { union.reset(unit) };
|
||||||
*unit = nsStyleUnit::eStyleUnit_Radian;
|
*unit = nsStyleUnit::eStyleUnit_Radian;
|
||||||
unsafe { *union.mFloat.as_mut() = self.radians() };
|
unsafe { *union.mFloat.as_mut() = self.radians() };
|
||||||
}
|
}
|
||||||
|
@ -320,7 +322,3 @@ pub fn round_border_to_device_pixels(width: Au, au_per_device_px: Au) -> Au {
|
||||||
max(au_per_device_px, Au(width.0 / au_per_device_px.0 * au_per_device_px.0))
|
max(au_per_device_px, Au(width.0 / au_per_device_px.0 * au_per_device_px.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn debug_assert_unit_is_safe_to_copy(unit: nsStyleUnit) {
|
|
||||||
debug_assert!(unit != nsStyleUnit::eStyleUnit_Calc, "stylo: Can't yet handle refcounted Calc");
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue