mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Instead of exposing many different kinds of messages to the compositor that are routed through the constellation, expose a single message type which can be sent across IPC channels. In addition, this IPC channel and the route to the crossbeam channel with the compositor is created along with the `CompositorProxy`, simplifying what needs to be passed around during pipeline initialization. Previously, some image updates (from video) were sent over IPC with a special serialization routine and some were sent via crossbeam channels (canvas). Now all updates go over the IPC channel `IpcSharedMemory` is used to avoid serialization penalties. This should improve performance and reduce copies for video, but add a memory copy overhead for canvas. This will improve in the future when canvas renders directly into a texture. All-in-all this is a simplification which opens the path toward having a standard compositor API and reduces the number of duplicate messages and proxying that had to happen in libservo. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
30cbf01280
commit
9195344b75
28 changed files with 547 additions and 800 deletions
|
@ -30,7 +30,7 @@ use style::values::computed::font::{FamilyName, FontFamilyNameSyntax, SingleFont
|
|||
use style::Atom;
|
||||
use url::Url;
|
||||
use webrender_api::{FontInstanceFlags, FontInstanceKey, FontKey};
|
||||
use webrender_traits::{ScriptToCompositorMsg, WebRenderScriptApi};
|
||||
use webrender_traits::CrossProcessCompositorApi;
|
||||
|
||||
use crate::font::{
|
||||
Font, FontDescriptor, FontFamilyDescriptor, FontGroup, FontRef, FontSearchScope,
|
||||
|
@ -52,7 +52,7 @@ pub struct FontContext {
|
|||
resource_threads: ReentrantMutex<CoreResourceThread>,
|
||||
|
||||
/// A sender that can send messages and receive replies from the compositor.
|
||||
webrender_api: ReentrantMutex<WebRenderScriptApi>,
|
||||
compositor_api: ReentrantMutex<CrossProcessCompositorApi>,
|
||||
|
||||
/// The actual instances of fonts ie a [`FontTemplate`] combined with a size and
|
||||
/// other font properties, along with the font data and a platform font instance.
|
||||
|
@ -100,14 +100,14 @@ impl MallocSizeOf for FontContext {
|
|||
impl FontContext {
|
||||
pub fn new(
|
||||
system_font_service_proxy: Arc<SystemFontServiceProxy>,
|
||||
webrender_api: WebRenderScriptApi,
|
||||
compositor_api: CrossProcessCompositorApi,
|
||||
resource_threads: ResourceThreads,
|
||||
) -> Self {
|
||||
#[allow(clippy::default_constructed_unit_structs)]
|
||||
Self {
|
||||
system_font_service_proxy,
|
||||
resource_threads: ReentrantMutex::new(resource_threads.core_thread),
|
||||
webrender_api: ReentrantMutex::new(webrender_api),
|
||||
compositor_api: ReentrantMutex::new(compositor_api),
|
||||
fonts: Default::default(),
|
||||
resolved_font_groups: Default::default(),
|
||||
web_fonts: Arc::new(RwLock::default()),
|
||||
|
@ -321,15 +321,11 @@ impl FontContext {
|
|||
.entry(identifier.clone())
|
||||
.or_insert_with(|| {
|
||||
let font_key = self.system_font_service_proxy.generate_font_key();
|
||||
let _ = self
|
||||
.webrender_api
|
||||
.lock()
|
||||
.sender()
|
||||
.send(ScriptToCompositorMsg::AddFont(
|
||||
font_key,
|
||||
font_data.as_ipc_shared_memory(),
|
||||
identifier.index(),
|
||||
));
|
||||
self.compositor_api.lock().add_font(
|
||||
font_key,
|
||||
font_data.as_ipc_shared_memory(),
|
||||
identifier.index(),
|
||||
);
|
||||
font_key
|
||||
});
|
||||
|
||||
|
@ -339,13 +335,11 @@ impl FontContext {
|
|||
.entry((font_key, pt_size))
|
||||
.or_insert_with(|| {
|
||||
let font_instance_key = self.system_font_service_proxy.generate_font_instance_key();
|
||||
let _ = self.webrender_api.lock().sender().send(
|
||||
ScriptToCompositorMsg::AddFontInstance(
|
||||
font_instance_key,
|
||||
font_key,
|
||||
pt_size.to_f32_px(),
|
||||
flags,
|
||||
),
|
||||
self.compositor_api.lock().add_font_instance(
|
||||
font_instance_key,
|
||||
font_key,
|
||||
pt_size.to_f32_px(),
|
||||
flags,
|
||||
);
|
||||
font_instance_key
|
||||
});
|
||||
|
|
|
@ -27,7 +27,7 @@ use style::values::specified::FontStretch as SpecifiedFontStretch;
|
|||
use style::Atom;
|
||||
use tracing::{instrument, span, Level};
|
||||
use webrender_api::{FontInstanceFlags, FontInstanceKey, FontKey};
|
||||
use webrender_traits::WebRenderFontApi;
|
||||
use webrender_traits::CrossProcessCompositorApi;
|
||||
|
||||
use crate::font::FontDescriptor;
|
||||
use crate::font_store::FontStore;
|
||||
|
@ -97,7 +97,7 @@ struct ResolvedGenericFontFamilies {
|
|||
pub struct SystemFontService {
|
||||
port: IpcReceiver<SystemFontServiceMessage>,
|
||||
local_families: FontStore,
|
||||
webrender_api: Box<dyn WebRenderFontApi>,
|
||||
compositor_api: CrossProcessCompositorApi,
|
||||
webrender_fonts: HashMap<FontIdentifier, FontKey>,
|
||||
font_instances: HashMap<(FontKey, Au), FontInstanceKey>,
|
||||
generic_fonts: ResolvedGenericFontFamilies,
|
||||
|
@ -129,7 +129,7 @@ impl SystemFontServiceProxySender {
|
|||
}
|
||||
|
||||
impl SystemFontService {
|
||||
pub fn spawn(webrender_api: Box<dyn WebRenderFontApi + Send>) -> SystemFontServiceProxySender {
|
||||
pub fn spawn(compositor_api: CrossProcessCompositorApi) -> SystemFontServiceProxySender {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
|
||||
thread::Builder::new()
|
||||
|
@ -139,7 +139,7 @@ impl SystemFontService {
|
|||
let mut cache = SystemFontService {
|
||||
port: receiver,
|
||||
local_families: Default::default(),
|
||||
webrender_api,
|
||||
compositor_api,
|
||||
webrender_fonts: HashMap::new(),
|
||||
font_instances: HashMap::new(),
|
||||
generic_fonts: Default::default(),
|
||||
|
@ -204,7 +204,7 @@ impl SystemFontService {
|
|||
|
||||
const FREE_FONT_KEYS_BATCH_SIZE: usize = 40;
|
||||
const FREE_FONT_INSTANCE_KEYS_BATCH_SIZE: usize = 40;
|
||||
let (mut new_font_keys, mut new_font_instance_keys) = self.webrender_api.fetch_font_keys(
|
||||
let (mut new_font_keys, mut new_font_instance_keys) = self.compositor_api.fetch_font_keys(
|
||||
FREE_FONT_KEYS_BATCH_SIZE - self.free_font_keys.len(),
|
||||
FREE_FONT_INSTANCE_KEYS_BATCH_SIZE - self.free_font_instance_keys.len(),
|
||||
);
|
||||
|
@ -290,7 +290,7 @@ impl SystemFontService {
|
|||
) -> FontInstanceKey {
|
||||
self.fetch_new_keys();
|
||||
|
||||
let webrender_font_api = &self.webrender_api;
|
||||
let compositor_api = &self.compositor_api;
|
||||
let webrender_fonts = &mut self.webrender_fonts;
|
||||
let font_data = self.local_families.get_or_initialize_font_data(&identifier);
|
||||
|
||||
|
@ -305,12 +305,12 @@ impl SystemFontService {
|
|||
// this for those platforms.
|
||||
#[cfg(target_os = "macos")]
|
||||
if let FontIdentifier::Local(local_font_identifier) = identifier {
|
||||
webrender_font_api
|
||||
compositor_api
|
||||
.add_system_font(font_key, local_font_identifier.native_font_handle());
|
||||
return font_key;
|
||||
}
|
||||
|
||||
webrender_font_api.add_font(
|
||||
compositor_api.add_font(
|
||||
font_key,
|
||||
font_data.as_ipc_shared_memory(),
|
||||
identifier.index(),
|
||||
|
@ -323,7 +323,7 @@ impl SystemFontService {
|
|||
.entry((font_key, pt_size))
|
||||
.or_insert_with(|| {
|
||||
let font_instance_key = self.free_font_instance_keys.pop().unwrap();
|
||||
webrender_font_api.add_font_instance(
|
||||
compositor_api.add_font_instance(
|
||||
font_instance_key,
|
||||
font_key,
|
||||
pt_size.to_f32_px(),
|
||||
|
|
|
@ -33,7 +33,7 @@ use style::values::computed::{FontLanguageOverride, XLang};
|
|||
use style::values::generics::font::LineHeight;
|
||||
use style::ArcSlice;
|
||||
use webrender_api::{FontInstanceKey, FontKey, IdNamespace};
|
||||
use webrender_traits::WebRenderScriptApi;
|
||||
use webrender_traits::CrossProcessCompositorApi;
|
||||
|
||||
struct TestContext {
|
||||
context: FontContext,
|
||||
|
@ -47,11 +47,11 @@ impl TestContext {
|
|||
let (core_sender, _) = ipc::channel().unwrap();
|
||||
let (storage_sender, _) = ipc::channel().unwrap();
|
||||
let mock_resource_threads = ResourceThreads::new(core_sender, storage_sender);
|
||||
let mock_webrender_api = WebRenderScriptApi::dummy();
|
||||
let mock_compositor_api = CrossProcessCompositorApi::dummy();
|
||||
|
||||
let proxy_clone = Arc::new(system_font_service_proxy.to_sender().to_proxy());
|
||||
Self {
|
||||
context: FontContext::new(proxy_clone, mock_webrender_api, mock_resource_threads),
|
||||
context: FontContext::new(proxy_clone, mock_compositor_api, mock_resource_threads),
|
||||
system_font_service,
|
||||
system_font_service_proxy,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue