зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1474793 - Part 11: Add FFI API to use SharedMemoryBuilder. r=emilio
Depends on D17197 Differential Revision: https://phabricator.services.mozilla.com/D17198 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
6b5853fa8e
Коммит
3a08c03925
|
@ -1187,6 +1187,7 @@ dependencies = [
|
||||||
"smallvec 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"smallvec 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"style 0.0.1",
|
"style 0.0.1",
|
||||||
"style_traits 0.0.1",
|
"style_traits 0.0.1",
|
||||||
|
"to_shmem 0.0.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2792,6 +2793,7 @@ dependencies = [
|
||||||
"smallvec 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"smallvec 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"style 0.0.1",
|
"style 0.0.1",
|
||||||
"style_traits 0.0.1",
|
"style_traits 0.0.1",
|
||||||
|
"to_shmem 0.0.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -180,6 +180,7 @@ SERVO_ARC_TYPE(ComputedStyle, mozilla::ComputedStyle)
|
||||||
SERVO_BOXED_TYPE(StyleSet, RawServoStyleSet)
|
SERVO_BOXED_TYPE(StyleSet, RawServoStyleSet)
|
||||||
SERVO_BOXED_TYPE(AuthorStyles, RawServoAuthorStyles)
|
SERVO_BOXED_TYPE(AuthorStyles, RawServoAuthorStyles)
|
||||||
SERVO_BOXED_TYPE(SelectorList, RawServoSelectorList)
|
SERVO_BOXED_TYPE(SelectorList, RawServoSelectorList)
|
||||||
|
SERVO_BOXED_TYPE(SharedMemoryBuilder, RawServoSharedMemoryBuilder)
|
||||||
SERVO_BOXED_TYPE(SourceSizeList, RawServoSourceSizeList)
|
SERVO_BOXED_TYPE(SourceSizeList, RawServoSourceSizeList)
|
||||||
SERVO_BOXED_TYPE(UseCounters, StyleUseCounters)
|
SERVO_BOXED_TYPE(UseCounters, StyleUseCounters)
|
||||||
#undef SERVO_BOXED_TYPE
|
#undef SERVO_BOXED_TYPE
|
||||||
|
|
|
@ -1002,6 +1002,16 @@ void Servo_Quotes_GetQuote(const RawServoQuotes* quotes, int32_t depth,
|
||||||
mozilla::StyleContentType quote_type,
|
mozilla::StyleContentType quote_type,
|
||||||
nsAString* result);
|
nsAString* result);
|
||||||
|
|
||||||
|
RawServoSharedMemoryBuilder* Servo_SharedMemoryBuilder_Create(uint8_t* buffer,
|
||||||
|
size_t len);
|
||||||
|
|
||||||
|
const ServoCssRules* Servo_SharedMemoryBuilder_AddStylesheet(
|
||||||
|
RawServoSharedMemoryBuilder* builder,
|
||||||
|
const RawServoStyleSheetContents* sheet);
|
||||||
|
|
||||||
|
size_t Servo_SharedMemoryBuilder_GetLength(
|
||||||
|
RawServoSharedMemoryBuilder* builder);
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* 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/. */
|
||||||
|
|
||||||
|
//! FFI implementations for types listed in ServoBoxedTypeList.h.
|
||||||
|
|
||||||
|
use crate::gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
|
||||||
|
use to_shmem::SharedMemoryBuilder;
|
||||||
|
|
||||||
|
// TODO(heycam): The FFI impls for most of the types in ServoBoxedTypeList.h are spread across
|
||||||
|
// various files at the moment, but should probably all move here, and use macros to define
|
||||||
|
// them more succinctly, like we do in arc_types.rs.
|
||||||
|
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
unsafe impl HasFFI for SharedMemoryBuilder {
|
||||||
|
type FFIType = crate::gecko_bindings::bindings::RawServoSharedMemoryBuilder;
|
||||||
|
}
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
unsafe impl HasSimpleFFI for SharedMemoryBuilder {}
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
unsafe impl HasBoxFFI for SharedMemoryBuilder {}
|
|
@ -8,6 +8,7 @@
|
||||||
mod non_ts_pseudo_class_list;
|
mod non_ts_pseudo_class_list;
|
||||||
|
|
||||||
pub mod arc_types;
|
pub mod arc_types;
|
||||||
|
pub mod boxed_types;
|
||||||
pub mod conversions;
|
pub mod conversions;
|
||||||
pub mod data;
|
pub mod data;
|
||||||
pub mod media_features;
|
pub mod media_features;
|
||||||
|
|
|
@ -27,3 +27,4 @@ servo_arc = {path = "../../components/servo_arc"}
|
||||||
smallvec = "0.6"
|
smallvec = "0.6"
|
||||||
style = {path = "../../components/style", features = ["gecko"]}
|
style = {path = "../../components/style", features = ["gecko"]}
|
||||||
style_traits = {path = "../../components/style_traits"}
|
style_traits = {path = "../../components/style_traits"}
|
||||||
|
to_shmem = {path = "../../components/to_shmem"}
|
||||||
|
|
|
@ -55,7 +55,8 @@ use style::gecko_bindings::structs::{
|
||||||
RawServoKeyframesRule, ServoCssRules, RawServoStyleSheetContents,
|
RawServoKeyframesRule, ServoCssRules, RawServoStyleSheetContents,
|
||||||
RawServoPageRule, RawServoNamespaceRule, RawServoMozDocumentRule,
|
RawServoPageRule, RawServoNamespaceRule, RawServoMozDocumentRule,
|
||||||
RawServoKeyframe, RawServoMediaRule, RawServoImportRule,
|
RawServoKeyframe, RawServoMediaRule, RawServoImportRule,
|
||||||
RawServoFontFaceRule, RawServoFontFeatureValuesRule
|
RawServoFontFaceRule, RawServoFontFeatureValuesRule,
|
||||||
|
RawServoSharedMemoryBuilder
|
||||||
};
|
};
|
||||||
use style::gecko_bindings::structs::gfxFontFeatureValueSet;
|
use style::gecko_bindings::structs::gfxFontFeatureValueSet;
|
||||||
use style::gecko_bindings::structs::nsAtom;
|
use style::gecko_bindings::structs::nsAtom;
|
||||||
|
@ -107,7 +108,7 @@ use style::properties::{parse_one_declaration_into, parse_style_attribute};
|
||||||
use style::properties::{ComputedValues, Importance, NonCustomPropertyId};
|
use style::properties::{ComputedValues, Importance, NonCustomPropertyId};
|
||||||
use style::properties::{LonghandId, LonghandIdSet, PropertyDeclarationBlock, PropertyId};
|
use style::properties::{LonghandId, LonghandIdSet, PropertyDeclarationBlock, PropertyId};
|
||||||
use style::properties::{PropertyDeclarationId, ShorthandId};
|
use style::properties::{PropertyDeclarationId, ShorthandId};
|
||||||
use style::properties::{SourcePropertyDeclaration, StyleBuilder};
|
use style::properties::{SourcePropertyDeclaration, StyleBuilder, UnparsedValue};
|
||||||
use style::rule_cache::RuleCacheConditions;
|
use style::rule_cache::RuleCacheConditions;
|
||||||
use style::rule_tree::{CascadeLevel, StrongRuleNode};
|
use style::rule_tree::{CascadeLevel, StrongRuleNode};
|
||||||
use style::selector_parser::{PseudoElementCascadeType, SelectorImpl};
|
use style::selector_parser::{PseudoElementCascadeType, SelectorImpl};
|
||||||
|
@ -137,6 +138,7 @@ use style::values::specified::gecko::IntersectionObserverRootMargin;
|
||||||
use style::values::specified::source_size_list::SourceSizeList;
|
use style::values::specified::source_size_list::SourceSizeList;
|
||||||
use style::values::{CustomIdent, KeyframesName};
|
use style::values::{CustomIdent, KeyframesName};
|
||||||
use style_traits::{CssWriter, ParsingMode, StyleParseErrorKind, ToCss};
|
use style_traits::{CssWriter, ParsingMode, StyleParseErrorKind, ToCss};
|
||||||
|
use to_shmem::SharedMemoryBuilder;
|
||||||
|
|
||||||
trait ClosureHelper {
|
trait ClosureHelper {
|
||||||
fn invoke(&self);
|
fn invoke(&self);
|
||||||
|
@ -6337,3 +6339,55 @@ pub unsafe extern "C" fn Servo_Quotes_GetQuote(
|
||||||
};
|
};
|
||||||
(*result).write_str(quote).unwrap();
|
(*result).write_str(quote).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn Servo_SharedMemoryBuilder_Create(
|
||||||
|
buffer: *mut u8,
|
||||||
|
len: usize,
|
||||||
|
) -> *mut RawServoSharedMemoryBuilder {
|
||||||
|
let mut builder = Box::new(SharedMemoryBuilder::new(buffer, len));
|
||||||
|
|
||||||
|
// We have Arc<UnparsedValue>s in style sheets due to CSS variables being
|
||||||
|
// used in shorthand property declarations. There aren't many, though,
|
||||||
|
// and they aren't big, so we just allow their duplication for now.
|
||||||
|
builder.add_allowed_duplication_type::<UnparsedValue>();
|
||||||
|
|
||||||
|
Box::into_raw(builder) as *mut _
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn Servo_SharedMemoryBuilder_AddStylesheet(
|
||||||
|
builder: &mut RawServoSharedMemoryBuilder,
|
||||||
|
raw_contents: &RawServoStyleSheetContents,
|
||||||
|
) -> *const ServoCssRules {
|
||||||
|
let builder = SharedMemoryBuilder::from_ffi_mut(builder);
|
||||||
|
let contents = StylesheetContents::as_arc(&raw_contents);
|
||||||
|
|
||||||
|
// Assert some things we assume when we create a style sheet from shared
|
||||||
|
// memory.
|
||||||
|
debug_assert_eq!(contents.origin, Origin::UserAgent);
|
||||||
|
debug_assert_eq!(contents.quirks_mode, QuirksMode::NoQuirks);
|
||||||
|
debug_assert!(contents.source_map_url.read().is_none());
|
||||||
|
debug_assert!(contents.source_url.read().is_none());
|
||||||
|
|
||||||
|
let rules = &contents.rules;
|
||||||
|
let shared_rules: &Arc<Locked<CssRules>> = &*builder.write(rules);
|
||||||
|
(&*shared_rules).with_raw_offset_arc(|arc| {
|
||||||
|
*Locked::<CssRules>::arc_as_borrowed(arc) as *const _
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn Servo_SharedMemoryBuilder_GetLength(
|
||||||
|
builder: &mut RawServoSharedMemoryBuilder,
|
||||||
|
) -> usize {
|
||||||
|
let builder = SharedMemoryBuilder::from_ffi_mut(builder);
|
||||||
|
builder.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn Servo_SharedMemoryBuilder_Drop(
|
||||||
|
builder: Owned<RawServoSharedMemoryBuilder>
|
||||||
|
) {
|
||||||
|
let _ = builder.into_box::<SharedMemoryBuilder>();
|
||||||
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ extern crate smallvec;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate style;
|
extern crate style;
|
||||||
extern crate style_traits;
|
extern crate style_traits;
|
||||||
|
extern crate to_shmem;
|
||||||
|
|
||||||
mod error_reporter;
|
mod error_reporter;
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
|
|
@ -24,3 +24,4 @@ size_of_test = {path = "../../../components/size_of_test"}
|
||||||
smallvec = "0.6"
|
smallvec = "0.6"
|
||||||
style_traits = {path = "../../../components/style_traits"}
|
style_traits = {path = "../../../components/style_traits"}
|
||||||
style = {path = "../../../components/style", features = ["gecko"]}
|
style = {path = "../../../components/style", features = ["gecko"]}
|
||||||
|
to_shmem = {path = "../../../components/to_shmem"}
|
||||||
|
|
|
@ -26,6 +26,7 @@ extern crate size_of_test;
|
||||||
#[cfg_attr(target_pointer_width = "64", macro_use)]
|
#[cfg_attr(target_pointer_width = "64", macro_use)]
|
||||||
extern crate style;
|
extern crate style;
|
||||||
extern crate style_traits;
|
extern crate style_traits;
|
||||||
|
extern crate to_shmem;
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "64")]
|
#[cfg(target_pointer_width = "64")]
|
||||||
mod size_of;
|
mod size_of;
|
||||||
|
|
|
@ -27,3 +27,4 @@ size_of_test = {path = "../../../components/size_of_test"}
|
||||||
style = {path = "../../../components/style"}
|
style = {path = "../../../components/style"}
|
||||||
style_traits = {path = "../../../components/style_traits"}
|
style_traits = {path = "../../../components/style_traits"}
|
||||||
std_test_override = { path = "../../../components/std_test_override" }
|
std_test_override = { path = "../../../components/std_test_override" }
|
||||||
|
to_shmem = { path = "../../../components/to_shmem" }
|
||||||
|
|
Загрузка…
Ссылка в новой задаче