Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Introduce a shared ipc router and a ipc handle #23909

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3a73e45
prototype script ipc router
gterzian Aug 2, 2019
5d0b2a8
fix removal
gterzian Aug 3, 2019
c92ea60
tidy
gterzian Aug 3, 2019
6498132
remove todo
gterzian Aug 3, 2019
8cf6c6a
add note
gterzian Aug 3, 2019
959aa3c
more notes
gterzian Aug 3, 2019
cc993a5
re-format callback
gterzian Aug 4, 2019
f629704
move to separate file, rename
gterzian Aug 4, 2019
dea4065
move to msg, rename
gterzian Aug 4, 2019
ec71d78
switch to shared router in script fetch
gterzian Aug 4, 2019
87bfe0e
swtich XHR to shared-router
gterzian Aug 4, 2019
c56c882
move to separate crate, plug into profiler
gterzian Aug 4, 2019
5d2de5c
switch eventsource to use ipc-callback
gterzian Aug 4, 2019
d488d29
switch script element to use ipc callback
gterzian Aug 4, 2019
ae7fd7d
switch websocket to use ipc callback
gterzian Aug 4, 2019
4461526
phantom type the ipc-handle
gterzian Aug 4, 2019
9ace427
drop ipc callback when websocket is closed
gterzian Aug 4, 2019
fb55f49
turn off fetch cancelling
gterzian Aug 5, 2019
6bdb54d
fmt
gterzian Aug 5, 2019
f1cfd69
set the sender on a handle at point of use
gterzian Aug 5, 2019
ba94357
add comment on shared-memory
gterzian Aug 5, 2019
9aaaa4f
introduce router id
gterzian Aug 6, 2019
d95fdfe
use shared-router in font-cache
gterzian Aug 6, 2019
b13ec32
switch layout image to using the shared-router
gterzian Aug 6, 2019
34c077e
fmt
gterzian Aug 6, 2019
94156b3
improve pipeline namespace reservation ordering
gterzian Aug 6, 2019
0923621
switch media element to use ipc callback
gterzian Aug 6, 2019
d797780
switch video elem to use ipc-callback
gterzian Aug 6, 2019
49481cd
remove unused import in layout image
gterzian Aug 6, 2019
03d080d
attempt to rewrite fetch cancelling with shared mem
gterzian Aug 7, 2019
12002a7
move to one router per process
gterzian Aug 7, 2019
dddf3c5
use router in layout
gterzian Aug 7, 2019
12123d9
more layout/font-cache
gterzian Aug 7, 2019
7ce7769
disable scroll-states
gterzian Aug 8, 2019
01ea7c5
rename routers to dispatchers
gterzian Aug 8, 2019
6e5a42e
fix gfx tests, fmt global
gterzian Aug 8, 2019
3e6cdfa
remove scroll state import
gterzian Aug 8, 2019
e7ec49e
turn off parallel layout
gterzian Aug 8, 2019
ae51f38
trun back on
gterzian Aug 8, 2019
69538cf
turn off parallel layout
gterzian Aug 8, 2019
416161c
restructure content process shutdown ack with sender, without layout
gterzian Aug 9, 2019
b2646ca
turn off fetch canceller
gterzian Aug 12, 2019
bcac149
do not cache any session history
gterzian Aug 13, 2019
73708cf
remove redundant windowproxy transplanting
gterzian Aug 14, 2019
208b83b
use router in constellation network listener
gterzian Aug 14, 2019
9451a00
update ipc chan
gterzian Sep 3, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 2 additions & 25 deletions components/compositing/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ use pixels::PixelFormat;
use profile_traits::time::{self as profile_time, profile, ProfilerCategory};
use script_traits::CompositorEvent::{MouseButtonEvent, MouseMoveEvent, TouchEvent, WheelEvent};
use script_traits::{AnimationState, AnimationTickType, ConstellationMsg, LayoutControlMsg};
use script_traits::{
MouseButton, MouseEventType, ScrollState, TouchEventType, TouchId, WheelDelta,
};
use script_traits::{MouseButton, MouseEventType, TouchEventType, TouchId, WheelDelta};
use script_traits::{UntrustedNodeAddress, WindowSizeData, WindowSizeType};
use servo_geometry::{DeviceIndependentPixel, FramebufferUintLength};
use std::collections::HashMap;
Expand Down Expand Up @@ -1136,28 +1134,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
}

