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

feat: add document ID to windows #187

Merged
merged 2 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 19 additions & 12 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ impl IOCompositor {
fn handle_browser_message(
&mut self,
msg: CompositorMsg,
windows: &mut HashMap<WindowId, Window>,
windows: &mut HashMap<WindowId, (Window, DocumentId)>,
) -> bool {
match self.shutdown_state {
ShutdownState::NotShuttingDown => {}
Expand Down Expand Up @@ -1119,8 +1119,7 @@ impl IOCompositor {
fn create_or_update_webview(
&mut self,
frame_tree: &SendableFrameTree,

windows: &mut HashMap<WindowId, Window>,
windows: &mut HashMap<WindowId, (Window, DocumentId)>,
) {
let pipeline_id = frame_tree.pipeline.id;
let webview_id = frame_tree.pipeline.top_level_browsing_context_id;
Expand All @@ -1132,7 +1131,7 @@ impl IOCompositor {
debug!("{webview_id}'s pipeline has changed from {old_pipeline} to {pipeline_id}");
}

if let Some(window) = windows.get(&self.current_window) {
if let Some((window, _)) = windows.get(&self.current_window) {
self.send_root_pipeline_display_list(window);
}
self.create_or_update_pipeline_details_with_frame_tree(frame_tree, None);
Expand All @@ -1144,14 +1143,14 @@ impl IOCompositor {
fn remove_webview(
&mut self,
top_level_browsing_context_id: TopLevelBrowsingContextId,
windows: &mut HashMap<WindowId, Window>,
windows: &mut HashMap<WindowId, (Window, DocumentId)>,
) {
debug!(
"Verso Compositor is removing webview {}",
top_level_browsing_context_id
);
let mut window_id = None;
for window in windows.values_mut() {
for (window, _) in windows.values_mut() {
let (webview, close_window) =
window.remove_webview(top_level_browsing_context_id, self);
if let Some(webview) = webview {
Expand Down Expand Up @@ -2034,7 +2033,9 @@ impl IOCompositor {
pipeline
.script_chan
.send(ConstellationControlMsg::SetEpochPaintTime(
*id, epoch, CrossProcessInstant::now(),
*id,
epoch,
CrossProcessInstant::now(),
))
{
warn!("Sending RequestLayoutPaintMetric message to layout failed ({e:?}).");
Expand Down Expand Up @@ -2079,7 +2080,10 @@ impl IOCompositor {
}

/// Receive and handle compositor messages.
pub fn receive_messages(&mut self, windows: &mut HashMap<WindowId, Window>) -> bool {
pub fn receive_messages(
&mut self,
windows: &mut HashMap<WindowId, (Window, DocumentId)>,
) -> bool {
// Check for new messages coming from the other threads in the system.
let mut compositor_messages = vec![];
let mut found_recomposite_msg = false;
Expand All @@ -2106,7 +2110,10 @@ impl IOCompositor {
}

/// Perform composition and related actions.
pub fn perform_updates(&mut self, windows: &mut HashMap<WindowId, Window>) -> bool {
pub fn perform_updates(
&mut self,
windows: &mut HashMap<WindowId, (Window, DocumentId)>,
) -> bool {
if self.shutdown_state == ShutdownState::FinishedShuttingDown {
return false;
}
Expand All @@ -2120,7 +2127,7 @@ impl IOCompositor {
self.zoom_action = false;
}

if let Some(window) = windows.get(&self.current_window) {
if let Some((window, _)) = windows.get(&self.current_window) {
match self.composition_request {
CompositionRequest::NoCompositingNecessary => {}
CompositionRequest::CompositeNow(_) => {
Expand All @@ -2147,13 +2154,13 @@ impl IOCompositor {
/// paint is not scheduled the compositor will hang forever.
///
/// This is used when resizing the window.
pub fn repaint_synchronously(&mut self, windows: &mut HashMap<WindowId, Window>) {
pub fn repaint_synchronously(&mut self, windows: &mut HashMap<WindowId, (Window, DocumentId)>) {
while self.shutdown_state != ShutdownState::ShuttingDown {
let msg = self.port.recv_compositor_msg();
let need_recomposite = matches!(msg, CompositorMsg::NewWebRenderFrameReady(_));
let keep_going = self.handle_browser_message(msg, windows);
if need_recomposite {
if let Some(window) = windows.get(&self.current_window) {
if let Some((window, _)) = windows.get(&self.current_window) {
self.composite(window);
if let Err(err) = self.rendering_context.present(&window.surface) {
log::warn!("Failed to present surface: {:?}", err);
Expand Down
14 changes: 8 additions & 6 deletions src/verso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use crate::{

/// Main entry point of Verso browser.
pub struct Verso {
windows: HashMap<WindowId, Window>,
windows: HashMap<WindowId, (Window, DocumentId)>,
compositor: Option<IOCompositor>,
constellation_sender: Sender<ConstellationMsg>,
embedder_receiver: EmbedderReceiver,
Expand Down Expand Up @@ -363,7 +363,7 @@ impl Verso {
);

let mut windows = HashMap::new();
windows.insert(window.id(), window);
windows.insert(window.id(), (window, webrender_document));

// Create Verso instance
let verso = Verso {
Expand All @@ -389,7 +389,7 @@ impl Verso {
compositor.maybe_start_shutting_down();
} else {
let need_repaint = match self.windows.get_mut(&window_id) {
Some(window) => window.handle_winit_window_event(
Some(window) => window.0.handle_winit_window_event(
&self.constellation_sender,
compositor,
&event,
Expand Down Expand Up @@ -419,7 +419,7 @@ impl Verso {
match compositor.shutdown_state {
ShutdownState::NotShuttingDown => {
if let Some(id) = webview_id {
for window in self.windows.values_mut() {
for (window, document) in self.windows.values_mut() {
if window.has_webview(id) {
if window.handle_servo_message(
id,
Expand All @@ -441,7 +441,9 @@ impl Verso {
);
let rect = DeviceIntRect::from_size(window.size());
window.panel = Some(WebView::new(panel_id, rect));
self.windows.insert(window.id(), window);
let webrender_document = document.clone();
self.windows
.insert(window.id(), (window, webrender_document));
}
break;
}
Expand All @@ -455,7 +457,7 @@ impl Verso {
if let Some(window) =
self.windows.get(&compositor.current_window)
{
window.set_cursor_icon(cursor);
window.0.set_cursor_icon(cursor);
}
}
EmbedderMsg::Shutdown | EmbedderMsg::ReadyToPresent(_) => {}
Expand Down