mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Update Servo::get_events to return drain type (#31181)
* Update Servo::get_events to return drain type to prevent constant allocation * Remove type alias for tlwc * Fix libsimpleservo
This commit is contained in:
parent
21dbf0ad3a
commit
266a082206
4 changed files with 23 additions and 12 deletions
|
@ -23,6 +23,7 @@ use std::collections::HashMap;
|
|||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::vec::Drain;
|
||||
|
||||
use bluetooth::BluetoothThreadFactory;
|
||||
use bluetooth_traits::BluetoothRequest;
|
||||
|
@ -64,7 +65,7 @@ pub use gleam::gl;
|
|||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use log::{error, trace, warn, Log, Metadata, Record};
|
||||
use media::{GLPlayerThreads, WindowGLContext};
|
||||
pub use msg::constellation_msg::TopLevelBrowsingContextId as BrowserId;
|
||||
pub use msg::constellation_msg::TopLevelBrowsingContextId;
|
||||
use msg::constellation_msg::{PipelineNamespace, PipelineNamespaceId};
|
||||
use net::resource_thread::new_resource_threads;
|
||||
use net_traits::IpcSend;
|
||||
|
@ -162,7 +163,7 @@ pub struct Servo<Window: WindowMethods + 'static + ?Sized> {
|
|||
compositor: IOCompositor<Window>,
|
||||
constellation_chan: Sender<ConstellationMsg>,
|
||||
embedder_receiver: EmbedderReceiver,
|
||||
messages_for_embedder: Vec<(Option<BrowserId>, EmbedderMsg)>,
|
||||
messages_for_embedder: Vec<(Option<TopLevelBrowsingContextId>, EmbedderMsg)>,
|
||||
profiler_enabled: bool,
|
||||
/// For single-process Servo instances, this field controls the initialization
|
||||
/// and deinitialization of the JS Engine. Multiprocess Servo instances have their
|
||||
|
@ -213,7 +214,7 @@ impl webrender_api::RenderNotifier for RenderNotifier {
|
|||
|
||||
pub struct InitializedServo<Window: WindowMethods + 'static + ?Sized> {
|
||||
pub servo: Servo<Window>,
|
||||
pub browser_id: BrowserId,
|
||||
pub browser_id: TopLevelBrowsingContextId,
|
||||
}
|
||||
|
||||
impl<Window> Servo<Window>
|
||||
|
@ -282,7 +283,7 @@ where
|
|||
|
||||
// Reserving a namespace to create TopLevelBrowsingContextId.
|
||||
PipelineNamespace::install(PipelineNamespaceId(0));
|
||||
let top_level_browsing_context_id = BrowserId::new();
|
||||
let top_level_browsing_context_id = TopLevelBrowsingContextId::new();
|
||||
|
||||
// Get both endpoints of a special channel for communication between
|
||||
// the client window and the compositor. This channel is unique because
|
||||
|
@ -722,8 +723,8 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_events(&mut self) -> Vec<(Option<BrowserId>, EmbedderMsg)> {
|
||||
::std::mem::replace(&mut self.messages_for_embedder, Vec::new())
|
||||
pub fn get_events(&mut self) -> Drain<'_, (Option<TopLevelBrowsingContextId>, EmbedderMsg)> {
|
||||
self.messages_for_embedder.drain(..)
|
||||
}
|
||||
|
||||
pub fn handle_events(&mut self, events: impl IntoIterator<Item = EmbedderEvent>) -> bool {
|
||||
|
|
|
@ -40,7 +40,7 @@ pub use servo::webrender_api::units::DeviceIntRect;
|
|||
use servo::webrender_api::units::DevicePixel;
|
||||
use servo::webrender_api::ScrollLocation;
|
||||
use servo::webrender_surfman::WebrenderSurfman;
|
||||
use servo::{self, gl, BrowserId, Servo};
|
||||
use servo::{self, gl, Servo, TopLevelBrowsingContextId};
|
||||
use servo_media::player::context as MediaPlayerContext;
|
||||
use surfman::{Connection, SurfaceType};
|
||||
|
||||
|
@ -336,7 +336,7 @@ pub fn deinit() {
|
|||
}
|
||||
|
||||
impl ServoGlue {
|
||||
fn get_browser_id(&self) -> Result<BrowserId, &'static str> {
|
||||
fn get_browser_id(&self) -> Result<TopLevelBrowsingContextId, &'static str> {
|
||||
let webview_id = match self.focused_webview_id {
|
||||
Some(id) => id,
|
||||
None => return Err("No focused WebViewId yet."),
|
||||
|
@ -646,6 +646,8 @@ impl ServoGlue {
|
|||
}
|
||||
|
||||
fn handle_servo_events(&mut self) -> Result<(), &'static str> {
|
||||
let mut need_update = false;
|
||||
let mut need_present = false;
|
||||
for (browser_id, event) in self.servo.get_events() {
|
||||
match event {
|
||||
EmbedderMsg::ChangePageTitle(title) => {
|
||||
|
@ -660,7 +662,7 @@ impl ServoGlue {
|
|||
let window_event =
|
||||
EmbedderEvent::AllowNavigationResponse(pipeline_id, data);
|
||||
self.events.push(window_event);
|
||||
let _ = self.perform_updates();
|
||||
need_update = true;
|
||||
}
|
||||
},
|
||||
EmbedderMsg::HistoryChanged(entries, current) => {
|
||||
|
@ -824,7 +826,7 @@ impl ServoGlue {
|
|||
self.callbacks.host_callbacks.on_panic(reason, backtrace);
|
||||
},
|
||||
EmbedderMsg::ReadyToPresent => {
|
||||
self.servo.present();
|
||||
need_present = true;
|
||||
},
|
||||
EmbedderMsg::Status(..) |
|
||||
EmbedderMsg::SelectFiles(..) |
|
||||
|
@ -839,6 +841,13 @@ impl ServoGlue {
|
|||
EmbedderMsg::EventDelivered(..) => {},
|
||||
}
|
||||
}
|
||||
|
||||
if need_update {
|
||||
let _ = self.perform_updates();
|
||||
}
|
||||
if need_present {
|
||||
self.servo.present();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -462,7 +462,7 @@ impl App {
|
|||
|
||||
// Take any new embedder messages from Servo itself.
|
||||
embedder_messages = self.servo.as_mut().unwrap().get_events();
|
||||
if embedder_messages.is_empty() {
|
||||
if embedder_messages.len() == 0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use std::fs::File;
|
|||
use std::io::Write;
|
||||
use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
use std::vec::Drain;
|
||||
use std::{env, thread};
|
||||
|
||||
use arboard::Clipboard;
|
||||
|
@ -292,7 +293,7 @@ where
|
|||
/// Returns true if the caller needs to manually present a new frame.
|
||||
pub fn handle_servo_events(
|
||||
&mut self,
|
||||
events: Vec<(Option<WebViewId>, EmbedderMsg)>,
|
||||
events: Drain<'_, (Option<WebViewId>, EmbedderMsg)>,
|
||||
) -> ServoEventResponse {
|
||||
let mut need_present = false;
|
||||
let mut history_changed = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue