mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
style: Add simple ToShmem implementations.
Differential Revision: https://phabricator.services.mozilla.com/D17190
This commit is contained in:
parent
f6ef35c5d3
commit
7fa7c103d6
7 changed files with 85 additions and 3 deletions
|
@ -100,7 +100,6 @@ extern crate style_traits;
|
||||||
extern crate thin_slice;
|
extern crate thin_slice;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
extern crate to_shmem;
|
extern crate to_shmem;
|
||||||
#[macro_use]
|
|
||||||
extern crate to_shmem_derive;
|
extern crate to_shmem_derive;
|
||||||
extern crate uluru;
|
extern crate uluru;
|
||||||
extern crate unicode_bidi;
|
extern crate unicode_bidi;
|
||||||
|
|
|
@ -67,6 +67,7 @@ pub mod system_colors {
|
||||||
use crate::gecko_bindings::structs::root::mozilla::LookAndFeel_ColorID;
|
use crate::gecko_bindings::structs::root::mozilla::LookAndFeel_ColorID;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use style_traits::{CssWriter, ToCss};
|
use style_traits::{CssWriter, ToCss};
|
||||||
|
use to_shmem::impl_trivial_to_shmem;
|
||||||
use crate::values::computed::{Context, ToComputedValue};
|
use crate::values::computed::{Context, ToComputedValue};
|
||||||
|
|
||||||
pub type SystemColor = LookAndFeel_ColorID;
|
pub type SystemColor = LookAndFeel_ColorID;
|
||||||
|
@ -75,6 +76,8 @@ pub mod system_colors {
|
||||||
// is a bindgen type. So we implement it on the typedef instead.
|
// is a bindgen type. So we implement it on the typedef instead.
|
||||||
malloc_size_of_is_0!(SystemColor);
|
malloc_size_of_is_0!(SystemColor);
|
||||||
|
|
||||||
|
impl_trivial_to_shmem!(SystemColor);
|
||||||
|
|
||||||
impl ToCss for SystemColor {
|
impl ToCss for SystemColor {
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
where
|
where
|
||||||
|
|
|
@ -36,6 +36,7 @@ use selectors::parser::SelectorParseErrorKind;
|
||||||
#[cfg(feature = "servo")] use servo_config::prefs;
|
#[cfg(feature = "servo")] use servo_config::prefs;
|
||||||
use style_traits::{CssWriter, KeywordsCollectFn, ParseError, ParsingMode};
|
use style_traits::{CssWriter, KeywordsCollectFn, ParseError, ParsingMode};
|
||||||
use style_traits::{SpecifiedValueInfo, StyleParseErrorKind, ToCss};
|
use style_traits::{SpecifiedValueInfo, StyleParseErrorKind, ToCss};
|
||||||
|
use to_shmem::impl_trivial_to_shmem;
|
||||||
use crate::stylesheets::{CssRuleType, Origin, UrlExtraData};
|
use crate::stylesheets::{CssRuleType, Origin, UrlExtraData};
|
||||||
use crate::values::generics::text::LineHeight;
|
use crate::values::generics::text::LineHeight;
|
||||||
use crate::values::computed;
|
use crate::values::computed;
|
||||||
|
@ -741,11 +742,13 @@ static ${name}: LonghandIdSet = LonghandIdSet {
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
/// A set of longhand properties
|
/// A set of longhand properties
|
||||||
#[derive(Clone, Debug, Default, MallocSizeOf, PartialEq)]
|
#[derive(Clone, Copy, Debug, Default, MallocSizeOf, PartialEq)]
|
||||||
pub struct LonghandIdSet {
|
pub struct LonghandIdSet {
|
||||||
storage: [u32; (${len(data.longhands)} - 1 + 32) / 32]
|
storage: [u32; (${len(data.longhands)} - 1 + 32) / 32]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_trivial_to_shmem!(LonghandIdSet);
|
||||||
|
|
||||||
/// An iterator over a set of longhand ids.
|
/// An iterator over a set of longhand ids.
|
||||||
pub struct LonghandIdSetIterator<'a> {
|
pub struct LonghandIdSetIterator<'a> {
|
||||||
longhands: &'a LonghandIdSet,
|
longhands: &'a LonghandIdSet,
|
||||||
|
|
|
@ -15,7 +15,9 @@ use crate::stylesheets::{CssRule, Origin, StylesheetInDocument};
|
||||||
use crate::values::CssUrl;
|
use crate::values::CssUrl;
|
||||||
use cssparser::SourceLocation;
|
use cssparser::SourceLocation;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
|
use std::mem::ManuallyDrop;
|
||||||
use style_traits::{CssWriter, ToCss};
|
use style_traits::{CssWriter, ToCss};
|
||||||
|
use to_shmem::{SharedMemoryBuilder, ToShmem};
|
||||||
|
|
||||||
/// With asynchronous stylesheet parsing, we can't synchronously create a
|
/// With asynchronous stylesheet parsing, we can't synchronously create a
|
||||||
/// GeckoStyleSheet. So we use this placeholder instead.
|
/// GeckoStyleSheet. So we use this placeholder instead.
|
||||||
|
@ -180,6 +182,12 @@ pub struct ImportRule {
|
||||||
pub source_location: SourceLocation,
|
pub source_location: SourceLocation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToShmem for ImportRule {
|
||||||
|
fn to_shmem(&self, _builder: &mut SharedMemoryBuilder) -> ManuallyDrop<Self> {
|
||||||
|
panic!("ToShmem failed for ImportRule: cannot handle imported style sheets")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl DeepCloneWithLock for ImportRule {
|
impl DeepCloneWithLock for ImportRule {
|
||||||
fn deep_clone_with_lock(
|
fn deep_clone_with_lock(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -17,6 +17,7 @@ use selectors::parser::SelectorParseErrorKind;
|
||||||
use std::fmt::{self, Debug, Write};
|
use std::fmt::{self, Debug, Write};
|
||||||
use std::hash;
|
use std::hash;
|
||||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||||
|
use to_shmem::impl_trivial_to_shmem;
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub use crate::gecko::url::CssUrl;
|
pub use crate::gecko::url::CssUrl;
|
||||||
|
@ -108,6 +109,8 @@ impl ComputeSquaredDistance for Impossible {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_trivial_to_shmem!(Impossible);
|
||||||
|
|
||||||
impl Parse for Impossible {
|
impl Parse for Impossible {
|
||||||
fn parse<'i, 't>(
|
fn parse<'i, 't>(
|
||||||
_context: &ParserContext,
|
_context: &ParserContext,
|
||||||
|
|
|
@ -10,7 +10,9 @@ name = "to_shmem"
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
servo = []
|
servo = ["serde", "cssparser/serde"]
|
||||||
gecko = []
|
gecko = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
cssparser = "0.25"
|
||||||
|
serde = {version = "1.0", optional = true}
|
||||||
|
|
|
@ -12,13 +12,18 @@
|
||||||
#![crate_name = "to_shmem"]
|
#![crate_name = "to_shmem"]
|
||||||
#![crate_type = "rlib"]
|
#![crate_type = "rlib"]
|
||||||
|
|
||||||
|
extern crate cssparser;
|
||||||
|
|
||||||
use std::alloc::Layout;
|
use std::alloc::Layout;
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
use std::any::TypeId;
|
use std::any::TypeId;
|
||||||
use std::isize;
|
use std::isize;
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
use std::marker::PhantomData;
|
||||||
use std::mem::{self, ManuallyDrop};
|
use std::mem::{self, ManuallyDrop};
|
||||||
|
use std::num::Wrapping;
|
||||||
|
use std::ops::Range;
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
use std::os::raw::c_void;
|
use std::os::raw::c_void;
|
||||||
use std::ptr::{self, NonNull};
|
use std::ptr::{self, NonNull};
|
||||||
|
@ -173,3 +178,62 @@ pub trait ToShmem: Sized {
|
||||||
/// accidentally invoke the destructor of the value that is produced.
|
/// accidentally invoke the destructor of the value that is produced.
|
||||||
fn to_shmem(&self, builder: &mut SharedMemoryBuilder) -> ManuallyDrop<Self>;
|
fn to_shmem(&self, builder: &mut SharedMemoryBuilder) -> ManuallyDrop<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! impl_trivial_to_shmem {
|
||||||
|
($($ty:ty),*) => {$(
|
||||||
|
impl $crate::ToShmem for $ty {
|
||||||
|
fn to_shmem(
|
||||||
|
&self,
|
||||||
|
_builder: &mut $crate::SharedMemoryBuilder,
|
||||||
|
) -> ::std::mem::ManuallyDrop<Self> {
|
||||||
|
::std::mem::ManuallyDrop::new(*self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*};
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_trivial_to_shmem!((), bool, f32, f64, i8, i16, i32, i64, u8, u16, u32, u64, isize, usize);
|
||||||
|
|
||||||
|
impl_trivial_to_shmem!(cssparser::RGBA);
|
||||||
|
impl_trivial_to_shmem!(cssparser::SourceLocation);
|
||||||
|
impl_trivial_to_shmem!(cssparser::TokenSerializationType);
|
||||||
|
|
||||||
|
impl<T> ToShmem for PhantomData<T> {
|
||||||
|
fn to_shmem(&self, _builder: &mut SharedMemoryBuilder) -> ManuallyDrop<Self> {
|
||||||
|
ManuallyDrop::new(*self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: ToShmem> ToShmem for Range<T> {
|
||||||
|
fn to_shmem(&self, builder: &mut SharedMemoryBuilder) -> ManuallyDrop<Self> {
|
||||||
|
ManuallyDrop::new(Range {
|
||||||
|
start: ManuallyDrop::into_inner(self.start.to_shmem(builder)),
|
||||||
|
end: ManuallyDrop::into_inner(self.end.to_shmem(builder)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToShmem for cssparser::UnicodeRange {
|
||||||
|
fn to_shmem(&self, _builder: &mut SharedMemoryBuilder) -> ManuallyDrop<Self> {
|
||||||
|
ManuallyDrop::new(cssparser::UnicodeRange {
|
||||||
|
start: self.start,
|
||||||
|
end: self.end,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: ToShmem, U: ToShmem> ToShmem for (T, U) {
|
||||||
|
fn to_shmem(&self, builder: &mut SharedMemoryBuilder) -> ManuallyDrop<Self> {
|
||||||
|
ManuallyDrop::new((
|
||||||
|
ManuallyDrop::into_inner(self.0.to_shmem(builder)),
|
||||||
|
ManuallyDrop::into_inner(self.1.to_shmem(builder)),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: ToShmem> ToShmem for Wrapping<T> {
|
||||||
|
fn to_shmem(&self, builder: &mut SharedMemoryBuilder) -> ManuallyDrop<Self> {
|
||||||
|
ManuallyDrop::new(Wrapping(ManuallyDrop::into_inner(self.0.to_shmem(builder))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue