Skip to content

Commit

Permalink
Add document ID to windows (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
wusyong authored Oct 12, 2024
1 parent 1e7c19d commit 8a7746e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
27 changes: 16 additions & 11 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,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 @@ -1116,8 +1116,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 @@ -1129,7 +1128,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 @@ -1141,14 +1140,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 @@ -2078,7 +2077,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 @@ -2105,7 +2107,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 @@ -2119,7 +2124,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 @@ -2146,13 +2151,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 @@ -366,7 +366,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 @@ -392,7 +392,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 @@ -422,7 +422,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 @@ -444,7 +444,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 @@ -458,7 +460,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

0 comments on commit 8a7746e

Please sign in to comment.