Create initial browser id for compositor on startup.

This commit is contained in:
Josh Matthews 2021-10-16 11:10:25 -04:00
parent 74f1eb199e
commit 6b50d7025c
7 changed files with 47 additions and 39 deletions

View file

@ -23,7 +23,9 @@ use image::{DynamicImage, ImageFormat};
use ipc_channel::ipc; use ipc_channel::ipc;
use libc::c_void; use libc::c_void;
use log::warn; use log::warn;
use msg::constellation_msg::{PipelineId, PipelineIndex, PipelineNamespaceId}; use msg::constellation_msg::{
PipelineId, PipelineIndex, PipelineNamespaceId, TopLevelBrowsingContextId,
};
use net_traits::image::base::Image; use net_traits::image::base::Image;
use net_traits::image_cache::CorsStatus; use net_traits::image_cache::CorsStatus;
use num_traits::FromPrimitive; use num_traits::FromPrimitive;
@ -104,6 +106,11 @@ impl FrameTreeId {
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
enum LayerPixel {} enum LayerPixel {}
struct RootPipeline {
top_level_browsing_context_id: TopLevelBrowsingContextId,
id: Option<PipelineId>,
}
/// NB: Never block on the constellation, because sometimes the constellation blocks on us. /// NB: Never block on the constellation, because sometimes the constellation blocks on us.
pub struct IOCompositor<Window: WindowMethods + ?Sized> { pub struct IOCompositor<Window: WindowMethods + ?Sized> {
/// The application window. /// The application window.
@ -113,7 +120,7 @@ pub struct IOCompositor<Window: WindowMethods + ?Sized> {
port: CompositorReceiver, port: CompositorReceiver,
/// The root pipeline. /// The root pipeline.
root_pipeline: Option<CompositionPipeline>, root_pipeline: RootPipeline,
/// Tracks details about each active pipeline that the compositor knows about. /// Tracks details about each active pipeline that the compositor knows about.
pipeline_details: HashMap<PipelineId, PipelineDetails>, pipeline_details: HashMap<PipelineId, PipelineDetails>,
@ -289,6 +296,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
is_running_problem_test: bool, is_running_problem_test: bool,
exit_after_load: bool, exit_after_load: bool,
convert_mouse_to_touch: bool, convert_mouse_to_touch: bool,
top_level_browsing_context_id: TopLevelBrowsingContextId,
) -> Self { ) -> Self {
let composite_target = match output_file { let composite_target = match output_file {
Some(_) => CompositeTarget::PngFile, Some(_) => CompositeTarget::PngFile,
@ -299,7 +307,10 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
embedder_coordinates: window.get_coordinates(), embedder_coordinates: window.get_coordinates(),
window, window,
port: state.receiver, port: state.receiver,
root_pipeline: None, root_pipeline: RootPipeline {
top_level_browsing_context_id,
id: None,
},
pipeline_details: HashMap::new(), pipeline_details: HashMap::new(),
scale: Scale::new(1.0), scale: Scale::new(1.0),
composition_request: CompositionRequest::NoCompositingNecessary, composition_request: CompositionRequest::NoCompositingNecessary,
@ -342,6 +353,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
is_running_problem_test: bool, is_running_problem_test: bool,
exit_after_load: bool, exit_after_load: bool,
convert_mouse_to_touch: bool, convert_mouse_to_touch: bool,
top_level_browsing_context_id: TopLevelBrowsingContextId,
) -> Self { ) -> Self {
let mut compositor = IOCompositor::new( let mut compositor = IOCompositor::new(
window, window,
@ -350,6 +362,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
is_running_problem_test, is_running_problem_test,
exit_after_load, exit_after_load,
convert_mouse_to_touch, convert_mouse_to_touch,
top_level_browsing_context_id,
); );
// Make sure the GL state is OK // Make sure the GL state is OK
@ -781,7 +794,10 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
frame_tree.pipeline.id frame_tree.pipeline.id
); );
self.root_pipeline = Some(frame_tree.pipeline.clone()); self.root_pipeline = RootPipeline {
top_level_browsing_context_id: frame_tree.pipeline.top_level_browsing_context_id,
id: Some(frame_tree.pipeline.id),
};
let pipeline_id = frame_tree.pipeline.id.to_webrender(); let pipeline_id = frame_tree.pipeline.id.to_webrender();
let mut txn = webrender_api::Transaction::new(); let mut txn = webrender_api::Transaction::new();
@ -823,10 +839,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
initial_viewport: initial_viewport, initial_viewport: initial_viewport,
}; };
let top_level_browsing_context_id = self let top_level_browsing_context_id = self.root_pipeline.top_level_browsing_context_id;
.root_pipeline
.as_ref()
.map(|pipeline| pipeline.top_level_browsing_context_id);
let msg = ConstellationMsg::WindowSize(top_level_browsing_context_id, data, size_type); let msg = ConstellationMsg::WindowSize(top_level_browsing_context_id, data, size_type);
@ -926,7 +939,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
} }
fn dispatch_mouse_window_move_event_class(&mut self, cursor: DevicePoint) { fn dispatch_mouse_window_move_event_class(&mut self, cursor: DevicePoint) {
let root_pipeline_id = match self.get_root_pipeline_id() { let root_pipeline_id = match self.root_pipeline.id {
Some(root_pipeline_id) => root_pipeline_id, Some(root_pipeline_id) => root_pipeline_id,
None => return, None => return,
}; };
@ -1204,10 +1217,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
} }
fn constrain_viewport(&mut self, pipeline_id: PipelineId, constraints: ViewportConstraints) { fn constrain_viewport(&mut self, pipeline_id: PipelineId, constraints: ViewportConstraints) {
let is_root = self let is_root = self.root_pipeline.id == Some(pipeline_id);
.root_pipeline
.as_ref()
.map_or(false, |root_pipeline| root_pipeline.id == pipeline_id);
if is_root { if is_root {
self.viewport_zoom = constraints.initial_zoom; self.viewport_zoom = constraints.initial_zoom;
@ -1640,10 +1650,6 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
); );
} }
fn get_root_pipeline_id(&self) -> Option<PipelineId> {
self.root_pipeline.as_ref().map(|pipeline| pipeline.id)
}
pub fn receive_messages(&mut self) -> bool { pub fn receive_messages(&mut self) -> bool {
// Check for new messages coming from the other threads in the system. // Check for new messages coming from the other threads in the system.
let mut compositor_messages = vec![]; let mut compositor_messages = vec![];

View file

@ -76,11 +76,7 @@ pub enum ConstellationMsg {
/// Request to traverse the joint session history of the provided browsing context. /// Request to traverse the joint session history of the provided browsing context.
TraverseHistory(TopLevelBrowsingContextId, TraversalDirection), TraverseHistory(TopLevelBrowsingContextId, TraversalDirection),
/// Inform the constellation of a window being resized. /// Inform the constellation of a window being resized.
WindowSize( WindowSize(TopLevelBrowsingContextId, WindowSizeData, WindowSizeType),
Option<TopLevelBrowsingContextId>,
WindowSizeData,
WindowSizeType,
),
/// Requests that the constellation instruct layout to begin a new tick of the animation. /// Requests that the constellation instruct layout to begin a new tick of the animation.
TickAnimation(PipelineId, AnimationTickType), TickAnimation(PipelineId, AnimationTickType),
/// Dispatch a webdriver command /// Dispatch a webdriver command

View file

@ -4983,7 +4983,7 @@ where
/// Called when the window is resized. /// Called when the window is resized.
fn handle_window_size_msg( fn handle_window_size_msg(
&mut self, &mut self,
top_level_browsing_context_id: Option<TopLevelBrowsingContextId>, top_level_browsing_context_id: TopLevelBrowsingContextId,
new_size: WindowSizeData, new_size: WindowSizeData,
size_type: WindowSizeType, size_type: WindowSizeType,
) { ) {
@ -4992,10 +4992,8 @@ where
new_size.initial_viewport.to_untyped() new_size.initial_viewport.to_untyped()
); );
if let Some(top_level_browsing_context_id) = top_level_browsing_context_id { let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id);
let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id); self.resize_browsing_context(new_size, size_type, browsing_context_id);
self.resize_browsing_context(new_size, size_type, browsing_context_id);
}
if let Some(resize_channel) = self.webdriver.resize_channel.take() { if let Some(resize_channel) = self.webdriver.resize_channel.take() {
let _ = resize_channel.send(new_size); let _ = resize_channel.send(new_size);

View file

@ -273,6 +273,11 @@ impl webrender_api::RenderNotifier for RenderNotifier {
} }
} }
pub struct InitializedServo<Window: WindowMethods + 'static + ?Sized> {
pub servo: Servo<Window>,
pub browser_id: BrowserId,
}
impl<Window> Servo<Window> impl<Window> Servo<Window>
where where
Window: WindowMethods + 'static + ?Sized, Window: WindowMethods + 'static + ?Sized,
@ -281,7 +286,7 @@ where
mut embedder: Box<dyn EmbedderMethods>, mut embedder: Box<dyn EmbedderMethods>,
window: Rc<Window>, window: Rc<Window>,
user_agent: Option<String>, user_agent: Option<String>,
) -> Servo<Window> { ) -> InitializedServo<Window> {
// Global configuration options, parsed from the command line. // Global configuration options, parsed from the command line.
let opts = opts::get(); let opts = opts::get();
@ -336,8 +341,9 @@ where
.unwrap_or(0); .unwrap_or(0);
webrender_gl.bind_framebuffer(gleam::gl::FRAMEBUFFER, framebuffer_object); webrender_gl.bind_framebuffer(gleam::gl::FRAMEBUFFER, framebuffer_object);
// Reserving a namespace to create TopLevelBrowserContextId. // Reserving a namespace to create TopLevelBrowsingContextId.
PipelineNamespace::install(PipelineNamespaceId(0)); PipelineNamespace::install(PipelineNamespaceId(0));
let browser_id = BrowserId::new();
// Get both endpoints of a special channel for communication between // Get both endpoints of a special channel for communication between
// the client window and the compositor. This channel is unique because // the client window and the compositor. This channel is unique because
@ -537,16 +543,18 @@ where
opts.is_running_problem_test, opts.is_running_problem_test,
opts.exit_after_load, opts.exit_after_load,
opts.convert_mouse_to_touch, opts.convert_mouse_to_touch,
browser_id,
); );
Servo { let servo = Servo {
compositor: compositor, compositor: compositor,
constellation_chan: constellation_chan, constellation_chan: constellation_chan,
embedder_receiver: embedder_receiver, embedder_receiver: embedder_receiver,
embedder_events: Vec::new(), embedder_events: Vec::new(),
profiler_enabled: false, profiler_enabled: false,
_js_engine_setup: js_engine_setup, _js_engine_setup: js_engine_setup,
} };
InitializedServo { servo, browser_id }
} }
fn handle_window_event(&mut self, event: WindowEvent) -> bool { fn handle_window_event(&mut self, event: WindowEvent) -> bool {

View file

@ -217,9 +217,10 @@ impl ServoThread {
.swap_chain() .swap_chain()
.expect("Failed to get webrender swap chain") .expect("Failed to get webrender swap chain")
.clone(); .clone();
let mut servo = Servo::new(embedder, window, None); let servo = Servo::new(embedder, window, None);
let id = servo.top_level_browsing_context_id;
let mut servo = servo.servo;
let id = TopLevelBrowsingContextId::new();
servo.handle_events(vec![WindowEvent::NewBrowser(url, id)]); servo.handle_events(vec![WindowEvent::NewBrowser(url, id)]);
let swap_chain = match webxr_mode { let swap_chain = match webxr_mode {

View file

@ -306,7 +306,7 @@ pub fn init(
SERVO.with(|s| { SERVO.with(|s| {
let mut servo_glue = ServoGlue { let mut servo_glue = ServoGlue {
webrender_surfman, webrender_surfman,
servo, servo: servo.servo,
batch_mode: false, batch_mode: false,
callbacks: window_callbacks, callbacks: window_callbacks,
browser_id: None, browser_id: None,
@ -314,8 +314,7 @@ pub fn init(
events: vec![], events: vec![],
context_menu_sender: None, context_menu_sender: None,
}; };
let browser_id = BrowserId::new(); let _ = servo_glue.process_event(WindowEvent::NewBrowser(url, servo.browser_id));
let _ = servo_glue.process_event(WindowEvent::NewBrowser(url, browser_id));
*s.borrow_mut() = Some(servo_glue); *s.borrow_mut() = Some(servo_glue);
}); });

View file

@ -100,9 +100,9 @@ impl App {
xr_discovery, xr_discovery,
)); ));
let mut servo = Servo::new(embedder, window.clone(), user_agent.clone()); let servo_data = Servo::new(embedder, window.clone(), user_agent.clone());
let browser_id = BrowserId::new(); let mut servo = servo_data.servo;
servo.handle_events(vec![WindowEvent::NewBrowser(get_default_url(), browser_id)]); servo.handle_events(vec![WindowEvent::NewBrowser(get_default_url(), servo_data.browser_id)]);
servo.setup_logging(); servo.setup_logging();
register_window(window.clone()); register_window(window.clone());