fn send_viewport_rects(&self) {
let mut scroll_states_per_pipeline = HashMap::new();
for scroll_layer_state in self
.webrender_api
.get_scroll_node_state(self.webrender_document)
{
let scroll_state = ScrollState {
scroll_id: scroll_layer_state.id,
scroll_offset: scroll_layer_state.scroll_offset,
};

scroll_states_per_pipeline
.entry(scroll_layer_state.id.pipeline_id())
.or_insert(vec![])
.push(scroll_state);
}

for (pipeline_id, scroll_states) in scroll_states_per_pipeline {
if let Some(pipeline) = self.pipeline(pipeline_id.from_webrender()) {
let msg = LayoutControlMsg::SetScrollStates(scroll_states);
let _ = pipeline.layout_chan.send(msg);
}
}
// Turn-off to see if it helps
}

// Check if any pipelines currently have active animations or animation callbacks.
Expand Down
2 changes: 2 additions & 0 deletions components/constellation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ no_wgl = ["canvas/no_wgl"]
[dependencies]
background_hang_monitor = { path = "../background_hang_monitor"}
backtrace = "0.3"
bincode = "1"
bluetooth_traits = { path = "../bluetooth_traits" }
canvas = {path = "../canvas", default-features = false}
clipboard = "0.5"
Expand Down Expand Up @@ -49,6 +50,7 @@ servo_geometry = {path = "../geometry"}
servo_rand = {path = "../rand"}
servo_remutex = {path = "../remutex"}
servo_url = {path = "../url"}
shared_ipc_router = {path = "../shared_ipc_router"}
webvr_traits = {path = "../webvr_traits"}
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
webxr-api = {git = "https://github.com/servo/webxr", features = ["ipc"]}
Expand Down
23 changes: 14 additions & 9 deletions components/constellation/constellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ use embedder_traits::{Cursor, EmbedderMsg, EmbedderProxy, EventLoopWaker};
use euclid::{default::Size2D as UntypedSize2D, Scale, Size2D};
use gfx::font_cache_thread::FontCacheThread;
use gfx_traits::Epoch;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::ipc::{self, IpcReceiver, IpcSender, IpcSharedMemory};
use ipc_channel::router::ROUTER;
use ipc_channel::Error as IpcError;
use keyboard_types::webdriver::Event as WebDriverInputEvent;
Expand Down Expand Up @@ -155,7 +155,7 @@ use script_traits::{
use script_traits::{LayoutMsg as FromLayoutMsg, ScriptMsg as FromScriptMsg, ScriptThreadFactory};
use script_traits::{SWManagerMsg, ScopeThings, UpdatePipelineIdReason, WebDriverCommandMsg};
use serde::{Deserialize, Serialize};
use servo_config::{opts, pref};
use servo_config::opts;
use servo_geometry::DeviceIndependentPixel;
use servo_rand::{random, Rng, ServoRng, SliceRandom};
use servo_remutex::ReentrantMutex;
Expand Down Expand Up @@ -719,8 +719,8 @@ where
let swmanager_receiver =
route_ipc_receiver_to_new_mpsc_receiver_preserving_errors(swmanager_receiver);

// Zero is reserved for the embedder.
PipelineNamespace::install(PipelineNamespaceId(1));
// Zero is reserved for the embedder, 1 for the font-cache.
PipelineNamespace::install(PipelineNamespaceId(2));

let mut constellation: Constellation<Message, LTF, STF> = Constellation {
namespace_receiver,
Expand Down Expand Up @@ -754,9 +754,11 @@ where
pipelines: HashMap::new(),
browsing_contexts: HashMap::new(),
pending_changes: vec![],
// We initialize the namespace at 2, since we reserved
// namespace 0 for the embedder, and 0 for the constellation
next_pipeline_namespace_id: PipelineNamespaceId(2),
// We initialize the namespace at 3, since we reserved
// namespace 0 for the embedder,
// and 1 for the font-cache,
// and 2 for the constellation
next_pipeline_namespace_id: PipelineNamespaceId(3),
time_profiler_chan: state.time_profiler_chan,
mem_profiler_chan: state.mem_profiler_chan,
window_size: WindowSizeData {
Expand Down Expand Up @@ -1668,6 +1670,9 @@ where
fn handle_request_from_layout(&mut self, message: FromLayoutMsg) {
debug!("Constellation got {:?} message", message);
match message {
FromLayoutMsg::GePipelineNameSpaceId(sender) => {
let _ = sender.send(self.next_pipeline_namespace_id());
},
FromLayoutMsg::ChangeRunningAnimationsState(pipeline_id, animation_state) => {
self.handle_change_running_animations_state(pipeline_id, animation_state)
},
Expand Down Expand Up @@ -2198,7 +2203,7 @@ where
&self,
id: PipelineId,
request_builder: RequestBuilder,
cancel_chan: IpcReceiver<()>,
cancel_chan: IpcSharedMemory,
) {
let listener = NetworkListener::new(
request_builder,
Expand Down Expand Up @@ -3862,7 +3867,7 @@ where
let pipelines_to_evict = {
let session_history = self.get_joint_session_history(top_level_browsing_context_id);

let history_length = pref!(session_history.max_length) as usize;
let history_length = 0 as usize;

// The past is stored with older entries at the front.
// We reverse the iter so that newer entries are at the front and then
Expand Down
57 changes: 36 additions & 21 deletions components/constellation/network_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
//! Any redirects that are encountered are followed. Whenever a non-redirect
//! response is received, it is forwarded to the appropriate script thread.

use bincode;
use crossbeam_channel::Sender;
use http::header::LOCATION;
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use msg::constellation_msg::PipelineId;
use net::http_loader::{set_default_accept, set_default_accept_language};
use net_traits::request::{Destination, Referrer, RequestBuilder};
use net_traits::response::ResponseInit;
use net_traits::{CoreResourceMsg, FetchChannels, FetchMetadata, FetchResponseMsg};
use net_traits::{IpcSend, NetworkError, ResourceThreads};
use shared_ipc_router::SharedIpcRouter;

pub struct NetworkListener {
res_init: Option<ResponseInit>,
Expand Down Expand Up @@ -43,8 +44,21 @@ impl NetworkListener {
}
}

pub fn initiate_fetch(&self, cancel_chan: Option<ipc::IpcReceiver<()>>) {
let (ipc_sender, ipc_receiver) = ipc::channel().expect("Failed to create IPC channel!");
pub fn initiate_fetch(&self, cancel_chan: Option<ipc::IpcSharedMemory>) {
// Note: this doesn't actually create a new router each time,
// although it does clone the handle to the router.
// It would be better to store it somewhere, and that is made harder
// by initiate_fetch being called itself from inside a the message handler.
let ipc_router = SharedIpcRouter::new();
if ipc_router.requires_setup_for_resource_manager() {
let _ = self
.resource_threads
.sender()
.send(CoreResourceMsg::NewDispatcher(
ipc_router.router_id.clone(),
ipc_router.ipc_sender.clone(),
));
}

let mut listener = NetworkListener {
res_init: self.res_init.clone(),
Expand All @@ -55,36 +69,37 @@ impl NetworkListener {
should_send: false,
};

if self.res_init.is_none() {
set_default_accept(Destination::Document, &mut listener.request_builder.headers);
set_default_accept_language(&mut listener.request_builder.headers);
}

let request_builder = listener.request_builder.clone();

let handle = ipc_router.add_callback(Box::new(move |data: Vec<u8>| {
let response: Result<FetchResponseMsg, bincode::Error> = bincode::deserialize(&data[..]);
match response {
Ok(FetchResponseMsg::ProcessResponse(res)) => listener.check_redirect(res),
Ok(msg_) => listener.send(msg_),
Err(e) => warn!("Error while receiving network listener message: {}", e),
};
}));

let msg = match self.res_init {
Some(ref res_init_) => CoreResourceMsg::FetchRedirect(
self.request_builder.clone(),
res_init_.clone(),
ipc_sender,
handle,
None,
),
None => {
set_default_accept(Destination::Document, &mut listener.request_builder.headers);
set_default_accept_language(&mut listener.request_builder.headers);

CoreResourceMsg::Fetch(
listener.request_builder.clone(),
FetchChannels::ResponseMsg(ipc_sender, cancel_chan),
request_builder,
FetchChannels::ResponseHandle(handle, cancel_chan),
)
},
};

ROUTER.add_route(
ipc_receiver.to_opaque(),
Box::new(move |message| {
let msg = message.to();
match msg {
Ok(FetchResponseMsg::ProcessResponse(res)) => listener.check_redirect(res),
Ok(msg_) => listener.send(msg_),
Err(e) => warn!("Error while receiving network listener message: {}", e),
};
}),
);

if let Err(e) = self.resource_threads.sender().send(msg) {
warn!("Resource thread unavailable ({})", e);
}
Expand Down
3 changes: 3 additions & 0 deletions components/gfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ doctest = false

[dependencies]
app_units = "0.7"
bincode = "1"
bitflags = "1.0"
euclid = "0.20"
fnv = "1.0"
Expand All @@ -26,6 +27,7 @@ lazy_static = "1"
libc = "0.2"
log = "0.4"
malloc_size_of = { path = "../malloc_size_of" }
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
ordered-float = "1.0"
packed_simd = "0.3"
Expand All @@ -34,6 +36,7 @@ serde = "1.0"
servo_arc = {path = "../servo_arc"}
servo_atoms = {path = "../atoms"}
servo_url = {path = "../url"}
shared_ipc_router = {path = "../shared_ipc_router"}
smallvec = { version = "0.6", features = ["std", "union"] }
style = {path = "../style", features = ["servo"]}
time = "0.1.12"
Expand Down
Loading